diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 082f179..4374bdf 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -31,6 +31,37 @@ class OrderDispatchService extends BaseService * @param int $pageSize */ public function workbenchOrderList(int $workerId, string $type, int $pageSize) + { + $model = $this->getWorkbenchOrderModel($workerId, $type); + $result = $model + ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'plan_time']) + ->order('id desc') + ->paginate($pageSize); + + return $result; + } + + /** + * 统计工作台订单 + * @param int $workerId + * @return array + */ + public function countWorkbenchOrder(int $workerId) + { + return [ + 'ongoing' => $this->getWorkbenchOrderModel($workerId, 'ongoing')->count(), + 'today' => $this->getWorkbenchOrderModel($workerId, 'today')->count(), + 'tomorrow' => $this->getWorkbenchOrderModel($workerId, 'tomorrow')->count(), + 'all' => $this->getWorkbenchOrderModel($workerId, 'all')->count(), + ]; + } + + /** + * 获取工作台订单模型 + * @param int $workerId + * @param string $type + */ + private function getWorkbenchOrderModel(int $workerId, string $type) { $model = $this->getOrderDispatchModel() ->with(['orderInfo' => function ($query) { @@ -66,12 +97,7 @@ class OrderDispatchService extends BaseService break; } - $result = $model - ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'plan_time']) - ->order('id desc') - ->paginate($pageSize); - - return $result; + return $model; } /** diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index c8a39c4..aca2ede 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -36,6 +36,15 @@ class OrderDispatch extends WorkerApi $this->success('获取成功', $res); } + /** + * 统计工作台订单 + */ + public function countWorkbenchOrder() + { + $res = $this->getOrderDispatchService()->countWorkbenchOrder($this->user['id']); + $this->success('获取成功', $res); + } + /** * 接单/拒接 * @return void