getOrderStatistics($start, $end); }); } catch (\Exception $e) { return $this->getOrderStatistics($start, $end); } } /** * @param $start * @param $end * @return Builder[]|Collection */ public function getOrderStatistics($start, $end) { $start = $start ?? date('Y-m-d 00:00:00'); $end = $end ?? date('Y-m-d 23:59:59'); $builders = Order::query()->selectRaw("warehouses.code," . "count(case wms_status when '创建订单' then 1 end) as createOrder, " . "count(case wms_status when '分配完成' then 1 end) as assignedComplete, " . "count(case wms_status when '部分分配' then 1 end) as partialAllocation, " . "count(case wms_status when '部分装箱' then 1 end) as partPacking, " . "count(case wms_status when '播种完成' then 1 end) as sowComplete, " . "count(1) as total" )->whereBetween('orders.created_at', [$start, $end,]) ->whereIn('wms_status', ['创建订单', '分配完成', '部分分配', '部分装箱', '播种完成']) ->leftJoin('warehouses', 'orders.warehouse_id', 'warehouses.id') ->groupBy('warehouse_id'); $builders->whereIn('owner_id', app("OwnerService")->getQuery()); return $builders->get(); } }