From 7690b1e40f09de30fb42d6bb34541fdcadce8808 Mon Sep 17 00:00:00 2001 From: hant Date: Sat, 8 Mar 2025 15:39:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BC=98=E6=83=A0=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=B7=A5=E4=BD=9C=E6=9C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Coupons.php | 38 +++++ application/admin/controller/Order.php | 48 ++++++- application/admin/controller/Phones.php | 160 ++++++++++++++++++++++ application/admin/lang/zh-cn/coupons.php | 20 +++ application/admin/lang/zh-cn/order.php | 3 +- application/admin/lang/zh-cn/phones.php | 10 ++ application/admin/model/Coupons.php | 63 +++++++++ application/admin/model/Order.php | 8 +- application/admin/model/Phones.php | 47 +++++++ application/admin/validate/Coupons.php | 27 ++++ application/admin/validate/Phones.php | 27 ++++ application/admin/view/coupons/add.html | 81 +++++++++++ application/admin/view/coupons/edit.html | 81 +++++++++++ application/admin/view/coupons/index.html | 46 +++++++ application/admin/view/order/add.html | 36 ++++- application/admin/view/order/edit.html | 2 +- application/admin/view/phones/add.html | 32 +++++ application/admin/view/phones/edit.html | 32 +++++ application/admin/view/phones/index.html | 46 +++++++ public/assets/js/backend/coupons.js | 62 +++++++++ public/assets/js/backend/order.js | 3 +- public/assets/js/backend/phones.js | 55 ++++++++ 22 files changed, 914 insertions(+), 13 deletions(-) create mode 100644 application/admin/controller/Coupons.php create mode 100644 application/admin/controller/Phones.php create mode 100644 application/admin/lang/zh-cn/coupons.php create mode 100644 application/admin/lang/zh-cn/phones.php create mode 100644 application/admin/model/Coupons.php create mode 100644 application/admin/model/Phones.php create mode 100644 application/admin/validate/Coupons.php create mode 100644 application/admin/validate/Phones.php create mode 100644 application/admin/view/coupons/add.html create mode 100644 application/admin/view/coupons/edit.html create mode 100644 application/admin/view/coupons/index.html create mode 100644 application/admin/view/phones/add.html create mode 100644 application/admin/view/phones/edit.html create mode 100644 application/admin/view/phones/index.html create mode 100644 public/assets/js/backend/coupons.js create mode 100644 public/assets/js/backend/phones.js diff --git a/application/admin/controller/Coupons.php b/application/admin/controller/Coupons.php new file mode 100644 index 0000000..98120a7 --- /dev/null +++ b/application/admin/controller/Coupons.php @@ -0,0 +1,38 @@ +model = new \app\admin\model\Coupons; + $this->view->assign("discountTypeList", $this->model->getDiscountTypeList()); + $this->view->assign("statusList", $this->model->getStatusList()); + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + +} diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 97d53be..68ceda9 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -22,6 +22,7 @@ class Order extends Backend */ protected $model = null; protected $sources = null; + protected $items = null; public function _initialize() { parent::_initialize(); @@ -53,8 +54,44 @@ class Order extends Backend // Tree::instance()->init($sources); // $data = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); // dd($data); + + $items = Db::name('item') + ->where('status',1) + ->field(['id','title','key_word','pid']) + ->order('pid','asc') + ->order('sort','desc') + ->select(); + + $phones = Db::name('phones') + ->where('assigned_user',$this->auth->id) + ->field(['id','model','phone_number']) + ->select(); + + $this->items = $items; + $filtered = array_filter($items, function($item) { + return $item['pid'] == 0; + }); + + $pid_map = array_column($filtered,null,'id'); + $res_items = []; + foreach ($items as $item){ + if ($item['pid'] != 0 && isset($pid_map[$item['pid']])){ + $res_items [] = [ + ...$item,'ptitle' => $pid_map[$item['pid']]['title'] + ]; + } + } + + $coupons = Db::name('coupons') + ->where('status','active') + ->field(['id','code','description']) + ->select(); + $this->view->assign("statusList", $this->model->getStatusList()); $this->view->assign("sources", $res); + $this->view->assign("coupons", $coupons); + $this->view->assign("items", $res_items); + $this->view->assign("phones", $phones); //$this->view->assign("collectList", $this->model->getCollectList()); //$this->view->assign("dispatchTypeList", $this->model->getDispatchTypeList()); } @@ -81,10 +118,15 @@ class Order extends Backend } [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model - ->field(['id','order_no','customer','tel','status','area_id','address', + ->field(['id','order_no','user_id','customer','tel','status','area_id','address', 'source','source_shop','source_uid','source','item_title','item_id', 'detail','remark','images','create_time','update_time']) ->where($where) + ->with(['user' => function($q){ + $q->field('id,nickname'); + },'area' => function($q){ + $q->field('id,area_code,merge_name'); + }]) ->order($sort, $order) ->paginate($limit); $result = ['total' => $list->total(), 'rows' => $list->items()]; @@ -116,8 +158,11 @@ class Order extends Backend } $sources = $this->sources; + $items = $this->items; $sources = array_column($sources,'title','id'); + $items = array_column($items,'title','id'); $params['source_shop'] = $sources[$params['source']] ?? null; + $params['item_title'] = $items[$params['item_id']] ?? null; $params['user_id'] = $this->auth->id; $params['status'] = 10; $params['order_no'] = $this->generateOrderNumber(); @@ -163,6 +208,7 @@ class Order extends Backend $data['update_time'] = date('Y-m-d H:i:s'); $sources = $this->sources; $sources = array_column($sources,'title','id'); +// $data['user_id'] = $this->auth->id; $data['source_shop'] = $sources[$data['source']] ?? null; // 更新订单信息 $order->save($data); diff --git a/application/admin/controller/Phones.php b/application/admin/controller/Phones.php new file mode 100644 index 0000000..c5c7f44 --- /dev/null +++ b/application/admin/controller/Phones.php @@ -0,0 +1,160 @@ +model = new \app\admin\model\Phones; + + $users = Db::name('admin') +// ->where('status',1) + ->field(['id','nickname']) + ->select(); + $this->view->assign("statusList", $this->model->getStatusList()); + $this->view->assign("users", $users); + + + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + + + public function index() + { + //设置过滤方法 + $this->request->filter(['strip_tags', 'trim']); + if (false === $this->request->isAjax()) { + return $this->view->fetch(); + } + //如果发送的来源是 Selectpage,则转发到 Selectpage + if ($this->request->request('keyField')) { + return $this->selectpage(); + } + [$where, $sort, $order, $offset, $limit] = $this->buildparams(); + $list = $this->model + ->where($where) + ->with(['user' => function($q){ + $q->field('id,nickname'); + }]) + ->order($sort, $order) + ->paginate($limit); + $result = ['total' => $list->total(), 'rows' => $list->items()]; + return json($result); + } + + public function add() + { + if (false === $this->request->isPost()) { + 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); + } + if ($params['assigned_user'] != 0){ + $params['status'] = 'assigned'; + $params['assigned_date'] = date('Y-m-d H:i:s'); + }else{ + $params['status'] = 'available'; + $params['assigned_date'] = null; + } + + + $result = $this->model->allowField(true)->save($params); + Db::commit(); + } catch (ValidateException|PDOException|Exception $e) { + Db::rollback(); + $this->error($e->getMessage()); + } + if ($result === false) { + $this->error(__('No rows were inserted')); + } + $this->success(); + } + + public function edit($ids = null) + { + if (!$ids) { + if (request()->isPost()){ + $ids = input('id'); + if (!$ids){ + $this->error('缺少订单ID'); + } + }else{ + $this->error('缺少订单ID'); + } + } + + // 获取当前ID对应的订单信息 + $order = $this->model->get($ids); + if (!$order) { + $this->error('订单不存在'); + } + + // 判断是否为POST请求,进行更新操作 + if (request()->isPost()) { + // 获取表单提交的数据 + $data = input('post.row/a'); + + if ($data['assigned_user'] != 0){ + $data['status'] = 'assigned'; + $data['assigned_date'] = date('Y-m-d H:i:s'); + }else{ + $data['status'] = 'available'; + $data['assigned_date'] = null; + } + // 更新订单信息 + $order->save($data); + + // 返回成功信息 + $this->success('更新成功', 'index'); + } + // 将订单数据传递到视图 + $this->assign('row', $order); + + // 渲染编辑页面 + return $this->fetch(); + } + +} diff --git a/application/admin/lang/zh-cn/coupons.php b/application/admin/lang/zh-cn/coupons.php new file mode 100644 index 0000000..de9a13b --- /dev/null +++ b/application/admin/lang/zh-cn/coupons.php @@ -0,0 +1,20 @@ + '优惠码唯一标识', + 'Code' => '优惠码名称', + 'Description' => '优惠码描述', + 'Discount_type' => '折扣类型', + 'Min_order' => '最低消费金额', + 'Max_discount' => '最大优惠金额', + 'Status' => '状态', + 'Threshold' => '优惠门槛', + 'Discount_value' => '优惠金额', + 'Created_at' => '创建时间', + 'Updated_at' => '更新时间', + 'Percentage' => '百分比优惠', + + 'Fixed' => '固定优惠', + 'Active' => '可用', + 'Inactive' => '禁用', +]; diff --git a/application/admin/lang/zh-cn/order.php b/application/admin/lang/zh-cn/order.php index 23ce16d..2fc90ac 100644 --- a/application/admin/lang/zh-cn/order.php +++ b/application/admin/lang/zh-cn/order.php @@ -57,5 +57,6 @@ return [ 'Payment_time' => '付款时间', 'Finishe_time' => '完成时间', 'Dispatch_time' => '派单时间', - 'Delete_time' => '删除时间' + 'Delete_time' => '删除时间', + 'Coupons' => '优惠', ]; diff --git a/application/admin/lang/zh-cn/phones.php b/application/admin/lang/zh-cn/phones.php new file mode 100644 index 0000000..59af4f3 --- /dev/null +++ b/application/admin/lang/zh-cn/phones.php @@ -0,0 +1,10 @@ + '手机号码', + 'Model' => '型号', + 'Assigned_user' => '使用者', + 'Assigned_date' => '使用时期', + 'Available' => '空闲', + 'Assigned' => '已分配', +]; diff --git a/application/admin/model/Coupons.php b/application/admin/model/Coupons.php new file mode 100644 index 0000000..f3996dc --- /dev/null +++ b/application/admin/model/Coupons.php @@ -0,0 +1,63 @@ + __('Fixed'), 'percentage' => __('Percentage')]; + } + + public function getStatusList() + { + return ['active' => __('Active'), 'inactive' => __('Inactive')]; + } + + + public function getDiscountTypeTextAttr($value, $data) + { + $value = $value ?: ($data['discount_type'] ?? ''); + $list = $this->getDiscountTypeList(); + return $list[$value] ?? ''; + } + + + public function getStatusTextAttr($value, $data) + { + $value = $value ?: ($data['status'] ?? ''); + $list = $this->getStatusList(); + return $list[$value] ?? ''; + } + + + + +} diff --git a/application/admin/model/Order.php b/application/admin/model/Order.php index e626744..8c8e58c 100644 --- a/application/admin/model/Order.php +++ b/application/admin/model/Order.php @@ -99,7 +99,11 @@ class Order extends Model } - public function admin(){ - return $this->belongsTo(Admin::class,'audit_admin_id',); + public function user(){ + return $this->belongsTo(Admin::class,'user_id',); + } + + public function area(){ + return $this->belongsTo(Area::class,'area_id','area_code'); } } diff --git a/application/admin/model/Phones.php b/application/admin/model/Phones.php new file mode 100644 index 0000000..6cbc532 --- /dev/null +++ b/application/admin/model/Phones.php @@ -0,0 +1,47 @@ + __('Available'), 'assigned' => __('Assigned')]; + } + + + public function getStatusTextAttr($value, $data) + { + $value = $value ?: ($data['status'] ?? ''); + $list = $this->getStatusList(); + return $list[$value] ?? ''; + } + + + + public function user(){ + return $this->belongsTo(Admin::class,'assigned_user'); + } +} diff --git a/application/admin/validate/Coupons.php b/application/admin/validate/Coupons.php new file mode 100644 index 0000000..2a1b72b --- /dev/null +++ b/application/admin/validate/Coupons.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/validate/Phones.php b/application/admin/validate/Phones.php new file mode 100644 index 0000000..61a94e5 --- /dev/null +++ b/application/admin/validate/Phones.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/coupons/add.html b/application/admin/view/coupons/add.html new file mode 100644 index 0000000..cc2ac12 --- /dev/null +++ b/application/admin/view/coupons/add.html @@ -0,0 +1,81 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ {foreach name="statusList" item="vo"} + + {/foreach} +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/coupons/edit.html b/application/admin/view/coupons/edit.html new file mode 100644 index 0000000..f500d2f --- /dev/null +++ b/application/admin/view/coupons/edit.html @@ -0,0 +1,81 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + + +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+ {foreach name="statusList" item="vo"} + + {/foreach} +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/coupons/index.html b/application/admin/view/coupons/index.html new file mode 100644 index 0000000..8e5b965 --- /dev/null +++ b/application/admin/view/coupons/index.html @@ -0,0 +1,46 @@ +
+ +
+ {:build_heading(null,FALSE)} + +
+ + +
+
+
+
+
+ + {:__('Add')} + {:__('Edit')} + {:__('Delete')} + + + + + +
+ +
+
+
+ +
+
+
diff --git a/application/admin/view/order/add.html b/application/admin/view/order/add.html index f6de8fc..71a0f33 100644 --- a/application/admin/view/order/add.html +++ b/application/admin/view/order/add.html @@ -51,19 +51,41 @@ +
+ +
+ +
+
- - - - - - - +
+ +
+ +
+ +
+
+ +
diff --git a/application/admin/view/order/edit.html b/application/admin/view/order/edit.html index 8d99a5b..bc428c0 100644 --- a/application/admin/view/order/edit.html +++ b/application/admin/view/order/edit.html @@ -43,7 +43,7 @@
diff --git a/application/admin/view/phones/add.html b/application/admin/view/phones/add.html new file mode 100644 index 0000000..de4bb8d --- /dev/null +++ b/application/admin/view/phones/add.html @@ -0,0 +1,32 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/phones/edit.html b/application/admin/view/phones/edit.html new file mode 100644 index 0000000..398c943 --- /dev/null +++ b/application/admin/view/phones/edit.html @@ -0,0 +1,32 @@ +
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
diff --git a/application/admin/view/phones/index.html b/application/admin/view/phones/index.html new file mode 100644 index 0000000..370d910 --- /dev/null +++ b/application/admin/view/phones/index.html @@ -0,0 +1,46 @@ +
+ +
+ {:build_heading(null,FALSE)} + +
+ + +
+
+
+
+
+ + {:__('Add')} + {:__('Edit')} + {:__('Delete')} + + + + + +
+ +
+
+
+ +
+
+
diff --git a/public/assets/js/backend/coupons.js b/public/assets/js/backend/coupons.js new file mode 100644 index 0000000..608d10e --- /dev/null +++ b/public/assets/js/backend/coupons.js @@ -0,0 +1,62 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'coupons/index' + location.search, + add_url: 'coupons/add', + edit_url: 'coupons/edit', + del_url: 'coupons/del', + multi_url: 'coupons/multi', + import_url: 'coupons/import', + table: 'coupons', + } + }); + + 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: 'code', title: __('Code'), operate: 'LIKE'}, + {field: 'description', title: __('Description'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'discount_type', title: __('Discount_type'), searchList: {"fixed":__('Fixed'),"percentage":__('Percentage')}, formatter: Table.api.formatter.normal}, + {field: 'min_order', title: __('Min_order'), operate:'BETWEEN'}, + {field: 'max_discount', title: __('Max_discount'), operate:'BETWEEN'}, + {field: 'status', title: __('Status'), searchList: {"active":__('Active'),"inactive":__('Inactive')}, formatter: Table.api.formatter.status}, + {field: 'threshold', title: __('Threshold'), operate:'BETWEEN'}, + {field: 'discount_value', title: __('Discount_value'), operate:'BETWEEN'}, + {field: 'created_at', title: __('Created_at')}, + {field: 'updated_at', title: __('Updated_at')}, + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ] + }); + + // 为表格绑定事件 + 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; +}); diff --git a/public/assets/js/backend/order.js b/public/assets/js/backend/order.js index 567c7c6..046efcb 100644 --- a/public/assets/js/backend/order.js +++ b/public/assets/js/backend/order.js @@ -28,6 +28,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin [ {checkbox: true}, {field: 'id', title: __('Id')}, + {field: 'user.nickname', title: '录单员'}, {field: 'order_no', title: __('Order_no'), operate: 'LIKE'}, {field: 'customer', title: __('Customer'), operate: 'LIKE'}, {field: 'tel', title: __('Tel'), operate: 'LIKE'}, @@ -46,7 +47,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin }, formatter: Table.api.formatter.status }, - {field: 'area_id', title: __('Area_id')}, + {field: 'area.merge_name', title: __('Area_id')}, { field: 'address', title: __('Address'), diff --git a/public/assets/js/backend/phones.js b/public/assets/js/backend/phones.js new file mode 100644 index 0000000..099c90a --- /dev/null +++ b/public/assets/js/backend/phones.js @@ -0,0 +1,55 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'phones/index' + location.search, + add_url: 'phones/add', + edit_url: 'phones/edit', + del_url: 'phones/del', + multi_url: 'phones/multi', + import_url: 'phones/import', + table: 'phones', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'phone_number', title: __('Phone_number'), operate: 'LIKE'}, + {field: 'model', title: __('Model'), operate: 'LIKE'}, + {field: 'user.nickname', title: __('Assigned_user')}, + {field: 'assigned_date', title: __('Assigned_date'), operate:'RANGE', addclass:'datetimerange', autocomplete:false}, + {field: 'status', title: __('Status'), searchList: {"available":__('Available'),"assigned":__('Assigned')}, formatter: Table.api.formatter.status}, + {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate} + ] + ] + }); + + // 为表格绑定事件 + 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; +});