Browse Source

统计订单数算上用优惠券的订单(因优惠券退款时是按比例退的,商户会有剩余优惠券的金额在)

master
weigang 5 years ago
parent
commit
b041fd0c71
  1. 14
      app/Service/v3/Implementations/OrderStatisticsService.php

14
app/Service/v3/Implementations/OrderStatisticsService.php

@ -37,13 +37,17 @@ class OrderStatisticsService implements OrderStatisticsServiceInterface
$builder = OrderMain::query()
->selectRaw('COUNT(DISTINCT '.$mainTable.'.id) AS count')
->join($childTable, ''.$childTable.'.order_main_id', '=', ''.$mainTable.'.global_order_id')
->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id')
->where([''.$childTable.'.store_id' => $storeId, ''.$mainTable.'.type' => $type])
->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED_DIRECT,OrderState::REFUND_REFUSE]));
->where(function ($query) use ($mainTable, $goodsTable, $type) {
$query->where(function ($q) use ($mainTable, $goodsTable, $type) {
$q->whereIn(''.$mainTable.'.state', array_merge(OrderState::FINISH, [OrderState::REFUNDED_DIRECT,OrderState::REFUND_REFUSE]));
if ($type == OrderType::ONLINE) {
$q->whereIn(''.$goodsTable.'.status', [1,2]);
}
if ($type == OrderType::ONLINE) {
$builder = $builder->join($goodsTable, ''.$goodsTable.'.order_id', '=', ''.$childTable.'.id')
->whereIn(''.$goodsTable.'.status', [1,2]);
}
})->orWhere(''.$mainTable.'.coupon_money', '>', 0);
});
if ($startTime) {
$builder = $builder->where(''.$mainTable.'.created_at', '>=', $startTime);

Loading…
Cancel
Save