diff --git a/application/admin/command/AreaPinyinCommand.php b/application/admin/command/AreaPinyinCommand.php index d49b6ee..2feeb71 100644 --- a/application/admin/command/AreaPinyinCommand.php +++ b/application/admin/command/AreaPinyinCommand.php @@ -22,11 +22,11 @@ class AreaPinyinCommand extends Command $pinyin = new Pinyin(); // 读取 `area` 表所有数据 - $areas = Db::name('areas')->where('id','>',1738)->select(); + $areas = Db::name('areas')->where('id','>',0)->select(); foreach ($areas as $area) { - $fullPinyin = strtolower(str_replace(' ','',$pinyin->name($area['short_name'],Converter::TONE_STYLE_NONE))); // 全拼 - $abbrPinyin = strtolower(str_replace(' ','',$pinyin->abbr($area['short_name']))); // 首字母 + $fullPinyin = strtolower(str_replace(' ','',$pinyin->name($area['merge_name'],Converter::TONE_STYLE_NONE))); // 全拼 + $abbrPinyin = strtolower(str_replace(' ','',$pinyin->abbr($area['merge_name']))); // 首字母 // 更新数据库 Db::name('areas') ->where('id', $area['id']) diff --git a/application/admin/controller/Item.php b/application/admin/controller/Item.php new file mode 100644 index 0000000..2f33226 --- /dev/null +++ b/application/admin/controller/Item.php @@ -0,0 +1,123 @@ +model = new \app\admin\model\Item; + + + // 必须将结果集转换为数组 + $ruleList = \think\Db::name("item")->field('id,pid,level,title')->order('sort DESC,id ASC')->select(); + + Tree::instance()->init($ruleList)->icon = ['    ', '    ', '    ']; +// dd($ruleList); + $this->rulelist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'title'); + $itemdata = [0 => __('None')]; + foreach ($this->rulelist as $k => $v) { + $itemdata[$v['id']] = $v['title']; + } + unset($v); + + $this->view->assign('itemdata', $itemdata); + + $this->view->assign("statusList", $this->model->getStatusList()); + } + + + + /** + * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 + * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 + * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 + */ + + 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); + } + + $pid = $params['pid']; + if ($pid > 0){ + $parent = $this->model->where('id',$pid)->find(); + if ($parent){ + $params['level'] = $parent->value('level') + 1; + } + }else{ + $params['level'] = 0; + } + + + $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 search(){ + + $keyword = request()->get('keyword'); + if (!$keyword){ + $this->success(data:[]); + }else{ + $data = model('item') +// ->where('level','=',3) + ->where(function ($query)use ($keyword){ + $query->where('title','like','%'.$keyword.'%') + ->whereOr('key_word', 'like', "%{$keyword}%"); + }) + ->order('level','desc') + ->field('title,id') + ->limit(0,10) + ->select(); + $this->success(data:$data); + } + + } +} diff --git a/application/admin/controller/Order.php b/application/admin/controller/Order.php index 3828f91..d25305d 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -53,7 +53,7 @@ class Order extends Backend [$where, $sort, $order, $offset, $limit] = $this->buildparams(); $list = $this->model ->field(['id','order_no','customer','tel','status','area_id','address', - 'work_tel_id','worker_id','source','source_uid','service_id','service_title', + 'work_tel_id','worker_id','source','source_uid','service_title', 'detail','remark','images','create_time','update_time']) ->where($where) ->order($sort, $order) diff --git a/application/admin/lang/zh-cn/item.php b/application/admin/lang/zh-cn/item.php new file mode 100644 index 0000000..fd5908f --- /dev/null +++ b/application/admin/lang/zh-cn/item.php @@ -0,0 +1,16 @@ + 'ID', + 'Pid' => 'PID', + 'Level' => '层级', + 'Title' => '服务名称', + 'Key_word' => '关键字', + 'Image' => '图标', + 'Sort' => '排序', + 'Status' => '状态', + 'Status 1' => '启用', + 'Set status to 1'=> '设为启用', + 'Status 0' => '关闭', + 'Set status to 0'=> '设为关闭' +]; diff --git a/application/admin/model/Item.php b/application/admin/model/Item.php new file mode 100644 index 0000000..4314b80 --- /dev/null +++ b/application/admin/model/Item.php @@ -0,0 +1,49 @@ + __('Status 1'), '0' => __('Status 0')]; + } + + + public function getStatusTextAttr($value, $data) + { + $value = $value ?: ($data['status'] ?? ''); + $list = $this->getStatusList(); + return $list[$value] ?? ''; + } + + + + +} diff --git a/application/admin/validate/Item.php b/application/admin/validate/Item.php new file mode 100644 index 0000000..4bdb62f --- /dev/null +++ b/application/admin/validate/Item.php @@ -0,0 +1,27 @@ + [], + 'edit' => [], + ]; + +} diff --git a/application/admin/view/item/add.html b/application/admin/view/item/add.html new file mode 100644 index 0000000..c7067f5 --- /dev/null +++ b/application/admin/view/item/add.html @@ -0,0 +1,60 @@ +
+ +
+ +
+ {:build_select('row[pid]', $itemdata, null, ['class'=>'form-control', 'required'=>''])} +
+
+ +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+
+ +
+ + +
+ +
+
    +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    + {foreach name="statusList" item="vo"} + + {/foreach} +
    + +
    +
    + +
    diff --git a/application/admin/view/item/edit.html b/application/admin/view/item/edit.html new file mode 100644 index 0000000..ad4c48d --- /dev/null +++ b/application/admin/view/item/edit.html @@ -0,0 +1,65 @@ +
    + +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    + +
    +
    +
    + +
    +
    + +
    + + +
    + +
    +
      +
      +
      +
      + +
      + +
      +
      +
      + +
      + +
      + {foreach name="statusList" item="vo"} + + {/foreach} +
      + +
      +
      + +
      diff --git a/application/admin/view/item/index.html b/application/admin/view/item/index.html new file mode 100644 index 0000000..a597675 --- /dev/null +++ b/application/admin/view/item/index.html @@ -0,0 +1,46 @@ +
      + +
      + {:build_heading(null,FALSE)} + +
      + + +
      +
      +
      +
      +
      + + {:__('Add')} + {:__('Edit')} + {:__('Delete')} + + + + + +
      + +
      +
      +
      + +
      +
      +
      diff --git a/public/assets/js/backend/item.js b/public/assets/js/backend/item.js new file mode 100644 index 0000000..9e93c48 --- /dev/null +++ b/public/assets/js/backend/item.js @@ -0,0 +1,57 @@ +define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) { + + var Controller = { + index: function () { + // 初始化表格参数配置 + Table.api.init({ + extend: { + index_url: 'item/index' + location.search, + add_url: 'item/add', + edit_url: 'item/edit', + del_url: 'item/del', + multi_url: 'item/multi', + import_url: 'item/import', + table: 'item', + } + }); + + var table = $("#table"); + + // 初始化表格 + table.bootstrapTable({ + url: $.fn.bootstrapTable.defaults.extend.index_url, + pk: 'id', + sortName: 'id', + columns: [ + [ + {checkbox: true}, + {field: 'id', title: __('Id')}, + {field: 'pid', title: __('Pid')}, + {field: 'level', title: __('Level')}, + {field: 'title', title: __('Title'), operate: 'LIKE'}, + {field: 'key_word', title: __('Key_word'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content}, + {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image}, + {field: 'sort', title: __('Sort')}, + {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"0":__('Status 0')}, 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; +}); diff --git a/public/assets/js/backend/order.js b/public/assets/js/backend/order.js index b662eed..b608824 100644 --- a/public/assets/js/backend/order.js +++ b/public/assets/js/backend/order.js @@ -59,7 +59,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin {field: 'worker_id', title: __('Worker_id')}, {field: 'source', title: __('Source')}, {field: 'source_uid', title: __('Source_uid'), operate: 'LIKE'}, - {field: 'service_id', title: __('Service_id')}, {field: 'service_title', title: __('Service_title'), operate: 'LIKE'}, { field: 'detail', @@ -235,7 +234,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin // 延迟 500 毫秒后执行 AJAX 查询(防止过快触发) timerService = setTimeout(() => { $.ajax({ - url: "/admin/area/search", // 你的 API 地址 + url: "/admin/item/search", // 你的 API 地址 type: "GET", data: {keyword: keyword}, dataType: "json", @@ -260,10 +259,10 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin } else { data.forEach(item => { let $option = $("") - .text(item.merge_name) - .attr("data-value", item.area_code) // 绑定 area_code + .text(item.title) + .attr("data-value", item.id) // 绑定 area_code .on("click", function () { - $inputService.val(item.merge_name); // 选中后填充输入框 + $inputService.val(item.title); // 选中后填充输入框 $hiddenFieldService.val($(this).attr("data-value")); // 存储 area_code $dropdownService.hide(); });