| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace shop\controllers;
- use biz\admin\services\AdminRelateService;
- use biz\merchant\services\AdminService;
- use biz\merchant\services\MerchantExtendService;
- use biz\merchant\services\MerchantService;
- use common\components\jwt;
- use Yii;
- use common\components\util;
- class BaseController extends PublicController
- {
- public $admin, $adminId, $adminAvatar, $account;
- public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantLogo, $signPackage;
- public $openMerchant, $openMerchantId;
- public $appId;
- public $isWx = false;
- public $isLogin = false;
- public $withoutLogin = [];//不需要登陆的方法名
- public $validate = true;
- //shish 2020.3.8
- public function beforeAction($action)
- {
- //token验证
- $adminId = jwt::getLoginId();
- $merchantId = 0;
- $merchant = [];
- $merchantExtend = [];
- $admin = [];
- if (empty($adminId)) {
- $this->validate = false;
- } else {
- $admin = AdminService::getById($adminId);
- if (empty($admin)) {
- util::fail('帐号无效');
- }
- $adminId = $admin['id'];
- $relateId = Yii::$app->redis->executeCommand('GET', ['ADMIN_RELATION_' . $adminId]);
- //缓存取得的不是数字可能被清缓存,需要重新登陆,$relateId = 0 则表示没有关联的商家
- if (is_numeric($relateId) == false) {
- util::notLogin('请重新进行登陆');
- }
- if (!empty($relateId)) {
- $relate = AdminRelateService::getById($relateId);
- $merchantId = $relate['merchantId'];
- $merchant = MerchantService::getMerchantById($merchantId);
- $merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
- }
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLogin)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin('您还没有登陆哦');
- }
- $this->admin = $admin;
- $this->adminId = $adminId;
- $this->merchantId = $merchantId;
- $this->merchant = $merchant;
- $this->merchantExtend = $merchantExtend;
- return parent::beforeAction($action);
- }
- }
|