From 751ddafe73484f517d300ed8d8d9359ffd6631fb Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Mon, 24 Jun 2024 17:57:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(ConfigLogic):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=A1=A8=E3=80=81=E7=BC=96=E8=BE=91=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E8=A1=A8=E3=80=81=E5=88=A0=E9=99=A4=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E8=A1=A8=E3=80=81=E8=8E=B7=E5=8F=96=E9=85=8D=E7=BD=AE=E8=A1=A8?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/ConfigController.php | 1 + .../controller/config/ConfigController.php | 95 +++++++++++++++++++ app/admin/lists/config/ConfigLists.php | 64 +++++++++++++ app/admin/logic/ConfigLogic.php | 91 ++++++++++++++++-- app/admin/validate/config/ConfigValidate.php | 86 +++++++++++++++++ 5 files changed, 330 insertions(+), 7 deletions(-) create mode 100644 app/admin/controller/config/ConfigController.php create mode 100644 app/admin/lists/config/ConfigLists.php create mode 100644 app/admin/validate/config/ConfigValidate.php diff --git a/app/admin/controller/ConfigController.php b/app/admin/controller/ConfigController.php index 35d12c289..9ccb57337 100644 --- a/app/admin/controller/ConfigController.php +++ b/app/admin/controller/ConfigController.php @@ -14,6 +14,7 @@ namespace app\admin\controller; +use app\admin\lists\config\ConfigLists; use app\admin\logic\auth\AuthLogic; use app\admin\logic\ConfigLogic; use think\facade\Db; diff --git a/app/admin/controller/config/ConfigController.php b/app/admin/controller/config/ConfigController.php new file mode 100644 index 000000000..a6ef4550b --- /dev/null +++ b/app/admin/controller/config/ConfigController.php @@ -0,0 +1,95 @@ +dataLists(new ConfigLists()); + } + + + /** + * @notes 添加配置表 + * @return \think\response\Json + * @author admin + * @date 2024/06/24 17:52 + */ + public function add() + { + $params = (new ConfigValidate())->post()->goCheck('add'); + $result = ConfigLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ConfigLogic::getError()); + } + + + /** + * @notes 编辑配置表 + * @return \think\response\Json + * @author admin + * @date 2024/06/24 17:52 + */ + public function edit() + { + $params = (new ConfigValidate())->post()->goCheck('edit'); + $result = ConfigLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ConfigLogic::getError()); + } + + + /** + * @notes 删除配置表 + * @return \think\response\Json + * @author admin + * @date 2024/06/24 17:52 + */ + public function delete() + { + $params = (new ConfigValidate())->post()->goCheck('delete'); + ConfigLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取配置表详情 + * @return \think\response\Json + * @author admin + * @date 2024/06/24 17:52 + */ + public function detail() + { + $params = (new ConfigValidate())->goCheck('detail'); + $result = ConfigLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/config/ConfigLists.php b/app/admin/lists/config/ConfigLists.php new file mode 100644 index 000000000..c2cd2b901 --- /dev/null +++ b/app/admin/lists/config/ConfigLists.php @@ -0,0 +1,64 @@ + ['name', 'type'], + ]; + } + + + /** + * @notes 获取配置列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/05/30 10:25 + */ + public function lists(): array + { + return Config::where($this->searchWhere) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取配置数量 + * @return int + * @author likeadmin + * @date 2024/05/30 10:25 + */ + public function count(): int + { + return AppUpdate::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/ConfigLogic.php b/app/admin/logic/ConfigLogic.php index d9ef9f806..a2b705d0c 100644 --- a/app/admin/logic/ConfigLogic.php +++ b/app/admin/logic/ConfigLogic.php @@ -14,17 +14,97 @@ namespace app\admin\logic; - +use app\common\logic\BaseLogic; +use app\common\model\Config; use app\common\model\dict\DictData; use app\common\service\{FileService, ConfigService}; +use think\facade\Db; /** * 配置类逻辑层 * Class ConfigLogic * @package app\admin\logic */ -class ConfigLogic +class ConfigLogic extends BaseLogic { + /** + * @notes 添加配置表 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/24 17:52 + */ + public static function add(array $params): bool + { + Db::startTrans(); + try { + Config::create([ + 'type' => $params['type'], + 'name' => $params['name'], + 'value' => $params['value'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑配置表 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/24 17:52 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Config::where('id', $params['id'])->update([ + 'type' => $params['type'], + 'name' => $params['name'], + 'value' => $params['value'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除配置表 + * @param array $params + * @return bool + * @author admin + * @date 2024/06/24 17:52 + */ + public static function delete(array $params): bool + { + return Config::destroy($params['id']); + } + + + /** + * @notes 获取配置表详情 + * @param $params + * @return array + * @author admin + * @date 2024/06/24 17:52 + */ + public static function detail($params): array + { + return Config::findOrEmpty($params['id'])->toArray(); + } /** * @notes 获取配置 * @return array @@ -68,7 +148,7 @@ class ConfigLogic if (!is_string($type)) { return []; } - + $type = explode(',', $type); $lists = DictData::whereIn('type_value', $type)->select()->toArray(); @@ -86,7 +166,4 @@ class ConfigLogic } return $result; } - - - -} \ No newline at end of file +} diff --git a/app/admin/validate/config/ConfigValidate.php b/app/admin/validate/config/ConfigValidate.php new file mode 100644 index 000000000..1a42ab197 --- /dev/null +++ b/app/admin/validate/config/ConfigValidate.php @@ -0,0 +1,86 @@ + 'require', + 'name' => 'require', + 'value' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '名称', + 'value' => '值', + ]; + + + /** + * @notes 添加场景 + * @return ConfigValidate + * @author admin + * @date 2024/06/24 17:52 + */ + public function sceneAdd() + { + return $this->only(['name','value']); + } + + + /** + * @notes 编辑场景 + * @return ConfigValidate + * @author admin + * @date 2024/06/24 17:52 + */ + public function sceneEdit() + { + return $this->only(['id','name','value']); + } + + + /** + * @notes 删除场景 + * @return ConfigValidate + * @author admin + * @date 2024/06/24 17:52 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ConfigValidate + * @author admin + * @date 2024/06/24 17:52 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file