From db61d6f92be0379f8728ca27fc0bf2537c42f111 Mon Sep 17 00:00:00 2001 From: weiz Date: Wed, 13 Dec 2023 14:53:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=A1=B9=E7=9B=AE=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E8=AE=BE=E7=BD=AE=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/ProjectRoleSetController.php | 108 ++++++++++++++++++ .../lists/project/ProjectRoleSetLists.php | 77 +++++++++++++ .../logic/project/ProjectRoleSetLogic.php | 108 ++++++++++++++++++ .../project/ProjectRoleSetValidate.php | 105 +++++++++++++++++ app/common/model/project/ProjectRoleSet.php | 34 ++++++ 5 files changed, 432 insertions(+) create mode 100644 app/adminapi/controller/project/ProjectRoleSetController.php create mode 100644 app/adminapi/lists/project/ProjectRoleSetLists.php create mode 100644 app/adminapi/logic/project/ProjectRoleSetLogic.php create mode 100644 app/adminapi/validate/project/ProjectRoleSetValidate.php create mode 100644 app/common/model/project/ProjectRoleSet.php diff --git a/app/adminapi/controller/project/ProjectRoleSetController.php b/app/adminapi/controller/project/ProjectRoleSetController.php new file mode 100644 index 000000000..d0ce44191 --- /dev/null +++ b/app/adminapi/controller/project/ProjectRoleSetController.php @@ -0,0 +1,108 @@ +dataLists(new ProjectRoleSetLists()); + } + + + /** + * @notes 添加项目角色设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function add() + { + $params = (new ProjectRoleSetValidate())->post()->goCheck('add'); + $result = ProjectRoleSetLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(ProjectRoleSetLogic::getError()); + } + + + /** + * @notes 编辑项目角色设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function edit() + { + $params = (new ProjectRoleSetValidate())->post()->goCheck('edit'); + $result = ProjectRoleSetLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(ProjectRoleSetLogic::getError()); + } + + + /** + * @notes 删除项目角色设置 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function delete() + { + $params = (new ProjectRoleSetValidate())->post()->goCheck('delete'); + ProjectRoleSetLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取项目角色设置详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function detail() + { + $params = (new ProjectRoleSetValidate())->goCheck('detail'); + $result = ProjectRoleSetLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/project/ProjectRoleSetLists.php b/app/adminapi/lists/project/ProjectRoleSetLists.php new file mode 100644 index 000000000..71d99884a --- /dev/null +++ b/app/adminapi/lists/project/ProjectRoleSetLists.php @@ -0,0 +1,77 @@ + ['name'], + ]; + } + + + /** + * @notes 获取项目角色设置列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function lists(): array + { + return ProjectRoleSet::where($this->searchWhere) + ->field(['id', 'name', 'sort']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取项目角色设置数量 + * @return int + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function count(): int + { + return ProjectRoleSet::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectRoleSetLogic.php b/app/adminapi/logic/project/ProjectRoleSetLogic.php new file mode 100644 index 000000000..f7920ad53 --- /dev/null +++ b/app/adminapi/logic/project/ProjectRoleSetLogic.php @@ -0,0 +1,108 @@ + $params['name'], + 'sort' => $params['sort'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑项目角色设置 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + ProjectRoleSet::where('id', $params['id'])->update([ + 'name' => $params['name'], + 'sort' => $params['sort'], + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除项目角色设置 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public static function delete(array $params): bool + { + return ProjectRoleSet::destroy($params['id']); + } + + + /** + * @notes 获取项目角色设置详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public static function detail($params): array + { + return ProjectRoleSet::field('id,name,sort')->findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectRoleSetValidate.php b/app/adminapi/validate/project/ProjectRoleSetValidate.php new file mode 100644 index 000000000..87c3cec0a --- /dev/null +++ b/app/adminapi/validate/project/ProjectRoleSetValidate.php @@ -0,0 +1,105 @@ + 'require', + 'name' => 'require|unique:'.ProjectRoleSet::class, + 'sort' => 'require|integer', + ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'name.require' => '角色名称不能为空', + 'name.unique' => '角色名称已存在', + 'sort.require' => '排序号不能为空', + 'sort.integer' => '排序号必须为整数', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + 'name' => '角色名称', + 'sort' => '排序号', + ]; + + + /** + * @notes 添加场景 + * @return ProjectRoleSetValidate + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function sceneAdd() + { + return $this->remove('id',true); + } + + + /** + * @notes 编辑场景 + * @return ProjectRoleSetValidate + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function sceneEdit() + {} + + + /** + * @notes 删除场景 + * @return ProjectRoleSetValidate + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return ProjectRoleSetValidate + * @author likeadmin + * @date 2023/12/13 14:23 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/project/ProjectRoleSet.php b/app/common/model/project/ProjectRoleSet.php new file mode 100644 index 000000000..2bc9c4788 --- /dev/null +++ b/app/common/model/project/ProjectRoleSet.php @@ -0,0 +1,34 @@ +