From 80a65b325f9641cdf9d0205010ed353653283daa Mon Sep 17 00:00:00 2001 From: xman <1946321327@qq.com> Date: Thu, 27 Mar 2025 14:33:49 +0800 Subject: [PATCH] =?UTF-8?q?cancel=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/orders/Dispatch2.php | 116 +++++++++--------- .../admin/view/orders/dispatch2/edit.html | 2 +- .../admin/view/orders/dispatch2/index.html | 2 +- public/assets/js/backend/orders/dispatch2.js | 2 +- 4 files changed, 58 insertions(+), 64 deletions(-) diff --git a/application/admin/controller/orders/Dispatch2.php b/application/admin/controller/orders/Dispatch2.php index 246301f..9df5649 100644 --- a/application/admin/controller/orders/Dispatch2.php +++ b/application/admin/controller/orders/Dispatch2.php @@ -228,66 +228,56 @@ class Dispatch2 extends Backend * @throws DataNotFoundException * @throws ModelNotFoundException */ - public function del($ids = null) - { - if (false === $this->request->isPost()) { - $this->error(__("Invalid parameters")); - } - $ids = $ids ?: $this->request->post("ids"); - if (empty($ids)) { - $this->error(__('Parameter %s can not be empty', 'ids')); - } - $pk = $this->model->getPk(); - $adminIds = $this->getDataLimitAdminIds(); - if (is_array($adminIds)) { - $this->model->where($this->dataLimitField, 'in', $adminIds); - } - $list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select(); - - $remark = $this->request->param('remark', ''); - - $count = 0; - Db::startTrans(); - try { - foreach ($list as $item) { - //$count += $item->delete(); - $order = Order::where('id', $item->order_id)->where('status', Order::STATUS_DISPATCHED)->find(); - if (!$order) { - $this->error('订单状态已变更,请刷新后操作'); - } - //取消 - $item->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]); - //回退订单状态 - $order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]); - - $params['order'] = $order->ref; - $params['role'] = 1; - $params['auth'] = $this->auth; - $params['remark'] = '派单被取消[ID:' . $item->id . '],订单状态回退'; - if (!empty($remark)) { - $params['remark'] .= ',操作备注:' . $remark; - } - Hook::listen('order_change', $params); - } - Db::commit(); - } catch (PDOException | Exception $e) { - Db::rollback(); - throw $e; - $this->error($e->getMessage()); - } - /* if ($count) { - $this->success(); - }*/ - $this->error(__('取消成功')); - } - - private function getWorkers($workers) - { - foreach ($workers as $worker){ - $worker->dist = '100m'; - } - return $workers; - } +// public function del($ids = null) +// { +// if (false === $this->request->isPost()) { +// $this->error(__("Invalid parameters")); +// } +// $ids = $ids ?: $this->request->post("ids"); +// if (empty($ids)) { +// $this->error(__('Parameter %s can not be empty', 'ids')); +// } +// $pk = $this->model->getPk(); +// $adminIds = $this->getDataLimitAdminIds(); +// if (is_array($adminIds)) { +// $this->model->where($this->dataLimitField, 'in', $adminIds); +// } +// $list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select(); +// +// $remark = $this->request->param('remark', ''); +// +// $count = 0; +// Db::startTrans(); +// try { +// foreach ($list as $item) { +// //$count += $item->delete(); +// $order = Order::where('id', $item->order_id)->where('status', Order::STATUS_DISPATCHED)->find(); +// if (!$order) { +// $this->error('订单状态已变更,请刷新后操作'); +// } +// //取消 +// $item->save(['status' => OrderDispatch::STATUS_CANCEL, 'remark' => $remark]); +// //回退订单状态 +// $order->allowField(true)->save(['status' => Order::STATUS_DISPATCHING]); +// +// $params['order'] = $order->ref; +// $params['role'] = 1; +// $params['auth'] = $this->auth; +// $params['remark'] = '派单被取消[ID:' . $item->id . '],订单状态回退'; +// if (!empty($remark)) { +// $params['remark'] .= ',操作备注:' . $remark; +// } +// Hook::listen('order_change', $params); +// } +// Db::commit(); +// } catch (PDOException | Exception $e) { +// Db::rollback(); +// throw $e; +// $this->error($e->getMessage()); +// } +// +// $this->error(__('取消成功')); +// } /** @@ -299,7 +289,7 @@ class Dispatch2 extends Backend * @throws DataNotFoundException * @throws ModelNotFoundException */ - public function cancel() + public function del() { if (false === $this->request->isPost()) { $this->error(__("Invalid parameters")); @@ -317,6 +307,10 @@ class Dispatch2 extends Backend } $list = $this->model->where($pk, 'in', $ids)->whereIn('status', $this->model->deleteStatusList())->select(); + if(count($list) != count($ids)){ + $this->error(__("任务状态不可操作,请刷新页面后再操作")); + } + $remark = $reason; $count = 0; Db::startTrans(); diff --git a/application/admin/view/orders/dispatch2/edit.html b/application/admin/view/orders/dispatch2/edit.html index 4464e69..9894a63 100644 --- a/application/admin/view/orders/dispatch2/edit.html +++ b/application/admin/view/orders/dispatch2/edit.html @@ -10,7 +10,7 @@
- +
diff --git a/application/admin/view/orders/dispatch2/index.html b/application/admin/view/orders/dispatch2/index.html index e083a7b..0eacde7 100644 --- a/application/admin/view/orders/dispatch2/index.html +++ b/application/admin/view/orders/dispatch2/index.html @@ -24,7 +24,7 @@ {:__('创建异常')} - {:__('取消任务')} + {:__('取消任务')} diff --git a/public/assets/js/backend/orders/dispatch2.js b/public/assets/js/backend/orders/dispatch2.js index 18da9a6..86fae35 100644 --- a/public/assets/js/backend/orders/dispatch2.js +++ b/public/assets/js/backend/orders/dispatch2.js @@ -121,7 +121,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, //这里可以加入 Ajax 请求处理逻辑 $.ajax({ - url: 'orders/dispatch2/cancel', + url: 'orders/dispatch2/del', type: 'POST', data: { ids: selectedIds,