From 62ac0003dbca242cd34e17d10d72124814433235 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 23 Jul 2024 15:16:10 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=20=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/TagCateController.php | 120 +++++++++++++++++++++++++++++++++++ app/controller/TagController.php | 63 ++++++++++++++++++ app/model/Tag.php | 9 +++ app/model/TagCate.php | 13 ++++ app/service/TagCateService.php | 17 +++++ route/app.php | 17 +++++ 6 files changed, 239 insertions(+) create mode 100644 app/controller/TagCateController.php create mode 100644 app/controller/TagController.php create mode 100644 app/model/Tag.php create mode 100644 app/model/TagCate.php create mode 100644 app/service/TagCateService.php diff --git a/app/controller/TagCateController.php b/app/controller/TagCateController.php new file mode 100644 index 0000000..0d0a088 --- /dev/null +++ b/app/controller/TagCateController.php @@ -0,0 +1,120 @@ +select(); + return jsonReturn(0, Lang::get('成功'), $tage_cate); + } + + /** + * 新建标签组 + * @param Request $request + * @return json + */ + public function save(Request $request) + { + try { + //默认是自定义标签组 + if (TagCate::where('name', $request->param('name'))->count() > 0) { + return jsonReturn(-5, '标签组已经存在'); + } + TagCate::create($request->param()); + } catch (\Exception $e) { + return jsonReturn(-5, $e->getMessage()); + } + return jsonReturn(0, Lang::get('新建标签组成功')); + } + + /** + * 新建标签 + * @param Request $request + * @return json + */ + public function saveTag(Request $request) + { + try { + if (Tag::where('cate_id', $request->param('id'))->where('name', $request->param('name'))->count() > 0) { + throw new \Exception('标签已经存在'); + } + $tag_cate = TagCate::find($request->param('id')); + + $tag = new Tag; + $tag->cate_id = $request->param('id'); + $tag->name = $request->param('name'); + $tag->type = $tag_cate->type; //标签的type 和标签组保持一致? + $tag->save(); + + return jsonReturn(0, Lang::get('新建标签成功')); + } catch (\Exception $e) { + return jsonReturn(-5, $e->getMessage()); + } + } + + /** + * 重命名标签组 + * @param Request $request + * @return json + */ + public function rename(Request $request) + { + try { + TagCate::whereIn('id', $request->param('id'))->update(['name' => $request->param('name')]); + return jsonReturn(0, Lang::get('重命名成功')); + } catch (\Exception $e) { + return jsonReturn(-5, $e->getMessage()); + } + } + + /** + * 删除标签组 + * @param Request $request + * @return json + */ + public function delete(Request $request) + { + Db::startTrans(); + try { + $tag_cate = TagCate::where('id', $request->param('id'))->find(); + if ($tag_cate->type == 1) { + throw new \Exception('系统标签无法删除'); + } + + //删除标签组 + $tag_cate->delete(); + + //标签组下标签移动到默认系统标签 + $default_tag_cate = (new TagCateService())->getDefaultTagCate(); + if (!$default_tag_cate) { + throw new \Exception('没有找到默认系统标签'); + } + Tag::where('cate_id', $request->param('id'))->update(['cate_id' => $default_tag_cate->id]); + Db::commit(); + return jsonReturn(0, Lang::get('删除标签组成功')); + + } catch (\Exception $e) { + Db::rollback(); + return jsonReturn(-5, $e->getMessage()); + } + } + + +} diff --git a/app/controller/TagController.php b/app/controller/TagController.php new file mode 100644 index 0000000..6393b9f --- /dev/null +++ b/app/controller/TagController.php @@ -0,0 +1,63 @@ +param('id')); + if (Tag::where('cate_id', $tag->cate_id)->where('name', $request->param('name'))->count() > 0) { + throw new \Exception('同标签组标签已经存在'); + } + $tag->name = $request->param('name'); + $tag->save(); + return jsonReturn(0, Lang::get('重命名成功')); + } catch (\Exception $e) { + return jsonReturn(-5, $e->getMessage()); + } + } + + /** + * 标签移动 + * @param Request $request + * @return json + */ + public function moveTo(Request $request) + { + try { + $tag = Tag::find($request->param('id')); + $tag->cate_id = $request->param('cate_id'); + $tag->save(); + return jsonReturn(0, Lang::get('移动成功')); + } catch (\Exception $e) { + return jsonReturn(-5, $e->getMessage()); + } + } + + public function delete() + { + //todo 删除标签 从素材上移出?后面再看 + } +} diff --git a/app/model/Tag.php b/app/model/Tag.php new file mode 100644 index 0000000..a88cb51 --- /dev/null +++ b/app/model/Tag.php @@ -0,0 +1,9 @@ +hasMany(Tag::class, 'cate_id', 'id'); + } +} diff --git a/app/service/TagCateService.php b/app/service/TagCateService.php new file mode 100644 index 0000000..572b3d4 --- /dev/null +++ b/app/service/TagCateService.php @@ -0,0 +1,17 @@ +where('type', 1)->find(); + } +} diff --git a/route/app.php b/route/app.php index e000cb3..c6147a3 100644 --- a/route/app.php +++ b/route/app.php @@ -59,6 +59,23 @@ Route::group('process_reason', function () { })->prefix('processReason/'); +//后台-标签组设置 +Route::group('tag_cate', function () { + Route::get('/index', 'index'); + Route::post('/save', 'save'); //新增标签组 + Route::post('/save_tag', 'saveTag'); //新增标签 + Route::post('/rename', 'rename'); + Route::post('/delete', 'delete'); +})->prefix('tagCate/'); + +//后台-标签组设置 +Route::group('tag', function () { + Route::post('/rename', 'rename'); + Route::post('/move_to', 'moveTo'); + Route::post('/delete', 'delete'); +})->prefix('tag/'); + + //阿里云 Route::group('oss', function () { Route::post('/upload', 'oss/upload');