get(Order::class)->getTable(); $mainTable = ApplicationContext::getContainer()->get(OrderMain::class)->getTable(); $goodsTable = ApplicationContext::getContainer()->get(OrderGoods::class)->getTable(); $builder = OrderMain::query() ->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,OrderState::REFUND_REFUSE])) ->whereIn(''.$goodsTable.'.status', [1,2]); if ($startTime) { $builder = $builder->where(''.$mainTable.'.created_at', '>=', $startTime); } if ($endTime) { $builder = $builder->where(''.$mainTable.'.created_at', '<=', $endTime); } return $builder->groupBy(''.$mainTable.'.id')->count(); // $builder = Order::join('lanzu_order_main','lanzu_order_main.global_order_id','lanzu_order.order_main_id') // ->where('lanzu_order.store_id',$storeId); // if(!empty($startTime) && !empty($endTime)){ // $builder->whereBetween('lanzu_order_main.created_at',[$startTime,$endTime]); // } // $count = $builder->whereIn('lanzu_order_main.state', OrderState::FINISH) // ->where('type',$type) // ->count(); // return $count; } }