'', 'isfounder' => false]; /** * Handle an incoming request. * * @param $request * @param Closure $next * * @return mixed */ public function handle($request, Closure $next) { global $_W; $check = $this->checkUserInfo(); $uri = \Route::getCurrentRoute()->Uri(); $uniacid = \YunShop::app()->uniacid; \YunShop::app()->uid = \Auth::guard('admin')->user()->uid; \YunShop::app()->username = \Auth::guard('admin')->user()->username; $_W['uid'] = \Auth::guard('admin')->user()->uid; $_W['username'] = \Auth::guard('admin')->user()->username; if (!$check['result']) { return $this->errorJson($check['msg'], ['status' => self::USER_STATUS]); } if (\Auth::guard('admin')->user()->uid == 1) { \YunShop::app()->role = 'founder'; \YunShop::app()->isfounder = true; $this->role = ['role' => 'founder', 'isfounder' => true]; } else { if (!in_array($uri, $this->authApi)) { return $this->errorJson('无访问权限', ['status' => self::API_STATUS]); } if (!empty($uniacid)) { $this->uniacid = $uniacid; $this->account = AppUser::getAccount(\Auth::guard('admin')->user()->uid, $uniacid); if (!is_null($this->account)) { $this->setRole(); } else { $this->relogin(); } } } return $next($request); } /** * 获取用户身份 * * @return array */ private function setRole() { if (\Auth::guard('admin')->user()->uid === 1) { \YunShop::app()->role = 'founder'; \YunShop::app()->isfounder = true; $this->role = ['role' => 'founder', 'isfounder' => true]; } else { \YunShop::app()->role = $this->account->role; \YunShop::app()->isfounder = false; $this->role = ['role' => $this->account->role, 'isfounder' => false]; } } /** * 验证访问权限 * * @return \Illuminate\Http\JsonResponse */ private function relogin() { \Auth::guard('admin')->logout(); request()->session()->flush(); request()->session()->regenerate(); Utils::removeUniacid(); return $this->errorJson('用户不存在,请重新登录', ['login_status' => 1, 'login_url' => '/#/login']); } /** * 检测用户信息 * * @return array */ private function checkUserInfo() { $user = \Auth::guard('admin')->user(); $result = 1; if ($user->status == 3) { $result = 0; $msg = '您已被禁用,请联系管理员'; } if ($user->endtime != 0 && $user->endtime <= time()) { $result = 0; $msg = '您的账号已过期,请联系管理员'; } return [ 'result' => $result, 'msg' => $msg ]; } /** * 获取错误信息 * * @return mixed */ private function errorMsg() { if (\Cache::has('app.access')) { $msg = \Cache::get('app.access'); \Cache::forget('app.access'); Utils::removeUniacid(); return $msg; } } }