diff --git a/application/admin/command/AreaPinyinCommand.php b/application/admin/command/AreaPinyinCommand.php new file mode 100644 index 0000000..2feeb71 --- /dev/null +++ b/application/admin/command/AreaPinyinCommand.php @@ -0,0 +1,40 @@ +setName('area:pinyin') + ->setDescription('批量生成区域名称的拼音'); + } + + protected function execute(Input $input, Output $output) + { + $pinyin = new Pinyin(); + + // 读取 `area` 表所有数据 + $areas = Db::name('areas')->where('id','>',0)->select(); + + foreach ($areas as $area) { + $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']) + ->update(['pinyin' => $fullPinyin, 'abbr' => $abbrPinyin]); + + $output->writeln("更新: {$area['merge_name']} -> {$fullPinyin} ({$abbrPinyin})"); + } + + $output->writeln("拼音转换完成!"); + } +} diff --git a/application/admin/controller/Area.php b/application/admin/controller/Area.php index 89edbe1..be5df7e 100644 --- a/application/admin/controller/Area.php +++ b/application/admin/controller/Area.php @@ -19,9 +19,22 @@ class Area extends Backend $this->success(data:[]); }else{ $data = model('area') - ->where('merge_name','like','%'.$keyword.'%') ->where('level','=',3) + ->where(function ($query)use ($keyword){ + $query->where('merge_name','like','%'.$keyword.'%') + ->whereOr('pinyin', 'like', "%{$keyword}%") + ->whereOr('abbr', 'like', "%{$keyword}%"); + }) + ->field('area_code, merge_name') + ->orderRaw( + "CASE + WHEN name LIKE '{$keyword}%' THEN 1 + WHEN pinyin LIKE '{$keyword}%' THEN 2 + WHEN abbr LIKE '{$keyword}%' THEN 3 + ELSE 4 + END" + ) ->limit(0,10) ->select(); $this->success(data:$data); 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 36cdcdb..d25305d 100644 --- a/application/admin/controller/Order.php +++ b/application/admin/controller/Order.php @@ -52,6 +52,9 @@ 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_title', + 'detail','remark','images','create_time','update_time']) ->where($where) ->order($sort, $order) ->paginate($limit); @@ -86,7 +89,8 @@ class Order extends Backend $params['enter_admin_id'] = $this->auth->id; $params['status'] = 10; $params['order_no'] = $this->generateOrderNumber(); - + $params['create_time'] = date('Y-m-d H:i:s'); + $params['update_time'] = date('Y-m-d H:i:s'); $result = $this->model->allowField(true)->save($params); Db::commit(); @@ -100,6 +104,73 @@ class Order extends Backend $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'); + $data['update_time'] = date('Y-m-d H:i:s'); + // 更新订单信息 + $order->save($data); + + // 返回成功信息 + $this->success('更新成功', 'index'); + } + $area = new \app\admin\model\Area(); + $area_name = $area->getNameByCode($order->area_id); + $order->area_name = $area_name; + + // 将订单数据传递到视图 + $this->assign('row', $order); + + // 渲染编辑页面 + return $this->fetch(); + } + + + public function copy($ids = null) + { + if (!$ids) { + $this->error('缺少订单ID'); + } + + // 获取当前ID对应的订单信息 + $order = $this->model->get($ids); + if (!$order) { + $this->error('订单不存在'); + } + + + $area = new \app\admin\model\Area(); + $area_name = $area->getNameByCode($order->area_id); + $order->area_name = $area_name; + + // 将订单数据传递到视图 + $this->assign('row', $order); + + // 渲染编辑页面 + return $this->fetch(); + } + function generateOrderNumber($prefix = 'ORD') { // 获取当前时间戳(精确到毫秒) $timestamp = microtime(true); 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/Area.php b/application/admin/model/Area.php index 68bc67c..94919f6 100644 --- a/application/admin/model/Area.php +++ b/application/admin/model/Area.php @@ -10,6 +10,11 @@ class Area extends Model // 表名 protected $name = 'areas'; + + + public function getNameByCode($code){ + return $this->where('area_code',$code)->find()->value('merge_name'); + } } 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 @@ +
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 @@ + 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 @@ +