From 1b4822e8c7a4f4b4713e9f02fb2995ed9bbcc4d6 Mon Sep 17 00:00:00 2001 From: chenbo <709206448@qq.com> Date: Thu, 28 Dec 2023 10:45:34 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=EF=BC=8C=E5=90=8E=E5=8F=B0=E7=89=87=E5=8C=BA=E5=BB=BA=E6=A1=A3?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserInformationThresholdController.php | 108 ++++++++++++++++++ app/adminapi/listener/OperationLog.php | 2 +- .../lists/UserInformationThresholdLists.php | 77 +++++++++++++ .../logic/UserInformationThresholdLogic.php | 108 ++++++++++++++++++ .../UserInformationThresholdValidate.php | 94 +++++++++++++++ app/api/controller/new/UserController.php | 61 ++-------- app/api/logic/UserLogic.php | 51 +++++++++ app/api/validate/RegisterValidate.php | 8 +- app/common/model/UserInformationThreshold.php | 34 ++++++ 9 files changed, 485 insertions(+), 58 deletions(-) create mode 100644 app/adminapi/controller/UserInformationThresholdController.php create mode 100644 app/adminapi/lists/UserInformationThresholdLists.php create mode 100644 app/adminapi/logic/UserInformationThresholdLogic.php create mode 100644 app/adminapi/validate/UserInformationThresholdValidate.php create mode 100644 app/common/model/UserInformationThreshold.php diff --git a/app/adminapi/controller/UserInformationThresholdController.php b/app/adminapi/controller/UserInformationThresholdController.php new file mode 100644 index 00000000..6ea3f0ef --- /dev/null +++ b/app/adminapi/controller/UserInformationThresholdController.php @@ -0,0 +1,108 @@ +dataLists(new UserInformationThresholdLists()); + } + + + /** + * @notes 添加 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function add() + { + $params = (new UserInformationThresholdValidate())->post()->goCheck('add'); + $result = UserInformationThresholdLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(UserInformationThresholdLogic::getError()); + } + + + /** + * @notes 编辑 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function edit() + { + $params = (new UserInformationThresholdValidate())->post()->goCheck('edit'); + $result = UserInformationThresholdLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(UserInformationThresholdLogic::getError()); + } + + + /** + * @notes 删除 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function delete() + { + $params = (new UserInformationThresholdValidate())->post()->goCheck('delete'); + UserInformationThresholdLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function detail() + { + $params = (new UserInformationThresholdValidate())->goCheck('detail'); + $result = UserInformationThresholdLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/listener/OperationLog.php b/app/adminapi/listener/OperationLog.php index 87bb054c..9c538ae2 100644 --- a/app/adminapi/listener/OperationLog.php +++ b/app/adminapi/listener/OperationLog.php @@ -71,7 +71,7 @@ class OperationLog $systemLog->type = $request->isGet() ? 'GET' : 'POST'; $systemLog->params = json_encode($params, true); $systemLog->ip = $request->ip(); - $systemLog->result = $response->getContent(); + $systemLog->result = substr($response->getContent(), 0, 65535); return $systemLog->save(); } } \ No newline at end of file diff --git a/app/adminapi/lists/UserInformationThresholdLists.php b/app/adminapi/lists/UserInformationThresholdLists.php new file mode 100644 index 00000000..564bb5ba --- /dev/null +++ b/app/adminapi/lists/UserInformationThresholdLists.php @@ -0,0 +1,77 @@ + ['village_code', 'threshold_value'], + ]; + } + + + /** + * @notes 获取列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function lists(): array + { + return UserInformationThreshold::where($this->searchWhere) + ->field(['id', 'village_code', 'threshold_value']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取数量 + * @return int + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function count(): int + { + return UserInformationThreshold::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/logic/UserInformationThresholdLogic.php b/app/adminapi/logic/UserInformationThresholdLogic.php new file mode 100644 index 00000000..fd878d12 --- /dev/null +++ b/app/adminapi/logic/UserInformationThresholdLogic.php @@ -0,0 +1,108 @@ + $params['village_code'], + 'threshold_value' => $params['threshold_value'], + ]); + + 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/28 10:41 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + UserInformationThreshold::where('id', $params['id'])->update([ + 'village_code' => $params['village_code'], + 'threshold_value' => $params['threshold_value'], + ]); + + 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/28 10:41 + */ + public static function delete(array $params): bool + { + return UserInformationThreshold::destroy($params['id']); + } + + + /** + * @notes 获取详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public static function detail($params): array + { + return UserInformationThreshold::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/adminapi/validate/UserInformationThresholdValidate.php b/app/adminapi/validate/UserInformationThresholdValidate.php new file mode 100644 index 00000000..42335946 --- /dev/null +++ b/app/adminapi/validate/UserInformationThresholdValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return UserInformationThresholdValidate + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return UserInformationThresholdValidate + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return UserInformationThresholdValidate + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return UserInformationThresholdValidate + * @author likeadmin + * @date 2023/12/28 10:41 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/api/controller/new/UserController.php b/app/api/controller/new/UserController.php index 9101d5f8..3718fedd 100644 --- a/app/api/controller/new/UserController.php +++ b/app/api/controller/new/UserController.php @@ -3,64 +3,21 @@ namespace app\api\controller\new; use app\api\controller\BaseApiController; -use app\common\model\dict\DictData; -use app\common\model\user\User; -use app\common\service\ConfigService; -use think\facade\Config; +use app\api\logic\UserLogic; +use app\api\validate\RegisterValidate; + class UserController extends BaseApiController { - - + public array $notNeedLogin = ['register']; public function register() { // 用户注册逻辑 - $params = $this->request->param(); - try { - // 手机号已被使用 - $mobileUser = User::where(['account' => $params['account']])->find(); - if (!empty($mobileUser)) { - self::setError('手机号已被注册'); - return false; - } - // 生成用户编号 - $userSn = User::createUserSn(); - $passwordSalt = Config::get('project.unique_identification'); - $password = create_password($params['password'], $passwordSalt); - - if ($params['avatar'] != '') { - $avatar = $params['avatar']; - } else { - $avatar = ConfigService::get('default_image', 'user_avatar'); - } - - User::create([ - 'sn' => $userSn, - 'avatar' => $avatar, - 'is_captain' => $params['is_captain'], - 'nickname' => $params['nickname'], - 'account' => $params['account'], - 'mobile' => $params['account'], - 'id_card' => $params['id_card'], - 'password' => $password, - 'channel' => 0, - 'sex' => $params['sex'], - 'province' => $params['province'], - 'city' => $params['city'], - 'area' => $params['area'], - 'street' => $params['street'], - 'village' => $params['village'], - 'brigade' => $params['brigade'], - 'address' => $params['address'], - 'qualification' => json_encode($params['qualification']), - 'company_id' => $params['company_id'], - 'group_id' => $params['group_id'], - ]); - - return true; - } catch (\Exception $e) { - self::setError($e->getMessage()); - return false; + $params = (new RegisterValidate())->post()->goCheck('register'); + $result = UserLogic::register($params); + if (true === $result) { + return $this->success('注册成功', [], 1, 1); } + return $this->fail(UserLogic::getError()); } } \ No newline at end of file diff --git a/app/api/logic/UserLogic.php b/app/api/logic/UserLogic.php index 8543a2ff..aa353612 100644 --- a/app/api/logic/UserLogic.php +++ b/app/api/logic/UserLogic.php @@ -22,6 +22,7 @@ use app\common\{enum\notice\NoticeEnum, model\user\User, model\user\UserAuth, model\user\Withdraw, + service\ConfigService, service\sms\SmsDriver, service\wechat\WeChatMnpService}; use app\common\model\dict\DictData; @@ -366,4 +367,54 @@ class UserLogic extends BaseLogic return [$count, $list]; } + public static function register(array $params) + { + try { + // 手机号已被使用 + $mobileUser = User::where(['account' => $params['account']])->find(); + if (!empty($mobileUser)) { + self::setError('手机号已被注册'); + return false; + } + // 生成用户编号 + $userSn = User::createUserSn(); + $passwordSalt = Config::get('project.unique_identification'); + $password = create_password($params['password'], $passwordSalt); + + if ($params['avatar'] != '') { + $avatar = $params['avatar']; + } else { + $avatar = ConfigService::get('default_image', 'user_avatar'); + } + + User::create([ + 'sn' => $userSn, + 'avatar' => $avatar, + 'is_captain' => 0, + 'nickname' => $params['nickname'], + 'account' => $params['account'], + 'mobile' => $params['account'], + 'id_card' => $params['id_card'], + 'password' => $password, + 'channel' => $params['channel'], + 'sex' => $params['sex'], + 'province' => $params['province'], + 'city' => $params['city'], + 'area' => $params['area'], + 'street' => $params['street'], + 'village' => $params['village'], + 'brigade' => $params['brigade'], + 'address' => $params['address'], + 'qualification' => json_encode($params['qualification']), + 'company_id' => 0, // 暂时为0 + 'group_id' => $params['group_id'], + ]); + + return true; + } catch (\Exception $e) { + self::setError($e->getMessage()); + return false; + } + } + } \ No newline at end of file diff --git a/app/api/validate/RegisterValidate.php b/app/api/validate/RegisterValidate.php index 39b4d5c0..fbd01c0f 100644 --- a/app/api/validate/RegisterValidate.php +++ b/app/api/validate/RegisterValidate.php @@ -26,13 +26,12 @@ class RegisterValidate extends BaseValidate { protected $regex = [ - 'register' => '^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]+$', + 'account' => '/^1[3-9][0-9]\d{8}$/', 'password' => '/^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-z]|[A-Z]|[0-9]){6,20}$/' ]; protected $rule = [ - 'channel' => 'require', - 'account' => 'require|length:3,12|unique:' . User::class . '|regex:register', + 'account' => 'require|unique:' . User::class . '|regex:account', 'password' => 'require|length:6,20|regex:password', 'password_confirm' => 'require|confirm' ]; @@ -40,9 +39,8 @@ class RegisterValidate extends BaseValidate protected $message = [ 'channel.require' => '注册来源参数缺失', 'account.require' => '请输入账号', - 'account.regex' => '账号须为字母数字组合', - 'account.length' => '账号须为3-12位之间', 'account.unique' => '账号已存在', + 'account.regex' => '账号须为手机号', 'password.require' => '请输入密码', 'password.length' => '密码须在6-25位之间', 'password.regex' => '密码须为数字,字母或符号组合', diff --git a/app/common/model/UserInformationThreshold.php b/app/common/model/UserInformationThreshold.php new file mode 100644 index 00000000..5a46fbee --- /dev/null +++ b/app/common/model/UserInformationThreshold.php @@ -0,0 +1,34 @@ +