controller->id; $actionName = $action->id; $this->menuList = MenuService::getMenu($controllerName); $this->subMenuList = MenuService::getSubMenu($controllerName, $actionName); $get = Yii::$app->request->get(); //$this->isLogin = xhAdminService::isLogin(); $this->isWeixin = util::isWeixin(); $noNeedLogin = false;//需要登陆 $account = isset($get['account']) ? $get['account'] : ''; //后台默认的输出方式是网页 Yii::$app->params['errorExportStyle'] = 'web'; Yii::$app->params['appStyle'] = 'backend'; $time = time(); $urlSession = Yii::$app->request->get('SESSIONID', ''); //通过url进行session id传输 if (empty($urlSession)) { $sessionId = Yii::$app->request->cookies->getValue("SESSIONID"); if (!empty($sessionId)) { $remainTime = Yii::$app->redis->executeCommand('TTL', [$sessionId]); //cookie过期时间不足2分钟时续期 if ($remainTime < 120) { $expireTime = 10 * 60 + $time; Yii::$app->response->cookies->add(new Cookie([ 'name' => 'SESSIONID', 'value' => $sessionId, 'domain' => $_SERVER['SERVER_NAME'], 'expire' => $expireTime ])); } $adminId = Yii::$app->redis->executeCommand('GET', [$sessionId]); if (!empty($adminId)) { $this->isLogin = true; } } } //绑定错误提示 $this->error = error::instance(); $merchant = []; if ($this->isLogin == true) { //$adminId = xhAdminService::getId(); $admin = xhAdminService::getById($adminId); $noNeedLogin = true; if (!empty($admin) && isset($admin['openId'])) { $largeImg = $admin['avatar']; $this->adminId = $adminId; $this->admin = $admin; $this->adminAvatar = xhAdminService::getAvatarList($largeImg); $relation = xhAdminToMerchantService::getByAdminId($adminId); if (!empty($relation)) { $merchantId = $relation['merchantId']; $merchant = xhMerchantService::getById($merchantId); } else { //不是创建管理员过程,有非管理员想登陆后台 if ($action->controller->id != 'admin' && $action->id != 'generate') { $noNeedLogin = false; xhAdminService::logout(); util::stop('确认您已经加入花卉宝?请与管理员联系'); } } } else { if ($action->controller->id != 'admin' && $action->id != 'generate') { $noNeedLogin = false; xhAdminService::logout(); util::stop('确认您已经加入花卉宝?请与管理员联系…'); } else { xhAdminService::logout(); $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $this->redirect($url); util::end(); } } if (!empty($merchant)) { $merchantId = $merchant['id']; $this->merchantId = $merchantId; $this->merchant = $merchant; $this->merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId); $this->merchantAsset = xhMerchantAssetService::getByMerchantId($merchantId); $this->merchantName = $this->merchant['merchantName']; $this->merchantLogo = $this->merchant['logo']; $this->appId = $this->merchant['wxAppId']; } } if (!empty($account)) { $merchant = xhMerchantService::getByAccount($account); if (!empty($merchant)) { $merchantId = $merchant['id']; $this->merchant = $merchant; $this->merchantId = $merchantId; $this->merchantExtend = xhMerchantExtendService::getByMerchantId($merchantId); $this->merchantAsset = xhMerchantAssetService::getByMerchantId($merchantId); $this->merchantName = $this->merchant['merchantName']; $this->merchantLogo = $this->merchant['logo']; $this->appId = $this->merchant['wxAppId']; } } if (!in_array($action->id, $this->withoutLogin) && $this->isLogin == false) { $this->redirect(['main/login']); util::end(); } Yii::$app->params['merchantId'] = $this->merchantId; Yii::$app->params['merchant'] = $this->merchant; $this->ourself = ['uid' => $this->merchantId, 'userName' => $this->merchant['merchantName'], 'avatar' => $this->merchant['logo'], 'role' => 'merchant']; $this->usageList = UsageRelationService::getMyUsage(); $this->categoryList = CategoryRelateService::getCategoryData(); return parent::beforeAction($action); } /** * 商户数据权限检测 */ protected function merchantCheck($data, $msg = '') { if (empty($data)) { $this->error(); } if ($data['merchantId'] != $this->merchantId) { $url = \yii\helpers\Url::to(['error/error-page']) . "?statusCode=illegalMerchantId"; $this->redirect($url); Yii::$app->end(); } return true; } /** * 后台友好错误提示页 * @param string $errorType 错误类型(从configDict中取,或从备置文件config中) */ protected function error($errorType = 'illegalData') { $url = \yii\helpers\Url::to(['error/error-page']) . "?statusCode=" . $errorType; $this->redirect($url); Yii::$app->end(); } //参数验证方法 shish 2019.8.19 public function validate($valid, $data) { return validate::check($valid, $data); } //方法里错误输出设置为json shish 2019.8.21 public function errorExportJson() { Yii::$app->params['errorExportStyle'] = 'json'; } }