From d986cd7b69034b23a9db4cc9c59f7811aeca3b34 Mon Sep 17 00:00:00 2001 From: xman <1946321327@qq.com> Date: Tue, 25 Mar 2025 09:22:41 +0800 Subject: [PATCH] sth --- .../admin/controller/orders/Dispatch2.php | 292 ++++++++++++++++++ .../admin/lang/zh-cn/orders/dispatch2.php | 82 +++++ .../admin/view/orders/dispatch2/add.html | 110 +++++++ .../admin/view/orders/dispatch2/edit.html | 55 ++++ .../admin/view/orders/dispatch2/index.html | 51 +++ public/assets/js/backend/orders/dispatch2.js | 164 ++++++++++ 6 files changed, 754 insertions(+) create mode 100644 application/admin/controller/orders/Dispatch2.php create mode 100644 application/admin/lang/zh-cn/orders/dispatch2.php create mode 100644 application/admin/view/orders/dispatch2/add.html create mode 100644 application/admin/view/orders/dispatch2/edit.html create mode 100644 application/admin/view/orders/dispatch2/index.html create mode 100644 public/assets/js/backend/orders/dispatch2.js diff --git a/application/admin/controller/orders/Dispatch2.php b/application/admin/controller/orders/Dispatch2.php new file mode 100644 index 0000000..b49c8c7 --- /dev/null +++ b/application/admin/controller/orders/Dispatch2.php @@ -0,0 +1,292 @@ +model = new \app\admin\model\OrderDispatch; + $this->view->assign("typeList", $this->model->getTypeList()); + $this->view->assign("statusList", $this->model->getStatusList()); + + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + /** + * 查看 + */ + public function index() + { + //当前是否为关联查询 + $this->relationSearch = true; + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if ($this->request->isAjax()) { + //如果发送的来源是Selectpage,则转发到Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + list($where, $sort, $order, $offset, $limit) = $this->buildparams(); + + $list = $this->model + ->with(['order']) + ->where($where) + ->order($sort, $order) + ->paginate($limit); + + foreach ($list as &$row) { + $row->btn_edit = (in_array($row->status, $this->model->btnActiveStatusList('btn_edit'))) ? true : false; + $row->btn_cancel = (in_array($row->status, $this->model->btnActiveStatusList('btn_cancel'))) ? true : false; + $row->btn_abnormal = (in_array($row->status, $this->model->btnActiveStatusList('btn_abnormal'))) ? true : false; + // $row->btn_income = (in_array($row->status, $this->model->btnActiveStatusList('btn_income')) && in_array($row->order->status, $orderModel->incomeBtnStatus())) ? true : false; + } + $result = array("total" => $list->total(), "rows" => $list->items()); + + return json($result); + } + return $this->view->fetch(); + } + + + /** + * 添加 + * + * @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(); + } + + /** + * 编辑 + * + * @param $ids + * @return string + * @throws DbException + * @throws \think\Exception + */ + public function edit($ids = null) + { + $row = $this->model->get($ids); + if (!$row) { + $this->error(__('No Results were found')); + } + $adminIds = $this->getDataLimitAdminIds(); + if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) { + $this->error(__('You have no permission')); + } + if (false === $this->request->isPost()) { + $this->view->assign('row', $row); + 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); + $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 . '.edit' : $name) : $this->modelValidate; + $row->validateFailException()->validate($validate); + } + $result = $row->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException | PDOException | Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if (false === $result) { + $this->error(__('No rows were updated')); + } + $this->success(); + } + + /** + * 取消派单 + * + * @param $ids + * @return void + * @throws DbException + * @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; + } + +} diff --git a/application/admin/lang/zh-cn/orders/dispatch2.php b/application/admin/lang/zh-cn/orders/dispatch2.php new file mode 100644 index 0000000..9fc67a1 --- /dev/null +++ b/application/admin/lang/zh-cn/orders/dispatch2.php @@ -0,0 +1,82 @@ + 'ID', + 'Order_id' => '订单ID', + 'Type' => '派单方式', + 'Type 1' => '手动', + 'Worker_id' => '师傅ID', + 'Worker_name' => '师傅姓名', + 'Worker_tel' => '师傅电话', + 'Status' => '进度', + 'Status 0' => '待接单', + 'Set status to 0' => '设为待接单', + 'Status 10' => '已接单', + 'Set status to 10' => '设为已接单', + 'Status 25' => '已开始', + 'Set status to 25' => '设为已开始', + 'Status 20' => '已预约', + 'Set status to 20' => '设为已预约', + 'Status 30' => '已打卡', + 'Set status to 30' => '设为已打卡', + 'Status 60' => '已完成', + 'Set status to 60' => '设为已完成', + 'Status -10' => '已拒接', + 'Set status to -10' => '设为已拒接', + 'Status -20' => '已移交', + 'Set status to -20' => '设为已移交', + 'Status -30' => '已取消', + 'Set status to -30' => '设为已取消', + 'Remark' => '备注', + 'Notice_num' => '通知次数', + 'Plan_time' => '预约时间', + 'Finish_time' => '完成时间', + 'Admin_id' => '派单人ID', + 'Admin_user' => '派单人', + 'Create_time' => '派单时间', + 'Update_time' => '编辑时间', + 'Order.id' => 'ID', + 'Order.order_no' => '订单号', + 'Order.customer' => '客户姓名', + 'Order.tel' => '客户电话', + 'Order.status' => '订单状态', + 'Order.status 10' => '未派单', + 'Order.status 20' => '已派单', + 'Order.status 30' => '进行中', + 'Order.status 40' => '待验收', + 'Order.status 41' => '审核驳回', + 'Order.status 50' => '待财务审核', + 'Order.status 60' => '已完成', + 'Order.status -10' => '取消', + 'Order.area_id' => '地域', + 'Order.address' => '详细地址', + 'Order.lng' => '经度', + 'Order.lat' => '纬度', + 'Order.work_tel_id' => '工作机', + 'Order.source_shop' => '来源店铺', + 'Order.source' => '订单来源', + 'Order.source_uid' => '来源UID', + 'Order.item_id' => '服务ID', + 'Order.item_title' => '服务名称', + 'Order.detail' => '订单详情', + 'Order.remark' => '订单备注', + 'Order.images' => '图片', + 'Order.plan_time' => '客户预约时间', + 'Order.admin_id' => '录单员ID', + 'Order.coupon_id' => '优惠码id', + 'Order.total' => '总收款', + 'Order.online_amount' => '线上收款', + 'Order.offline_amount' => '线下收款', + 'Order.discount_amount' => '优惠抵扣', + 'Order.refund_amount' => '总退款额', + 'Order.real_amount' => '实际收款', + 'Order.cost' => '师傅成本', + 'Order.performance' => '预计利润', + 'Order.cancel_reason_id' => '取消原因', + 'Order.cancel_detail' => '取消详情', + 'Order.audit_remark' => '审核备注', + 'Order.audit_admin_id' => '审核员', + 'Order.create_time' => '录单时间', + 'Order.update_time' => '更新时间', + 'Order.delete_time' => '删除时间' +]; diff --git a/application/admin/view/orders/dispatch2/add.html b/application/admin/view/orders/dispatch2/add.html new file mode 100644 index 0000000..47b59d9 --- /dev/null +++ b/application/admin/view/orders/dispatch2/add.html @@ -0,0 +1,110 @@ +
+
+ +
+
+

订单详情

+

订单编号: {$row.order_no}

+

顾客信息: {$row.customer} 电话:{$row.tel}

+

订单来源: {$row.source_shop} 单号:{$row.source_uid}

+

区域: {$row.area_name}

+

地址: {$row.address}

+

订单类型: {$row.item_title}

+

订单详情: {$row.detail}

+

订单备注: {$row.remark}

+ + +
+
+
+ +
+ + +
+
+ +
+ +
+ +
+
+ + + +
+
+
+
+
+
+
+
+
+

师傅选择

+ + +
+
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+

搜索

+

清空

+
+ +
+
+
+ +
+
+
+
+
+ + + \ No newline at end of file diff --git a/application/admin/view/orders/dispatch2/edit.html b/application/admin/view/orders/dispatch2/edit.html new file mode 100644 index 0000000..4464e69 --- /dev/null +++ b/application/admin/view/orders/dispatch2/edit.html @@ -0,0 +1,55 @@ +
+ + + + + + + + +
+ +
+ +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ {foreach name="statusList" item="vo"} + + {/foreach} +
+ +
+
+ + + +
diff --git a/application/admin/view/orders/dispatch2/index.html b/application/admin/view/orders/dispatch2/index.html new file mode 100644 index 0000000..28d4130 --- /dev/null +++ b/application/admin/view/orders/dispatch2/index.html @@ -0,0 +1,51 @@ +
+ +
+ {:build_heading(null,FALSE)} + +
+ + +
+
+
+
+
+ + + + {:__('创建异常')} + + + + + + +
+ +
+
+
+ +
+
+
diff --git a/public/assets/js/backend/orders/dispatch2.js b/public/assets/js/backend/orders/dispatch2.js new file mode 100644 index 0000000..0d7afc9 --- /dev/null +++ b/public/assets/js/backend/orders/dispatch2.js @@ -0,0 +1,164 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form','layer'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'orders/dispatch2/index' + location.search, + //add_url: 'orders/dispatch/add', + edit_url: 'orders/dispatch2/edit', + del_url: 'orders/dispatc2h/del', + multi_url: 'orders/dispatch2/multi', + import_url: 'orders/dispatch2/import', + table: 'order_dispatch', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + fixedColumns: true, + fixedRightNumber: 1, + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + //{field: 'order_id', title: __('Order_id')}, + + {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'}, + + {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"10":__('Status 10'),"20":__('Status 20'),"25":__('Status 25'),"30":__('Status 30'),"60":__('Status 60'),"-10":__('Status -10'),"-20":__('Status -20'),"-30":__('Status -30')}, formatter: Table.api.formatter.status}, + + // {field: 'worker_id', title: __('Worker_id')}, + {field: 'worker_name', title: __('Worker_name'), operate: 'LIKE'}, + {field: 'worker_tel', title: __('Worker_tel'), operate: 'LIKE'}, + + {field: 'type', title: __('Type'), searchList: {"1":__('Type 1')}, formatter: Table.api.formatter.normal}, + + {field: 'plan_time', title: __('Plan_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + + + {field: 'order.source_shop', title: __('Order.source_shop'), operate: 'LIKE'}, + {field: 'order.source', title: __('Order.source')}, + {field: 'order.customer', title: __('Order.customer'), operate: 'LIKE'}, + {field: 'order.tel', title: __('Order.tel'), operate: 'LIKE'}, + {field: 'order.address', title: __('Order.address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + + {field: 'order.item_title', title: __('Order.item_title'), operate: 'LIKE'}, + {field: 'order.detail', title: __('Order.detail'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + + {field: 'order.images', title: __('Order.images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images}, + + {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + + // {field: 'is_notice', title: __('Is_notice'), searchList: {"0":__('Is_notice 0'),"1":__('Is_notice 1')}, formatter: Table.api.formatter.normal}, + {field: 'finish_time', title: __('Finish_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + // {field: 'admin_id', title: __('Admin_id')}, + {field: 'admin_user', title: __('Admin_user'), operate: 'LIKE'}, + {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, + + align:'left', + buttons: [ + { + name: 'edit', + text:"修改", + title:"", + icon: 'fa fa-pencil', + //title: __('Edit'), + extend: 'data-toggle="tooltip" data-container="body"', + classname: 'btn btn-xs btn-success btn-editone', + visible:function(row){ + if(row.btn_edit){ + return true; + } + 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, + } + ], + + } + ] + ] + }); + + // 为表格绑定事件 + Table.api.bindevent(table); + }, + add: function () { + Controller.api.bindevent(); + }, + edit: function () { + Controller.api.bindevent(); + }, + api: { + bindevent: function () { + Form.api.bindevent($("form[role=form]")); + } + } + }; + return Controller; +});