添加日志

This commit is contained in:
xman 2025-04-14 10:44:19 +08:00
parent 4da8536a47
commit b042e4904c
2 changed files with 39 additions and 30 deletions

View File

@ -8,6 +8,7 @@ use app\admin\model\OrderDispatch;
use app\admin\model\Worker;
use app\admin\model\WorkerItem;
use app\common\controller\Backend;
use app\common\Logic\OrderLogic;
use fast\Tree;
use think\Db;
use think\exception\PDOException;
@ -210,16 +211,16 @@ class Order extends Backend
$result = $this->model->allowField(true)->save($params);
if ($params['dispatch_type'] == 2) {
$this->autoDispatch($this->model);
}
//日志
$hookparams['order'] = $this->model;
$hookparams['order'] = $this->model->get($this->model->id);
$hookparams['role'] = 1;
$hookparams['auth'] = $this->auth;
$hookparams['remark'] = $params['remark']??'';
Hook::listen('order_change', $hookparams);
if ($params['dispatch_type'] == 2) {
$this->autoDispatch($this->model);
}
Db::commit();
} catch (ValidateException | PDOException | Exception $e) {
Db::rollback();
@ -373,17 +374,17 @@ class Order extends Backend
$worker = (new Worker())->where('id', $worker_id)->find();
$insert ['worker_name'] = $worker['name'];
$insert ['worker_tel'] = $worker['tel'];
(new OrderDispatch())->allowField(true)->save($insert);
$orderDispatch = new OrderDispatch();
$orderDispatch->allowField(true)->save($insert);
$order->status = \app\admin\model\Order::STATUS_DISPATCHED;
$order->save();
//日志
$hookparams['order'] = $order;
$hookparams['role'] = 1;
$hookparams['auth'] = $this->auth;
$hookparams['remark'] = $params['remark']??'';
Hook::listen('order_change', $hookparams);
$hookParams = [
'dispatch' => $orderDispatch,
'remark' => '',
];
Hook::listen('order_dispatch_change', $hookParams);
return true;
@ -433,7 +434,7 @@ class Order extends Backend
'abnormal_title' => model('abnormal')->get($params['abnormal_id'])->title ?? '',
'detail' => $params['detail'],
'admin_id' => $this->auth->id,
'admin_user' => $this->auth->getUserInfo()['username'] ?? '',
'admin_user' => $this->auth->getUserInfo()['nickname'] ?? '',
'create_time' => now()->format('Y-m-d H:m:s'),
'update_time' => now()->format('Y-m-d H:m:s'),
];
@ -472,13 +473,18 @@ class Order extends Backend
$result = false;
Db::startTrans();
try {
$order = model('order')->get($params['order_id']);
$order = model('order')->get($params['order_id'],['dispatch']);
if (!$order){
$this->error('Not Find');
}
$params['status'] = \app\admin\model\Order::STATUS_CANCEL;
$result = $order->allowField(true)->save($params);
if(!empty($order->dispatch)){
$orderLogic = new OrderLogic();
$orderLogic->cancelOrderDispatch($order->dispatch,$this->auth,$params['remark']??'后台取消',false);
}
//日志
$hookparams['order'] = $order;
$hookparams['role'] = 1;

View File

@ -112,26 +112,10 @@ class OrderLogic
* @param Dispatch $dispatch
* @return void
*/
public function cancelOrderDispatch(OrderDispatch $dispatch,$auth=null,$remark='')
public function cancelOrderDispatch(OrderDispatch $dispatch,$auth=null,$remark='',$cancelOrder=true)
{
$order = Order::where('id',$dispatch->id)->where('status',Order::STATUS_DISPATCHED)->find();
if(!empty($order)){
throw new Exception('未找到关联订单');
}
//取消
$dispatch->allowField(true)->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]);
//回退订单状态
$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
$params['order'] = $order;
$params['role'] = 1;
$params['auth'] = $auth;
$params['remark'] = '任务被取消[ID' . $dispatch->id . '],订单状态回退';
if (!empty($remark)) {
$params['remark'] .= ',备注:' . $remark;
}
Hook::listen('order_change', $params);
$hookParams = [
'dispatch' => $dispatch,
@ -139,6 +123,25 @@ class OrderLogic
];
Hook::listen('order_dispatch_change', $hookParams);
if($cancelOrder){
$order = Order::where('id',$dispatch->id)->where('status',Order::STATUS_DISPATCHED)->find();
if(!empty($order)){
throw new Exception('未找到关联订单');
}
//回退订单状态
$order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]);
$params['order'] = $order;
$params['role'] = 1;
$params['auth'] = $auth;
$params['remark'] = '任务被取消[ID' . $dispatch->id . '],订单状态回退';
if (!empty($remark)) {
$params['remark'] .= ',备注:' . $remark;
}
Hook::listen('order_change', $params);
}
}
}