From 3b25807f24c116ba62a9d45ce072f7d0e0a34a0e Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 17 Feb 2024 18:01:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../article/ArticleLabelController.php | 95 ++++++++++++++++++ .../controller/setting/LabelController.php | 95 ++++++++++++++++++ app/admin/lists/article/ArticleLabelLists.php | 65 +++++++++++++ app/admin/lists/setting/LabelLists.php | 65 +++++++++++++ app/admin/logic/article/ArticleLabelLogic.php | 94 ++++++++++++++++++ app/admin/logic/setting/LabelLogic.php | 96 +++++++++++++++++++ .../validate/article/ArticleLabelValidate.php | 82 ++++++++++++++++ app/admin/validate/setting/LabelValidate.php | 82 ++++++++++++++++ app/common/model/article/ArticleLabel.php | 22 +++++ app/common/model/setting/Label.php | 22 +++++ .../generator/core/VueApiGenerator.php | 4 +- 11 files changed, 720 insertions(+), 2 deletions(-) create mode 100644 app/admin/controller/article/ArticleLabelController.php create mode 100644 app/admin/controller/setting/LabelController.php create mode 100644 app/admin/lists/article/ArticleLabelLists.php create mode 100644 app/admin/lists/setting/LabelLists.php create mode 100644 app/admin/logic/article/ArticleLabelLogic.php create mode 100644 app/admin/logic/setting/LabelLogic.php create mode 100644 app/admin/validate/article/ArticleLabelValidate.php create mode 100644 app/admin/validate/setting/LabelValidate.php create mode 100644 app/common/model/article/ArticleLabel.php create mode 100644 app/common/model/setting/Label.php diff --git a/app/admin/controller/article/ArticleLabelController.php b/app/admin/controller/article/ArticleLabelController.php new file mode 100644 index 0000000..83a85a1 --- /dev/null +++ b/app/admin/controller/article/ArticleLabelController.php @@ -0,0 +1,95 @@ +dataLists(new ArticleLabelLists()); + } + + + /** + * @notes 添加文章标签 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function add() + { + $params = (new ArticleLabelValidate())->post()->goCheck('add'); + $result = ArticleLabelLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ArticleLabelLogic::getError()); + } + + + /** + * @notes 编辑文章标签 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function edit() + { + $params = (new ArticleLabelValidate())->post()->goCheck('edit'); + $result = ArticleLabelLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ArticleLabelLogic::getError()); + } + + + /** + * @notes 删除文章标签 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function delete() + { + $params = (new ArticleLabelValidate())->post()->goCheck('delete'); + ArticleLabelLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取文章标签详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function detail() + { + $params = (new ArticleLabelValidate())->goCheck('detail'); + $result = ArticleLabelLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/setting/LabelController.php b/app/admin/controller/setting/LabelController.php new file mode 100644 index 0000000..91cc523 --- /dev/null +++ b/app/admin/controller/setting/LabelController.php @@ -0,0 +1,95 @@ +dataLists(new LabelLists()); + } + + + /** + * @notes 添加标签 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function add() + { + $params = (new LabelValidate())->post()->goCheck('add'); + $result = LabelLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(LabelLogic::getError()); + } + + + /** + * @notes 编辑标签 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function edit() + { + $params = (new LabelValidate())->post()->goCheck('edit'); + $result = LabelLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(LabelLogic::getError()); + } + + + /** + * @notes 删除标签 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function delete() + { + $params = (new LabelValidate())->post()->goCheck('delete'); + LabelLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取标签详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function detail() + { + $params = (new LabelValidate())->goCheck('detail'); + $result = LabelLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/article/ArticleLabelLists.php b/app/admin/lists/article/ArticleLabelLists.php new file mode 100644 index 0000000..989cc7b --- /dev/null +++ b/app/admin/lists/article/ArticleLabelLists.php @@ -0,0 +1,65 @@ + ['article_id', 'label_id'], + ]; + } + + + /** + * @notes 获取文章标签列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function lists(): array + { + return ArticleLabel::where($this->searchWhere) + ->field(['id', 'article_id', 'label_id']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取文章标签数量 + * @return int + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function count(): int + { + return ArticleLabel::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/setting/LabelLists.php b/app/admin/lists/setting/LabelLists.php new file mode 100644 index 0000000..33b9869 --- /dev/null +++ b/app/admin/lists/setting/LabelLists.php @@ -0,0 +1,65 @@ + ['label_name', 'logo'], + ]; + } + + + /** + * @notes 获取标签列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function lists(): array + { + return Label::where($this->searchWhere) + ->field(['id', 'label_name', 'logo']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取标签数量 + * @return int + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function count(): int + { + return Label::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/article/ArticleLabelLogic.php b/app/admin/logic/article/ArticleLabelLogic.php new file mode 100644 index 0000000..0704dd7 --- /dev/null +++ b/app/admin/logic/article/ArticleLabelLogic.php @@ -0,0 +1,94 @@ +getMessage()); + return false; + } + } + + + /** + * @notes 编辑文章标签 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ArticleLabel::where('id', $params['id'])->update([ + + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除文章标签 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public static function delete(array $params): bool + { + return ArticleLabel::destroy($params['id']); + } + + + /** + * @notes 获取文章标签详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public static function detail($params): array + { + return ArticleLabel::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/setting/LabelLogic.php b/app/admin/logic/setting/LabelLogic.php new file mode 100644 index 0000000..11f29f6 --- /dev/null +++ b/app/admin/logic/setting/LabelLogic.php @@ -0,0 +1,96 @@ + $params['label_name'], + 'logo' => $params['logo'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑标签 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Label::where('id', $params['id'])->update([ + 'label_name' => $params['label_name'], + 'logo' => $params['logo'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除标签 + * @param array $params + * @return bool + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public static function delete(array $params): bool + { + return Label::destroy($params['id']); + } + + + /** + * @notes 获取标签详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public static function detail($params): array + { + return Label::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/article/ArticleLabelValidate.php b/app/admin/validate/article/ArticleLabelValidate.php new file mode 100644 index 0000000..6e9964d --- /dev/null +++ b/app/admin/validate/article/ArticleLabelValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ArticleLabelValidate + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ArticleLabelValidate + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ArticleLabelValidate + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ArticleLabelValidate + * @author likeadmin + * @date 2024/02/17 14:07 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/setting/LabelValidate.php b/app/admin/validate/setting/LabelValidate.php new file mode 100644 index 0000000..341347b --- /dev/null +++ b/app/admin/validate/setting/LabelValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return LabelValidate + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return LabelValidate + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return LabelValidate + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return LabelValidate + * @author likeadmin + * @date 2024/02/17 13:57 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/article/ArticleLabel.php b/app/common/model/article/ArticleLabel.php new file mode 100644 index 0000000..92cc64a --- /dev/null +++ b/app/common/model/article/ArticleLabel.php @@ -0,0 +1,22 @@ +getTableName(); + $content = Str::camel($this->getTableName()); if (!empty($this->classDir)) { - $content = $this->classDir . '/' . $this->getTableName(); + $content = $this->classDir . '/' . Str::camel($this->getTableName()); } return Str::lower($content); }