diff --git a/app/api/logic/LoginLogic.php b/app/api/logic/LoginLogic.php index c00d900d4..e8962e93c 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('用户不存在,请联系管理员开通供销系统账户'); + 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('用户不存在,请联系管理员开通供销系统账户'); 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'], diff --git a/app/middleapi/controller/UserController.php b/app/middleapi/controller/UserController.php index 5c1395aee..58c4fd0c7 100644 --- a/app/middleapi/controller/UserController.php +++ b/app/middleapi/controller/UserController.php @@ -4,6 +4,7 @@ namespace app\middleapi\controller; use app\common\enum\user\AccountLogEnum; use app\common\model\user\User; +use app\common\model\user\UserRole; use app\common\enum\user\UserTerminalEnum; use think\facade\Db; use app\common\controller\BaseLikeAdminController; @@ -61,4 +62,28 @@ class UserController extends BaseLikeAdminController return $this->success('请求成功',$result); } + public function roleLists() + { + if(!$this->request->isPost()){ + return $this->fail('请求方式错误'); + } + $params = $this->request->post(['page_no','page_size']); + $pageNo = !empty($params['page_no']) ? $params['page_no'] : 1; + $pageSize = !empty($params['page_size']) ? $params['page_size'] : 20; + $lists = UserRole::field(['id', 'name', 'desc', 'menu_arr', 'sort']) + ->page($pageNo, $pageSize) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + + $count = UserRole::count(); + $result = [ + 'lists' => $lists, + 'count' => $count, + 'page_no' => $pageNo, + 'page_size' => $pageSize + ]; + return $this->success('请求成功',$result); + } + } \ No newline at end of file