From fe115b963e0563461fff36cb55d5eb265cbf8e74 Mon Sep 17 00:00:00 2001 From: hant Date: Thu, 5 Jun 2025 22:01:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Test.php | 4 +- .../admin/controller/AutoDispatchLogic.php | 5 +- application/admin/controller/Order.php | 97 +++++++++++++------ .../admin/controller/orders/Abnormal.php | 23 ++++- .../admin/view/orders/abnormal/edit.html | 2 +- application/common/Logic/OrderLogic.php | 8 +- application/config.php | 4 +- public/assets/js/backend/orders/abnormal.js | 4 +- 8 files changed, 106 insertions(+), 41 deletions(-) diff --git a/application/admin/command/Test.php b/application/admin/command/Test.php index 0c2e103..ef5fc4e 100644 --- a/application/admin/command/Test.php +++ b/application/admin/command/Test.php @@ -34,11 +34,11 @@ class Test extends Command protected function execute(Input $input, Output $output) { - + dd(config('system_id')); $order = Order::where('id',140)->find(); AutoDispatchLogic::autoDispatch($order); - dd(2); + $hookParams = [ 'dispatch' => (new OrderDispatch())->where('id', 144)->find(), diff --git a/application/admin/controller/AutoDispatchLogic.php b/application/admin/controller/AutoDispatchLogic.php index 39298c4..82e37d7 100644 --- a/application/admin/controller/AutoDispatchLogic.php +++ b/application/admin/controller/AutoDispatchLogic.php @@ -29,8 +29,8 @@ class AutoDispatchLogic } //$admin = Admin::where('id',$order->admin_id)->find(); $insert = [ - 'admin_id' => 1, - 'admin_user' => '系统', + 'admin_id' => config('system_id'), + 'admin_user' => config('system_name'), 'order_id' => $order->id, 'type' => 2, 'worker_id' => $worker_id, @@ -48,6 +48,7 @@ class AutoDispatchLogic $order->dispatch_admin_id = 1; $order->dispatch_admin_user = '系统'; $order->worker_id = $worker_id; + $order->dispatch_type = 2; $order->save(); diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index ef6eff8..1c45169 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -120,7 +120,7 @@ class Order extends Backend public function index() { $this->request->filter(['strip_tags', 'trim']); - $group = \model('auth_group_access')->where('uid',$this->auth->id)->find()->group_id ?? 0; + $group = \model('auth_group_access')->where('uid', $this->auth->id)->find()->group_id ?? 0; $user = \model('admin')->find($this->auth->id); @@ -132,7 +132,7 @@ class Order extends Backend return $this->selectpage(); } - $type = request()->get('type',1); + $type = request()->get('type', 1); [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $build = $this->model @@ -148,25 +148,25 @@ class Order extends Backend $filter = (array)json_decode(input()['filter'] ?? '', true); $admin_filter = $filter['user.nickname'] ?? false; - if ($admin_filter){ - $admin_ids = Admin::where('nickname','like','%'.$admin_filter.'%')->column('id'); - $build->whereIn('admin_id',$admin_ids); + if ($admin_filter) { + $admin_ids = Admin::where('nickname', 'like', '%' . $admin_filter . '%')->column('id'); + $build->whereIn('admin_id', $admin_ids); } - if ($type == 1){ - $build->where('status','>=', 0); + if ($type == 1) { + $build->where('status', '>=', 0); } - if ($type == 2){ - $build->where('status','<', 0); + if ($type == 2) { + $build->where('status', '<', 0); } if ($group == 2 || $group == 6) { // 生成 SQL 语句 - $ids = $user->area_ids??''; - if ($ids == ''){ + $ids = $user->area_ids ?? ''; + if ($ids == '') { return ['total' => 0, 'rows' => []]; } - $ids = explode(',',$ids); + $ids = explode(',', $ids); $area_codes = $this->filterAreaCodes($ids); $build->where(function ($q) use ($area_codes) { @@ -185,15 +185,15 @@ class Order extends Backend $q->field('id,area_code,merge_name'); }, 'phone' => function ($q) { $q->field('id,model'); - },'coupon' => function ($q) { + }, 'coupon' => function ($q) { $q->field('id,code,description'); }]) ->order($sort, $order) ->paginate($limit); - foreach ($list as &$item){ + foreach ($list as &$item) { $item->aftersale_btn = false; - if($item->aftersale_id==0 && $this->auth->check('aftersales/aftersale/add') && $item->status == \app\admin\model\Order::STATUS_FINISHED){ //$item->status == \app\admin\model\Order::STATUS_FINISHED && + if ($item->aftersale_id == 0 && $this->auth->check('aftersales/aftersale/add') && $item->status == \app\admin\model\Order::STATUS_FINISHED) { //$item->status == \app\admin\model\Order::STATUS_FINISHED && $item->aftersale_btn = true; } } @@ -248,7 +248,7 @@ class Order extends Backend $result = $this->model->allowField(true)->save($params); if ($params['dispatch_type'] == 2) { - AutoDispatchLogic::autoDispatch($this->model,$this->auth); + AutoDispatchLogic::autoDispatch($this->model, $this->auth); } Db::commit(); } catch (ValidateException | PDOException | Exception $e) { @@ -361,9 +361,6 @@ class Order extends Backend } - - - public function smart() { $this->success(data: Address::smart(request()->get('str'))); @@ -466,12 +463,13 @@ class Order extends Backend $result = false; Db::startTrans(); try { + $abnormal_title = model('abnormal')->get($params['abnormal_id'])->title ?? ''; $insert = [ 'order_id' => $params['order_id'], 'status' => 0, 'level' => $params['level'], 'abnormal_id' => $params['abnormal_id'], - 'abnormal_title' => model('abnormal')->get($params['abnormal_id'])->title ?? '', + 'abnormal_title' => $abnormal_title, 'detail' => $params['detail'], 'admin_id' => $this->auth->id, 'admin_user' => $this->auth->getUserInfo()['nickname'] ?? '', @@ -479,16 +477,59 @@ class Order extends Backend 'update_time' => now()->format('Y-m-d H:m:s'), ]; - Message::create([ - 'to_id' => $order->admin_id, - 'type' => 1, - 'title' => '订单报错通知', - 'content' => '【订单报错通知】您有一条订单号为' . $order->order_no . '的订单订单信息录入错误,请前往报错订单界面进行查看,并立即处理!' - ]); + + if ($params['abnormal_id'] == 2 || $params['abnormal_id'] == 3) { + + $order->status = \app\admin\model\Order::STATUS_CANCEL; + $order->save(); + if (!empty($order->dispatch->id)) { + $orderLogic = new OrderLogic(); + $orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false); + //日志 + $hookparams['order'] = $order; + $hookparams['role'] = 1; + $hookparams['auth'] = $this->auth; + $hookparams['remark'] = $params['remark'] ?? ''; + Hook::listen('order_change', $hookparams); + } + + $insert['deal_type'] = 2; + $insert['handle_detail'] = '系统取消订单'; + $insert['handle_admin_user'] = config('system_name'); + $insert['handle_admin_id'] = config('system_id'); + $insert['handle_time'] = now()->format('Y-m-d H:i:s'); + $insert['status'] = 1; + + } else if ($params['abnormal_id'] == 5 || $params['abnormal_id'] == 15) { + + $order->status = \app\admin\model\Order::STATUS_DISPATCHING; + $order->save(); + if (!empty($order->dispatch->id)) { + $OrderLogic = new OrderLogic(); + $OrderLogic->noWorkerCanGetIt($order->dispatch, '系统取消' . $abnormal_title); + AutoDispatchLogic::autoDispatch($order); + } + + $insert['deal_type'] = 3; + $insert['handle_detail'] = '系统重新派单'; + $insert['handle_admin_user'] = config('system_name'); + $insert['handle_admin_id'] = config('system_id'); + $insert['handle_time'] = now()->format('Y-m-d H:i:s'); + $insert['status'] = 1; + } else { + Message::create([ + 'to_id' => $order->admin_id, + 'type' => 1, + 'title' => '订单报错通知', + 'content' => '【订单报错通知】您有一条订单号为' . $order->order_no . '的订单订单信息录入错误,请前往报错订单界面进行查看,并立即处理!' + ]); + } + $result = \model('order_abnormal')->insert($insert); Db::commit(); } catch (ValidateException | PDOException | Exception $e) { + throw $e; Db::rollback(); $this->error($e->getMessage()); } @@ -536,11 +577,11 @@ class Order extends Backend if (!empty($order->dispatch->id)) { $orderLogic = new OrderLogic(); - $orderLogic->cancelOrderDispatch($order->dispatch, $this->auth, '订单被取消', false); + $orderLogic->cancelOrderDispatch($order->dispatch, null, '订单被取消', false); //日志 $hookparams['order'] = $order; $hookparams['role'] = 1; - $hookparams['auth'] = $this->auth; + $hookparams['auth'] = null; $hookparams['remark'] = $params['remark'] ?? ''; Hook::listen('order_change', $hookparams); } diff --git a/application/admin/controller/orders/Abnormal.php b/application/admin/controller/orders/Abnormal.php index 0e55b82..a68c8b4 100644 --- a/application/admin/controller/orders/Abnormal.php +++ b/application/admin/controller/orders/Abnormal.php @@ -2,6 +2,7 @@ namespace app\admin\controller\orders; +use app\admin\controller\AutoDispatchLogic; use app\admin\model\Order; use app\common\controller\Backend; use app\common\Logic\OrderLogic; @@ -130,10 +131,7 @@ class Abnormal extends Backend if ($params['abnormal_id'] == 2 || $params['abnormal_id'] == 3){ - $order->status = Order::STATUS_CANCEL; - $order->abnormal_id = $params['abnormal_id']; - $order->abnormal_title = $abnormal_title; $order->save(); if (!empty($order->dispatch->id)) { $orderLogic = new OrderLogic(); @@ -146,8 +144,27 @@ class Abnormal extends Backend Hook::listen('order_change', $hookparams); } + $params['deal_type'] = 2; + $params['handle_detail'] = '系统取消订单'; + $params['handle_admin_user'] = config('system_name'); + $params['handle_admin_id'] = config('system_id'); + $params['status'] = 1; + } + if ($params['abnormal_id'] == 5 || $params['abnormal_id'] == 15){ + if (!empty($order->dispatch->id)) { + $OrderLogic = new OrderLogic(); + $OrderLogic->noWorkerCanGetIt($order->dispatch,'系统取消'.$abnormal_title); + AutoDispatchLogic::autoDispatch($order); + } + + $params['deal_type'] =3; + $params['handle_detail'] = '系统重新派单'; + $params['handle_admin_user'] = config('system_name'); + $params['handle_admin_id'] = config('system_id'); + $params['status'] = 1; + } $result = $this->model->allowField(true)->save($params); diff --git a/application/admin/view/orders/abnormal/edit.html b/application/admin/view/orders/abnormal/edit.html index 29c05bb..8f43c3e 100644 --- a/application/admin/view/orders/abnormal/edit.html +++ b/application/admin/view/orders/abnormal/edit.html @@ -31,7 +31,7 @@
- +