diff --git a/application/admin/behavior/OrderDispatchLog.php b/application/admin/behavior/OrderDispatchLog.php new file mode 100644 index 0000000..87e815b --- /dev/null +++ b/application/admin/behavior/OrderDispatchLog.php @@ -0,0 +1,31 @@ +getStatusList(); + $dispatch = $response['dispatch']; //订单对象 + $remark = $response['remark'] ?? ''; //备注 + + $data = [ + 'dispatch_id' => $dispatch->id, + 'order_id' => $dispatch->order_id, + 'worker_id' => $dispatch->worker_id, + 'order_status' => $dispatch->status, + 'order_status_text' => $statusList[$dispatch->status], + 'remark' => $remark, + ]; + \app\admin\model\OrderDispatchLog::create($data); + //(new \app\admin\model\OrderDispatchLog())->cre($data); + } +} diff --git a/application/admin/controller/orders/Dispatch2.php b/application/admin/controller/orders/Dispatch2.php index 62d8628..107f4db 100644 --- a/application/admin/controller/orders/Dispatch2.php +++ b/application/admin/controller/orders/Dispatch2.php @@ -229,23 +229,28 @@ class Dispatch2 extends Backend $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate; $row->validateFailException()->validate($validate); } + + $workerChange = false; + $remark = ''; if($row->worker_id != $params['worker_id']){ //更换了师傅 $worker = model('worker')->where('id',$params['worker_id'])->find(); $params ['worker_name'] = $worker->name; $params ['worker_tel'] = $worker->tel; //记录日志 - OrderDispatchLog::create([ - 'dispatch_id' => $row->id, - 'order_id' => $row->order_id, - 'worker_id' => $params['worker_id'], - 'status' => $row->status, - 'status_text' => $this->model->getStatusList()[$row->status], - 'remark' => '师傅由 ('.$row->worker_id.')'.$row->worker_name.' 更换为('.$params['worker_id'].')'.$worker->name - ]); + $remark = '师傅由 ('.$row->worker_id.')'.$row->worker_name.' 更换为('.$params['worker_id'].')'.$worker->name; + $workerChange = true; + } $result = $row->allowField(true)->save($params); + if($workerChange){ + $hookParams = [ + 'dispatch' => $row, + 'remark' => $remark, + ]; + Hook::listen('order_dispatch_change', $hookParams); + } Db::commit(); } catch (ValidateException | PDOException | Exception $e) { Db::rollback(); diff --git a/application/tags.php b/application/tags.php index f51a20b..f1d6c53 100755 --- a/application/tags.php +++ b/application/tags.php @@ -43,4 +43,8 @@ return [ 'app\\admin\\behavior\\OrderLog', 'app\\admin\\behavior\\OrderChangeAfter', ], + + 'order_dispatch_change' => [ + 'app\\admin\\behavior\\OrderDispatchLog', + ], ];