dispatch 增加变更日志
This commit is contained in:
parent
7a4bafcc12
commit
b77ccfe5f8
31
application/admin/behavior/OrderDispatchLog.php
Normal file
31
application/admin/behavior/OrderDispatchLog.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace app\admin\behavior;
|
||||||
|
|
||||||
|
use think\Lang;
|
||||||
|
|
||||||
|
class OrderDispatchLog
|
||||||
|
{
|
||||||
|
//记录订单任务日志
|
||||||
|
public function run(&$response)
|
||||||
|
{
|
||||||
|
|
||||||
|
Lang::load(APP_PATH . 'admin/lang/zh-cn/orders/dispatch2.php');
|
||||||
|
|
||||||
|
$Model = new \app\admin\model\OrderDispatch();
|
||||||
|
$statusList = $Model->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -229,23 +229,28 @@ class Dispatch2 extends Backend
|
||||||
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
|
||||||
$row->validateFailException()->validate($validate);
|
$row->validateFailException()->validate($validate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$workerChange = false;
|
||||||
|
$remark = '';
|
||||||
if($row->worker_id != $params['worker_id']){ //更换了师傅
|
if($row->worker_id != $params['worker_id']){ //更换了师傅
|
||||||
$worker = model('worker')->where('id',$params['worker_id'])->find();
|
$worker = model('worker')->where('id',$params['worker_id'])->find();
|
||||||
$params ['worker_name'] = $worker->name;
|
$params ['worker_name'] = $worker->name;
|
||||||
$params ['worker_tel'] = $worker->tel;
|
$params ['worker_tel'] = $worker->tel;
|
||||||
|
|
||||||
//记录日志
|
//记录日志
|
||||||
OrderDispatchLog::create([
|
$remark = '师傅由 ('.$row->worker_id.')'.$row->worker_name.' 更换为('.$params['worker_id'].')'.$worker->name;
|
||||||
'dispatch_id' => $row->id,
|
$workerChange = true;
|
||||||
'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
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
$result = $row->allowField(true)->save($params);
|
$result = $row->allowField(true)->save($params);
|
||||||
|
|
||||||
|
if($workerChange){
|
||||||
|
$hookParams = [
|
||||||
|
'dispatch' => $row,
|
||||||
|
'remark' => $remark,
|
||||||
|
];
|
||||||
|
Hook::listen('order_dispatch_change', $hookParams);
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
} catch (ValidateException | PDOException | Exception $e) {
|
} catch (ValidateException | PDOException | Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
|
|
|
||||||
|
|
@ -43,4 +43,8 @@ return [
|
||||||
'app\\admin\\behavior\\OrderLog',
|
'app\\admin\\behavior\\OrderLog',
|
||||||
'app\\admin\\behavior\\OrderChangeAfter',
|
'app\\admin\\behavior\\OrderChangeAfter',
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'order_dispatch_change' => [
|
||||||
|
'app\\admin\\behavior\\OrderDispatchLog',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user