diff --git a/app/admin/controller/article/ArticleController.php b/app/admin/controller/article/ArticleController.php new file mode 100644 index 0000000..d40c89f --- /dev/null +++ b/app/admin/controller/article/ArticleController.php @@ -0,0 +1,95 @@ +dataLists(new ArticleLists()); + } + + + /** + * @notes 添加文章 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function add() + { + $params = (new ArticleValidate())->post()->goCheck('add'); + $result = ArticleLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ArticleLogic::getError()); + } + + + /** + * @notes 编辑文章 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function edit() + { + $params = (new ArticleValidate())->post()->goCheck('edit'); + $result = ArticleLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ArticleLogic::getError()); + } + + + /** + * @notes 删除文章 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function delete() + { + $params = (new ArticleValidate())->post()->goCheck('delete'); + ArticleLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取文章详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function detail() + { + $params = (new ArticleValidate())->goCheck('detail'); + $result = ArticleLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/controller/setting/CategoryController.php b/app/admin/controller/setting/CategoryController.php new file mode 100644 index 0000000..9119440 --- /dev/null +++ b/app/admin/controller/setting/CategoryController.php @@ -0,0 +1,95 @@ +dataLists(new CategoryLists()); + } + + + /** + * @notes 添加分类表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function add() + { + $params = (new CategoryValidate())->post()->goCheck('add'); + $result = CategoryLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(CategoryLogic::getError()); + } + + + /** + * @notes 编辑分类表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function edit() + { + $params = (new CategoryValidate())->post()->goCheck('edit'); + $result = CategoryLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(CategoryLogic::getError()); + } + + + /** + * @notes 删除分类表 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function delete() + { + $params = (new CategoryValidate())->post()->goCheck('delete'); + CategoryLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取分类表详情 + * @return \think\response\Json + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function detail() + { + $params = (new CategoryValidate())->goCheck('detail'); + $result = CategoryLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/article/ArticleLists.php b/app/admin/lists/article/ArticleLists.php new file mode 100644 index 0000000..278bcc5 --- /dev/null +++ b/app/admin/lists/article/ArticleLists.php @@ -0,0 +1,65 @@ + ['title', 'state'], + ]; + } + + + /** + * @notes 获取文章列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function lists(): array + { + return Article::where($this->searchWhere) + ->field(['id', 'title_map', 'title', 'state', 'pv', 'top', 'create_user', 'update_user']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取文章数量 + * @return int + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function count(): int + { + return Article::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/lists/setting/CategoryLists.php b/app/admin/lists/setting/CategoryLists.php new file mode 100644 index 0000000..0ef0ce0 --- /dev/null +++ b/app/admin/lists/setting/CategoryLists.php @@ -0,0 +1,65 @@ + ['pid', 'cate_name', 'path', 'sort', 'pic', 'is_show', 'level'], + ]; + } + + + /** + * @notes 获取分类表列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function lists(): array + { + return Category::where($this->searchWhere) + ->field(['category_id', 'pid', 'cate_name', 'path', 'sort', 'pic', 'is_show', 'level']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['category_id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取分类表数量 + * @return int + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function count(): int + { + return Category::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/admin/logic/article/ArticleLogic.php b/app/admin/logic/article/ArticleLogic.php new file mode 100644 index 0000000..4225517 --- /dev/null +++ b/app/admin/logic/article/ArticleLogic.php @@ -0,0 +1,108 @@ + $params['title'], + 'state' => $params['state'], + 'top' => $params['top'] + ]); + ArticleContent::create(['article_id'=>$res->id,'content'=>$params['content']]); + 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/05 16:36 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Article::where('id', $params['id'])->update([ + 'title_map' => $params['title_map'], + 'title' => $params['title'], + 'state' => $params['state'], + // 'pv' => $params['pv'], + 'top' => $params['top'], + // 'create_user' => $params['create_user'], + // 'update_user' => $params['update_user'] + ]); + $find=ArticleContent::where('article_id',$params['id'])->find(); + if($find){ + ArticleContent::where('article_id',$params['id'])->update(['content'=>$params['content']]); + }else{ + ArticleContent::create(['article_id'=>$params['id'],'content'=>$params['content']]); + } + 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/05 16:36 + */ + public static function delete(array $params): bool + { + return Article::destroy($params['id']); + } + + + /** + * @notes 获取文章详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public static function detail($params): array + { + return Article::with('detail')->findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/logic/setting/CategoryLogic.php b/app/admin/logic/setting/CategoryLogic.php new file mode 100644 index 0000000..2afd91f --- /dev/null +++ b/app/admin/logic/setting/CategoryLogic.php @@ -0,0 +1,108 @@ + $params['category_id'], + 'pid' => $params['pid'], + 'cate_name' => $params['cate_name'], + 'path' => $params['path'], + 'sort' => $params['sort'], + 'pic' => $params['pic'], + 'is_show' => $params['is_show'], + 'level' => $params['level'] + ]); + + 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/05 16:13 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Category::where('category_id', $params['category_id'])->update([ + 'category_id' => $params['category_id'], + 'pid' => $params['pid'], + 'cate_name' => $params['cate_name'], + 'path' => $params['path'], + 'sort' => $params['sort'], + 'pic' => $params['pic'], + 'is_show' => $params['is_show'], + 'level' => $params['level'] + ]); + + 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/05 16:13 + */ + public static function delete(array $params): bool + { + return Category::destroy($params['category_id']); + } + + + /** + * @notes 获取分类表详情 + * @param $params + * @return array + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public static function detail($params): array + { + return Category::findOrEmpty($params['category_id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/article/ArticleValidate.php b/app/admin/validate/article/ArticleValidate.php new file mode 100644 index 0000000..00f73f5 --- /dev/null +++ b/app/admin/validate/article/ArticleValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return ArticleValidate + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return ArticleValidate + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return ArticleValidate + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ArticleValidate + * @author likeadmin + * @date 2024/02/05 16:36 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/admin/validate/setting/CategoryValidate.php b/app/admin/validate/setting/CategoryValidate.php new file mode 100644 index 0000000..63ed095 --- /dev/null +++ b/app/admin/validate/setting/CategoryValidate.php @@ -0,0 +1,94 @@ + 'require', + 'pid' => 'require', + 'cate_name' => 'require', + 'path' => 'require', + 'sort' => 'require', + 'is_show' => 'require', + 'level' => 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'category_id' => 'category_id', + 'pid' => '父id', + 'cate_name' => '分类名称', + 'path' => '路径', + 'sort' => '排序', + 'is_show' => '是否显示', + 'level' => '等级', + ]; + + + /** + * @notes 添加场景 + * @return CategoryValidate + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function sceneAdd() + { + return $this->only(['pid','cate_name','path','sort','is_show','level']); + } + + + /** + * @notes 编辑场景 + * @return CategoryValidate + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function sceneEdit() + { + return $this->only(['category_id','pid','cate_name','path','sort','is_show','level']); + } + + + /** + * @notes 删除场景 + * @return CategoryValidate + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function sceneDelete() + { + return $this->only(['category_id']); + } + + + /** + * @notes 详情场景 + * @return CategoryValidate + * @author likeadmin + * @date 2024/02/05 16:13 + */ + public function sceneDetail() + { + return $this->only(['category_id']); + } + +} \ No newline at end of file diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index 95880a6..87cf5c9 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -19,6 +19,7 @@ class IndexController extends BaseLikeAdminController public function download() { $params = (new GenerateTableValidate())->goCheck('download'); + var_dump($params); $result = GeneratorLogic::download($params['file']); if (false === $result) { return $this->fail(GeneratorLogic::getError() ?: '下载失败'); diff --git a/app/common/model/article/Article.php b/app/common/model/article/Article.php new file mode 100644 index 0000000..0e1ef04 --- /dev/null +++ b/app/common/model/article/Article.php @@ -0,0 +1,25 @@ +hasOne(ArticleContent::class,'article_id')->bind(['content']); + } +} \ No newline at end of file diff --git a/app/common/model/article/ArticleContent.php b/app/common/model/article/ArticleContent.php new file mode 100644 index 0000000..903babc --- /dev/null +++ b/app/common/model/article/ArticleContent.php @@ -0,0 +1,18 @@ + $file['type'], 'name' => $file['name'], 'uri' => FileService::getFileUrl($file['uri']), - 'url' => $file['uri'] + 'succMap' => [ + $fileInfo['name']=> $file['uri'] + ] ]; } catch (Exception $e) { diff --git a/app/common/service/generator/core/VueApiGenerator.php b/app/common/service/generator/core/VueApiGenerator.php index aba12d4..0844955 100644 --- a/app/common/service/generator/core/VueApiGenerator.php +++ b/app/common/service/generator/core/VueApiGenerator.php @@ -79,7 +79,7 @@ class VueApiGenerator extends BaseGenerator implements GenerateInterface { $content = $this->getTableName(); if (!empty($this->classDir)) { - $content = $this->classDir . '.' . $this->getTableName(); + $content = $this->classDir . '/' . $this->getTableName(); } return Str::lower($content); }