|
|
@@ -5,25 +5,33 @@ namespace App\Services;
|
|
|
|
|
|
|
|
|
use App\Order;
|
|
|
+use Illuminate\Support\Facades\Auth;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
class RealtimePendingOrdersService
|
|
|
{
|
|
|
public function warehousesOrders($start = null, $end = null)
|
|
|
{
|
|
|
- $start = $start ?? date('Y-m-d 00:00:00');
|
|
|
- $end = $end ?? date('Y-m-d 23:59:59');
|
|
|
- return Order::query()->selectRaw("warehouses.name," .
|
|
|
- "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')
|
|
|
- ->get();
|
|
|
+ return Cache::get('RealTimePendingOrders' . Auth::id(), function () use ($start, $end) {
|
|
|
+ $start = $start ?? date('Y-m-d 00:00:00');
|
|
|
+ $end = $end ?? date('Y-m-d 23:59:59');
|
|
|
+ $ownerIds = app('OwnerService')->getSelectionId();
|
|
|
+ $builders = Order::query()->selectRaw("warehouses.name," .
|
|
|
+ "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');
|
|
|
+ if ($ownerIds) $builders->whereIn('owner_id', $ownerIds);
|
|
|
+ $builders = $builders->get();
|
|
|
+ Cache::put('RealTimePendingOrders' . Auth::id(), $builders);
|
|
|
+ return $builders;
|
|
|
+ });
|
|
|
}
|
|
|
}
|