From ed9f8742932c08d4af0b9c9068fa8cadc89e4d62 Mon Sep 17 00:00:00 2001 From: ctexthuang Date: Tue, 29 Oct 2024 17:25:19 +0800 Subject: [PATCH] feat : user --- app/Constants/Common/VerifyTypeCode.php | 26 +++++++ app/Controller/Admin/EmployeeController.php | 56 ++++++++++++++ app/Extend/StringUtil.php | 83 +++++++++++++++++++++ app/Model/AdminUser.php | 9 +++ app/Request/Admin/EmployeeRequest.php | 56 ++++++++++++++ app/Service/Admin/EmployeeService.php | 73 ++++++++++++++++++ 6 files changed, 303 insertions(+) create mode 100644 app/Constants/Common/VerifyTypeCode.php create mode 100644 app/Controller/Admin/EmployeeController.php create mode 100644 app/Extend/StringUtil.php create mode 100644 app/Request/Admin/EmployeeRequest.php create mode 100644 app/Service/Admin/EmployeeService.php diff --git a/app/Constants/Common/VerifyTypeCode.php b/app/Constants/Common/VerifyTypeCode.php new file mode 100644 index 0000000..5595ae4 --- /dev/null +++ b/app/Constants/Common/VerifyTypeCode.php @@ -0,0 +1,26 @@ +add(); + } + + #[RequestMapping(path: "edit", methods: "POST")] + #[Scene(scene: "edit")] + public function edit(EmployeeRequest $request) + { + return (new EmployeeService)->edit(); + } + + #[RequestMapping(path: "del", methods: "POST")] + #[Scene(scene: "del")] + public function delete(EmployeeRequest $request) + { + return (new EmployeeService)->delete(); + } + + #[RequestMapping(path: "list", methods: "POST")] + #[Scene(scene: "list")] + public function list(EmployeeRequest $request) + { + return (new EmployeeService)->handle(); + } + + #[RequestMapping(path: "info", methods: "POST")] + #[Scene(scene: "info")] + public function info(EmployeeRequest $request) + { + return (new EmployeeService)->get(); + } +} diff --git a/app/Extend/StringUtil.php b/app/Extend/StringUtil.php new file mode 100644 index 0000000..a7eefbc --- /dev/null +++ b/app/Extend/StringUtil.php @@ -0,0 +1,83 @@ +where('username', $account)->where('is_del',1)->first(); } + + /** + * @param $name + * @return \Hyperf\Database\Model\Model|Builder|null + */ + public function getAdminInfoByName($name): \Hyperf\Database\Model\Model|Builder|null + { + return $this->where('chinese_name', $name)->where('is_del',1)->first(); + } } diff --git a/app/Request/Admin/EmployeeRequest.php b/app/Request/Admin/EmployeeRequest.php new file mode 100644 index 0000000..bc88341 --- /dev/null +++ b/app/Request/Admin/EmployeeRequest.php @@ -0,0 +1,56 @@ + 'required|digits:11', + 'chinese_name' =>'required|string', + 'status' => 'required|in:1,2', + 'role_id' => 'exists:admin_role,id', + 'avatar' => '', + 'limit' => 'required|integer', + ]; + } + + public function messages(): array + { + return [ + 'account.required' => '账号必填', + 'account.digits' => '账号格式错误', + 'chinese_name.required' => '名称必填', + 'status.required' => '状态必填', + 'status.in' => '状态值错误', + 'role_id.exists' => '角色不存在', +// 'avatar.required' => '头像必填', + 'limit.required' => 'limit必填' + ]; + } + + protected array $scenes = [ + 'add' => ['account','chinese_name','status','role_id','avatar'], + 'edit' => ['id','account','chinese_name','status','role_id','avatar'], + 'del' => ['id'], + 'reset_password' => ['id'], + 'info' => ['id'], + 'list' => ['limit'] + ]; +} diff --git a/app/Service/Admin/EmployeeService.php b/app/Service/Admin/EmployeeService.php new file mode 100644 index 0000000..23015cc --- /dev/null +++ b/app/Service/Admin/EmployeeService.php @@ -0,0 +1,73 @@ +return->success(); + } + + public function add() + { + $name = $this->request->input('chinese_name'); + $account = $this->request->input('account'); + + $oldAccount = $this->adminUserModel->getAdminInfoByAccount($account); + $oldName = $this->adminUserModel->getAdminInfoByName($name); + + if (!empty($oldName) && !empty($oldAccount)) throw new AdminException('账号或者员工已存在'); + + $salt = StringUtil::randStr(6); + + $model = new AdminUser(); + + $model->username = $account; + $model->chinese_name = $name; + $model->salt = + $model->status = $this->request->input('status', 1); + $model->avatar = $this->request->input('avatar',0); + $model->role_id = $this->request->input('role_id', 0); + + + $model->save(); + + return $this->return->success(); + } + + public function edit() + { + return $this->return->success(); + } + + public function delete() + { + return $this->return->success(); + } + + public function get() + { + return $this->return->success(); + } +} \ No newline at end of file