diff --git a/application/services/OrderDispatchService.php b/application/services/OrderDispatchService.php index 946ca2d..e9a1510 100644 --- a/application/services/OrderDispatchService.php +++ b/application/services/OrderDispatchService.php @@ -199,14 +199,7 @@ class OrderDispatchService extends BaseService */ public function appointmentTime(int $workerId, int $orderDispatchId, string $planTime) { - $orderDispatch = $this->getOrderDispatchModel() - ->where('id', $orderDispatchId) - ->where('worker_id', $workerId) - ->find(); - if (!$orderDispatch) { - $this->apiError('订单不存在'); - } - + $orderDispatch = $this->getOrderDispatchInfo($workerId, $orderDispatchId); $orderDispatch->status = OrderDispatch::STATUS_PLANIT; $orderDispatch->plan_time = $planTime; $orderDispatch->save(); @@ -219,6 +212,37 @@ class OrderDispatchService extends BaseService return true; } + + public function arrivedOnSite(int $workerId, int $orderDispatchId, string $img) + { + $time = datetime(time()); + $orderDispatch = $this->getOrderDispatchInfo($workerId, $orderDispatchId); + $orderDispatch->status = OrderDispatch::STATUS_CLOCK; + $orderDispatch->arrive_image = $img; + $orderDispatch->arrive_time = $time; + $orderDispatch->save(); + + //派单状态变更 + $orderDispatchChangeParams = [ + 'dispatch' => $orderDispatch, + 'remark' => '师傅已上门,上门时间:' . $time, + ]; + Hook::listen('order_dispatch_change', $orderDispatchChangeParams); + + return true; + } + + private function getOrderDispatchInfo(int $workerId, int $orderDispatchId) { + $res = $this->getOrderDispatchModel() + ->where('id', $orderDispatchId) + ->where('worker_id', $workerId) + ->find(); + if (!$res) { + $this->apiError('订单不存在'); + } + + return $res; + } }