From 4c26d857e8aec263d9b72bbf7ab9618db7f91d23 Mon Sep 17 00:00:00 2001 From: xman <1946321327@qq.com> Date: Wed, 26 Mar 2025 20:12:03 +0800 Subject: [PATCH] sth --- .../admin/controller/orders/Dispatch2.php | 63 ++++++++++ .../admin/view/orders/dispatch2/index.html | 18 +-- public/assets/js/backend/orders/dispatch2.js | 114 +++++++++--------- 3 files changed, 130 insertions(+), 65 deletions(-) diff --git a/application/admin/controller/orders/Dispatch2.php b/application/admin/controller/orders/Dispatch2.php index b49c8c7..246301f 100644 --- a/application/admin/controller/orders/Dispatch2.php +++ b/application/admin/controller/orders/Dispatch2.php @@ -289,4 +289,67 @@ class Dispatch2 extends Backend return $workers; } + + /** + * 取消派单 + * + * @param $ids + * @return void + * @throws DbException + * @throws DataNotFoundException + * @throws ModelNotFoundException + */ + public function cancel() + { + if (false === $this->request->isPost()) { + $this->error(__("Invalid parameters")); + } + $ids = $this->request->post("ids/a"); + $reason = $this->request->post("reason"); + + 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 = $reason; + $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; + $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(); + $this->error($e->getMessage()); + } + /* if ($count) { + $this->success(); + }*/ + $this->success(__('取消成功')); + } + } diff --git a/application/admin/view/orders/dispatch2/index.html b/application/admin/view/orders/dispatch2/index.html index 28d4130..e083a7b 100644 --- a/application/admin/view/orders/dispatch2/index.html +++ b/application/admin/view/orders/dispatch2/index.html @@ -24,16 +24,18 @@ {:__('创建异常')} + {:__('取消任务')} - + + diff --git a/public/assets/js/backend/orders/dispatch2.js b/public/assets/js/backend/orders/dispatch2.js index 0d7afc9..18da9a6 100644 --- a/public/assets/js/backend/orders/dispatch2.js +++ b/public/assets/js/backend/orders/dispatch2.js @@ -8,7 +8,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, index_url: 'orders/dispatch2/index' + location.search, //add_url: 'orders/dispatch/add', edit_url: 'orders/dispatch2/edit', - del_url: 'orders/dispatc2h/del', + //del_url: 'orders/dispatc2h/del', multi_url: 'orders/dispatch2/multi', import_url: 'orders/dispatch2/import', table: 'order_dispatch', @@ -82,62 +82,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, return false; } }, - { - name: 'del', - text:"取消", - title:"取消", - icon: 'fa fa-trash', - //title: __('Del'), - extend: 'data-toggle="tooltip" data-container="body"', - classname: 'btn btn-xs btn-danger btn-delone', - click: function (data, row) { - layer.prompt({ - formType: 2, - value: '', - title: '请输入备注', - maxlength: 140, - },function(value, index, elem) { - var url = 'orders/dispatch2/del' + row.id; - var options = {url: url, data: {remark: value}}; - Fast.api.ajax(options, function (data, ret) { - // table.trigger("uncheckbox"); - table.bootstrapTable('refresh'); - }) - },function (data, ret) { - var error = $(this).data("error") || $.noop; - if (typeof error === 'function') { - if (false === error.call(this, data, ret)) { - return false; - } - } - }); - layer.close(index); - }, - visible:function(row){ - if(row.btn_cancel){ - return true; - } - return false; - }, - }, - { - name:"abnormal", - text:"创建异常", - title:"创建异常", - classname:"btn-add btn-dialog", - icon:'fa fa-add', - url:function(row) { - return "orders/abnormal/add?order_id="+row.order_id - }, - dropdown:"更多", - visible:function(row){ - if(row.btn_income){ - return true; - } - return false; - }, - //refresh:true, - } ], } @@ -147,6 +91,62 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, // 为表格绑定事件 Table.api.bindevent(table); + + + // 获取选中项 + $(document).on("click", ".btn-cancel-selected", function () { + //Layer.alert(JSON.stringify(Table.api.selecteddata(table))); + + // 获取选中项的 ID + var selectedData = Table.api.selecteddata(table); + var selectedIds = selectedData.map(item => item.id); // 假设每行数据有 `id` 字段 + + if (selectedIds.length === 0) { + Layer.alert("请先选择至少一项数据!"); + return; + } + + // 弹出确认框并要求输入文本 + Layer.prompt({ + title: "请输入操作理由", + formType: 2, // 多行文本输入框 + }, function (inputValue, index) { + if (!inputValue) { + Layer.alert("输入内容不能为空!"); + return; + } + + // 关闭弹出框 + Layer.close(index); + + //这里可以加入 Ajax 请求处理逻辑 + $.ajax({ + url: 'orders/dispatch2/cancel', + type: 'POST', + data: { + ids: selectedIds, + reason: inputValue, + }, + success: function (response,data) { + if(response.code == 1){ + // 成功提示 + Toastr.success(data.message || "操作成功!"); + // 刷新表格 + table.bootstrapTable('refresh'); + }else{ + Toastr.error(response.msg || "操作失败!"); + } + return; + }, + error: function () { + Toastr.error("操作失败,请重试!"); + return; + } + }); + }); + + }); + }, add: function () { Controller.api.bindevent();