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