新增用户绑定关系
This commit is contained in:
parent
653bb99399
commit
81e7bce99f
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace app\api\logic;
|
||||
use app\common\{enum\notice\NoticeEnum, logic\BaseLogic, model\auth\Admin, model\user\User, service\sms\SmsDriver};
|
||||
use app\common\{enum\notice\NoticeEnum, logic\BaseLogic, model\auth\Admin, model\user\User, model\systems\SystemUser, service\sms\SmsDriver};
|
||||
use app\api\service\JwtTokenService;
|
||||
use think\facade\Config;
|
||||
|
||||
/**
|
||||
|
@ -106,4 +107,39 @@ class UserLogic extends BaseLogic
|
|||
}
|
||||
}
|
||||
|
||||
//bind用户信息
|
||||
public static function bindSystemUser(array $params, array $userinfo): bool
|
||||
{
|
||||
try {
|
||||
$systemUser = SystemUser::where([
|
||||
'app_id' => $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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\model\systems;
|
||||
|
||||
use app\common\model\BaseModel;
|
||||
|
||||
class SystemUser extends BaseModel
|
||||
{
|
||||
protected $name = 'system_user';
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace app\common\validate\user;
|
||||
|
||||
|
||||
use app\common\enum\notice\NoticeEnum;
|
||||
use app\common\model\systems\System;
|
||||
use app\common\validate\BaseValidate;
|
||||
|
||||
class SystemUserValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'app_id' => '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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue