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