dispatch 增加变更日志

This commit is contained in:
xman 2025-03-31 11:33:44 +08:00
parent b77ccfe5f8
commit 65aea57786
2 changed files with 16 additions and 85 deletions

View File

@ -30,7 +30,7 @@ class Dispatch2 extends Backend
*/
protected $model = null;
protected $searchFields = 'order.order_no,order.tel,order.customer,worker_name,worker_tel';
protected $searchFields = 'order.id,order.order_no,order.tel,order.customer,worker_name,worker_tel';
public function _initialize()
{
@ -92,88 +92,6 @@ class Dispatch2 extends Backend
}
/**
* 添加
*
* @return string
* @throws \think\Exception
*/
public function add()
{
if (false === $this->request->isPost()) {
$id = $this->request->param('order_id');
$order = model('order')->where('id', $id)->find();
if (!$order) {
$this->error(__('No results were found'));
}
$items = Db::name('item')
->where('status',1)
->field(['id','title','key_word','pid'])
->order('pid','asc')
->order('sort','desc')
->select();
$tree = $this->buildTree($items);
$formattedTree = $this->formatTree($tree);
$area_name = model('area')->getNameByCode($order->area_id);
$order->area_name = str_replace(',','/',$area_name);
$this->view->assign('items', $formattedTree);
$this->view->assign('row', $order);
return $this->view->fetch();
}
$params = $this->request->post('row/a');
if (empty($params)) {
$this->error(__('Parameter %s can not be empty', ''));
}
$params = $this->preExcludeFields($params);
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
$params[$this->dataLimitField] = $this->auth->id;
}
$result = false;
Db::startTrans();
try {
//是否采用模型验证
if ($this->modelValidate) {
$name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
$validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.add' : $name) : $this->modelValidate;
$this->model->validateFailException()->validate($validate);
}
$order = model('order')->where('id',$params['order_id'])->find();
if (!$order){
$this->error(__('No results were found'));
}
$insert = [
'admin_id' => $this->auth->id,
'admin_user' => $this->auth->nickname,
'order_id' => $params['order_id'],
'type' => 1,
'worker_id' => $params['worker_id'],
'plan_time' => $order['plan_time'],
'is_receipt' => $order['receive_type'] == 1
];
$worker = model('worker')->where('id',$params['worker_id'])->find();
$insert ['worker_name'] = $worker->name;
$insert ['worker_tel'] = $worker->tel;
$result = $this->model->allowField(true)->save($insert);
$order->status = Order::STATUS_DISPATCHED;
$order->save();
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
if ($result === false) {
$this->error(__('No rows were inserted'));
}
$this->success();
}
/**
* 编辑
*
@ -327,7 +245,7 @@ class Dispatch2 extends Backend
//修改订单状态
$OrderLogic = new OrderLogic();
$OrderLogic -> dispachFinishAfter($row,['role'=>1,'auth'=>$this->auth]);
$OrderLogic -> dispachFinishAfter($row,['role'=>1,'auth'=>$this->auth,'remark'=>'后台操作adminId:'.$this->auth->id]);
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
@ -443,7 +361,7 @@ class Dispatch2 extends Backend
$this->error('订单状态已变更,请刷新后操作');
}
//取消
$item->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
$item->allowField(true)->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
//回退订单状态
$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
$params['order'] = $order;
@ -454,6 +372,12 @@ class Dispatch2 extends Backend
$params['remark'] .= ',操作备注:' . $remark;
}
Hook::listen('order_change', $params);
$hookParams = [
'dispatch' => $item,
'remark' => '后台取消,adminId:'.$this->auth->id
];
Hook::listen('order_dispatch_change', $hookParams);
}
Db::commit();
} catch (PDOException | Exception $e) {

View File

@ -57,6 +57,13 @@ class OrderLogic
$params['remark'] = $roleInfo['remark'] ?? $orderDispatch->remark;
Hook::listen('order_change', $params);
$hookParams = [
'dispatch' => $orderDispatch,
'remark' => $roleInfo['remark'] ?? $orderDispatch->remark,
];
Hook::listen('order_dispatch_change', $hookParams);
}
}