admin = Session::get('jjjshop_admin'); // 当前路由信息 $this->getRouteinfo(); // 验证登录 $this->checkLogin(); } /** * 解析当前路由参数 (分组名称、控制器名称、方法名) */ protected function getRouteinfo() { // 控制器名称 $this->controller = toUnderScore(Request()->controller()); // 方法名称 $this->action = Request()->action(); // 控制器分组 (用于定义所属模块) $groupstr = strstr($this->controller, '.', true); $this->group = $groupstr !== false ? $groupstr : $this->controller; // 当前uri $this->routeUri = $this->controller . '/' . $this->action; } /** * 验证登录状态 */ private function checkLogin() { // 验证当前请求是否在白名单 if (in_array($this->routeUri, $this->allowAllAction)) { return true; } // 验证登录状态 if (!empty($this->admin) || $this->admin['is_login'] == 1) { return true; } throw new BaseException(['code' => -1, 'msg' => 'not_login']); return false; } }