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}
+ + +