From 81e7bce99fbbb61947f26894e18bf6af1d7de6e0 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Mon, 13 Nov 2023 16:10:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=94=A8=E6=88=B7=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E5=85=B3=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/user/UserController.php | 12 ++++++ app/api/logic/LoginLogic.php | 4 -- app/api/logic/UserLogic.php | 38 ++++++++++++++++++- app/common/model/systems/SystemUser.php | 11 ++++++ .../validate/user/SystemUserValidate.php | 38 +++++++++++++++++++ 5 files changed, 98 insertions(+), 5 deletions(-) create mode 100644 app/common/model/systems/SystemUser.php create mode 100644 app/common/validate/user/SystemUserValidate.php diff --git a/app/api/controller/user/UserController.php b/app/api/controller/user/UserController.php index 95d4ad75..45298fdc 100644 --- a/app/api/controller/user/UserController.php +++ b/app/api/controller/user/UserController.php @@ -6,6 +6,7 @@ use app\api\controller\BaseApiController; use app\api\logic\UserLogic; use app\common\validate\login\PasswordValidate; use app\common\validate\user\UserValidate; +use app\common\validate\user\SystemUserValidate; use think\response\Json; class UserController extends BaseApiController @@ -45,6 +46,17 @@ class UserController extends BaseApiController return $this->fail(UserLogic::getError()); } + //绑定中台系统子应用用户关系 + public function bindSystemUser(): Json + { + $params = (new SystemUserValidate())->post()->goCheck('bind'); + $result = UserLogic::bindSystemUser($params, $this->userInfo); + if($result) { + return $this->success('操作成功'); + } + return $this->fail(UserLogic::getError()); + } + /* // 更新用户信息 public function updateUser(): Json diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index 793040ea..1cc2ae7e 100644 --- a/app/api/logic/LoginLogic.php +++ b/app/api/logic/LoginLogic.php @@ -151,10 +151,6 @@ class LoginLogic extends BaseLogic try { $userInfo = JwtTokenService::parseToken($params['token']); return $userInfo; - return [ - 'uid' => $userInfo['uid'], - 'phone' => $userInfo['phone'] - ]; } catch (\Exception $e) { //记录日志 Log::error($e->getMessage()); diff --git a/app/api/logic/UserLogic.php b/app/api/logic/UserLogic.php index e64ea357..e8c060cb 100644 --- a/app/api/logic/UserLogic.php +++ b/app/api/logic/UserLogic.php @@ -1,7 +1,8 @@ $params['app_id'], + 'user_id' => $userinfo['user_id'], + 'system_user_id' => $params['system_user_id'] + ])->findOrEmpty(); + if ($systemUser->isEmpty()) { + SystemUser::create([ + 'app_id' => $params['app_id'], + 'user_id' => $userinfo['user_id'], + 'system_user_id' => $params['system_user_id'], + 'phone' => $userinfo['phone'], + 'create_time' => time(), + 'update_time' => time() + ]); + } else { + SystemUser::where('id', $systemUser['id'])->update([ + 'app_id' => $params['app_id'], + 'user_id' => $userinfo['user_id'], + 'system_user_id' => $params['system_user_id'], + 'phone' => $userinfo['phone'], + 'create_time' => time(), + 'update_time' => time() + ]); + } + return true; + }catch (\Exception $e){ + self::setError($e->getMessage()); + return false; + } + } + } \ No newline at end of file diff --git a/app/common/model/systems/SystemUser.php b/app/common/model/systems/SystemUser.php new file mode 100644 index 00000000..5dc1c354 --- /dev/null +++ b/app/common/model/systems/SystemUser.php @@ -0,0 +1,11 @@ + 'require|checkApp', + 'system_user_id' => 'require', + ]; + + protected $message = [ + 'app_id.require' => '应用id不能为空', + 'system_user_id.require' => '应用用户id不能为空' + ]; + + public function sceneBind(): SystemUserValidate + { + return $this->only(['app_id', 'system_user_id']); + } + + public function checkApp($appid): bool|string + { + $app = System::field('id, status')->where('app_id',$appid)->findOrEmpty(); + if($app->isEmpty()){ + return '应用错误'; + } + if ($app['status'] != 0) { + return '应用已禁止或删除'; + } + return true; + } +} \ No newline at end of file