更新供销系统登录

This commit is contained in:
yaooo 2023-11-24 14:00:36 +08:00
parent 0e7c4434ff
commit ad80574645

View File

@ -34,6 +34,10 @@ use Firebase\JWT\Key;
use Firebase\JWT\SignatureInvalidException; use Firebase\JWT\SignatureInvalidException;
use Firebase\JWT\BeforeValidException; use Firebase\JWT\BeforeValidException;
use Firebase\JWT\ExpiredException; use Firebase\JWT\ExpiredException;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\GuzzleException;
use Guzzle\Http\Exception\RequestException;
/** /**
* 登录逻辑 * 登录逻辑
* Class LoginLogic * Class LoginLogic
@ -228,36 +232,56 @@ class LoginLogic extends BaseLogic
$where = ['account|mobile' => $jwtData['phone']]; $where = ['account|mobile' => $jwtData['phone']];
$user = User::where($where)->findOrEmpty(); $user = User::where($where)->findOrEmpty();
if ($user->isEmpty()) { if ($user->isEmpty()) {
$user_id = $jwtData['uid']; try {
$find = Db::name('user_other')->where('other_user_id', $user_id)->where('type', 'shop_user')->find(); //适配解析商城token
if ($find) { $parseHostUrl = env('url.shop_prefix') . '/api/parse/token';
$user = User::where('id', $find['user_id'])->findOrEmpty(); $client = new Client(['timeout' => 5]);
if ($user->isEmpty()) { $requestBody['token'] = $token;
$response = $client->request('POST', $parseHostUrl, [
'json' => $requestBody,
'verify' => false
]);
$responseData = $response->getBody()->getContents();
$responseArray = json_decode($responseData, true);
if (empty($responseArray['data']['user']['uid'])) {
self::setError('用户不存在,请联系管理员开通供销系统账户'); self::setError('用户不存在,请联系管理员开通供销系统账户');
return false; return false;
} else {
$user_id = $responseArray['data']['user']['uid'];
$find = Db::name('user_other')->where('other_user_id', $user_id)->where('type', 'shop_user')->find();
if ($find) {
$user = User::where('id', $find['user_id'])->findOrEmpty();
if ($user->isEmpty()) {
self::setError('用户不存在,请联系管理员开通供销系统账户');
return false;
}
$terminal=3;
$Android=IndexLogic::isAndroid();
if($Android){
$terminal=5;
}
$ios=IndexLogic::isIOS();
if($ios){
$terminal=6;
}
$userInfo = UserTokenService::setToken($user->id, $terminal);
//返回登录信息
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
$avatar = FileService::getFileUrl($avatar);
return [
'nickname' => $userInfo['nickname'],
'sn' => $userInfo['sn'],
'mobile' => $userInfo['mobile'],
'avatar' => $avatar,
'token' => $userInfo['token'],
];
} else {
self::setError('用户不存在请联系管理员开通供销系统账户1');
return false;
}
} }
$terminal=3; } catch (GuzzleException $e) {
$Android=IndexLogic::isAndroid(); return $this->fail($e->getMessage());self::setError('用户不存在请联系管理员开通供销系统账户2');
if($Android){
$terminal=5;
}
$ios=IndexLogic::isIOS();
if($ios){
$terminal=6;
}
$userInfo = UserTokenService::setToken($user->id, $terminal);
//返回登录信息
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
$avatar = FileService::getFileUrl($avatar);
return [
'nickname' => $userInfo['nickname'],
'sn' => $userInfo['sn'],
'mobile' => $userInfo['mobile'],
'avatar' => $avatar,
'token' => $userInfo['token'],
];
} else {
self::setError('用户不存在,请联系管理员开通供销系统账户');
return false; return false;
} }
} }
@ -265,13 +289,21 @@ class LoginLogic extends BaseLogic
$user->login_time = time(); $user->login_time = time();
$user->login_ip = request()->ip(); $user->login_ip = request()->ip();
$user->save(); $user->save();
$terminal=3;
$Android=IndexLogic::isAndroid();
if($Android){
$terminal=5;
}
$ios=IndexLogic::isIOS();
if($ios){
$terminal=6;
}
//设置token //设置token
$userInfo = UserTokenService::setToken($user->id, 1); $userInfo = UserTokenService::setToken($user->id, $terminal);
//返回登录信息 //返回登录信息
$avatar = $user->avatar ?: Config::get('project.default_image.user_avatar'); $avatar = $user->avatar ?: Config::get('project.default_image.user_avatar');
$avatar = FileService::getFileUrl($avatar); $avatar = FileService::getFileUrl($avatar);
$user_id = $jwtData['uid']; $user_id = $jwtData['uid'];
Db::name('user_other')->insert(['user_id'=>$user->id,'other_user_id'=>$user_id,'type'=>'middle']);
return [ return [
'nickname' => $userInfo['nickname'], 'nickname' => $userInfo['nickname'],
'sn' => $userInfo['sn'], 'sn' => $userInfo['sn'],