diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 736d17e..89cb5c6 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -26,13 +26,15 @@ class OrderDispatchService extends BaseService } /** + * 工作台列表 * @param int $workerId 师傅id * @param string $type 类型:pending=待沟通,need_visit=待上门,ongoing=服务中,finished=已完成 + * @param string $needVisitType 待上门类型:today=今日,tomorrow=明日,all=全部 * @param int $pageSize */ - public function workbenchOrderList(int $workerId, string $type, int $pageSize) + public function workbenchOrderList(int $workerId, string $type, int $pageSize, string $needVisitType) { - $model = $this->getWorkbenchOrderModel($workerId, $type); + $model = $this->getWorkbenchOrderModel($workerId, $type, $needVisitType); $result = $model ->field(['id', 'order_id', 'status', 'remark', 'create_time', 'plan_time']) ->order('id desc') @@ -49,10 +51,13 @@ class OrderDispatchService extends BaseService public function countWorkbenchOrder(int $workerId) { return [ - 'pending' => $this->getWorkbenchOrderModel($workerId, 'ongoing')->count(), - 'need_visit' => $this->getWorkbenchOrderModel($workerId, 'today')->count(), - 'ongoing' => $this->getWorkbenchOrderModel($workerId, 'tomorrow')->count(), - 'finished' => $this->getWorkbenchOrderModel($workerId, 'all')->count(), + 'pending' => $this->getWorkbenchOrderModel($workerId, 'pending')->count(), + 'need_visit' => $this->getWorkbenchOrderModel($workerId, 'need_visit')->count(), + 'ongoing' => $this->getWorkbenchOrderModel($workerId, 'ongoing')->count(), + 'finished' => $this->getWorkbenchOrderModel($workerId, 'finished')->count(), + 'today' => $this->getWorkbenchOrderModel($workerId, 'need_visit', 'today')->count(), + 'tomorrow' => $this->getWorkbenchOrderModel($workerId, 'need_visit', 'tomorrow')->count(), + 'all' => $this->getWorkbenchOrderModel($workerId, 'need_visit', 'all')->count(), ]; } @@ -60,8 +65,9 @@ class OrderDispatchService extends BaseService * 获取工作台订单模型 * @param int $workerId * @param string $type + * @param string $needVisitType */ - private function getWorkbenchOrderModel(int $workerId, string $type) + private function getWorkbenchOrderModel(int $workerId, string $type, string $needVisitType = '') { $model = $this->getOrderDispatchModel() ->with(['orderInfo' => function ($query) { @@ -71,30 +77,32 @@ class OrderDispatchService extends BaseService }]) ->where('worker_id', $workerId); - $status = [ - OrderDispatch::STATUS_GOTIT, - OrderDispatch::STATUS_PLANIT, - OrderDispatch::STATUS_CLOCK, - ]; switch ($type) { + case 'pending': + //待沟通 + $model->where('status', OrderDispatch::STATUS_GOTIT); + break; + case 'need_visit': + //待上门 + $model->where('status', OrderDispatch::STATUS_PLANIT); + switch ($needVisitType) { + case 'today': + $model->where('plan_time', '>=', date('Y-m-d 00:00:00')); + $model->where('plan_time', '<=', date('Y-m-d 23:59:59')); + break; + case 'tomorrow': + $model->where('plan_time', '>=', date('Y-m-d 00:00:00', strtotime('+1 day'))); + $model->where('plan_time', '<=', date('Y-m-d 23:59:59', strtotime('+1 day'))); + break; + } + break; case 'ongoing': - //所有已接单未完成的订单 - $model->whereIn('status', $status); + //服务中 + $model->where('status', OrderDispatch::STATUS_CLOCK); break; - case 'today': - $model->whereIn('status', $status); - $model->where('plan_time', '>=', date('Y-m-d 00:00:00')); - $model->where('plan_time', '<=', date('Y-m-d 23:59:59')); - break; - case 'tomorrow': - $model->whereIn('status', $status); - $model->where('plan_time', '>=', date('Y-m-d 00:00:00', strtotime('+1 day'))); - $model->where('plan_time', '<=', date('Y-m-d 23:59:59', strtotime('+1 day'))); - break; - case 'all': - $status[] = OrderDispatch::STATUS_REFUSED; - $status[] = OrderDispatch::STATUS_FINISH; - $model->whereIn('status', $status); + case 'finished': + //已完成 + $model->where('status', OrderDispatch::STATUS_FINISH); break; } diff --git a/application/worker/controller/OrderDispatch.php b/application/worker/controller/OrderDispatch.php index e9218c1..5e9f151 100644 --- a/application/worker/controller/OrderDispatch.php +++ b/application/worker/controller/OrderDispatch.php @@ -48,7 +48,8 @@ class OrderDispatch extends WorkerApi $pageSize = $this->request->request('page_size', 20); $type = $this->request->request('workbench_type'); - $res = $this->getOrderDispatchService()->workbenchOrderList($this->user['id'], $type, $pageSize); + $needVisitType = $this->request->request('need_visit_type'); + $res = $this->getOrderDispatchService()->workbenchOrderList($this->user['id'], $type, $pageSize, $needVisitType); $this->success('获取成功', $res); } diff --git a/application/worker/validate/OrderDispatch.php b/application/worker/validate/OrderDispatch.php index 0937eed..95e8039 100644 --- a/application/worker/validate/OrderDispatch.php +++ b/application/worker/validate/OrderDispatch.php @@ -9,7 +9,8 @@ class OrderDispatch extends Validate protected $rule = [ 'type|确认类型' => 'require|in:accept,reject', 'order_dispatch_id|订单派单id' => 'require|number', - 'workbench_type|工作台类型' => 'require|in:ongoing,today,tomorrow,all', + 'workbench_type|工作台类型' => 'require|in:pending,need_visit,ongoing,finished', + 'need_visit_type|待上门类型' => 'require|in:today,tomorrow,all', 'plan_time|预约时间' => 'require|date', 'images|上门图片' => 'require|max:3000', @@ -30,7 +31,7 @@ class OrderDispatch extends Validate protected $scene = [ 'orderConfirm' => ['type', 'order_dispatch_id', 'reject_reason'], - 'workbenchOrderList' => ['workbench_type'], + 'workbenchOrderList' => ['workbench_type', 'need_visit_type'], 'info' => ['order_dispatch_id'], 'appointmentTime' => ['order_dispatch_id', 'plan_time'], 'arrivedOnSite' => ['order_dispatch_id', 'images'],