| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace ghs\controllers;
- use biz\merchant\services\MerchantExtendService;
- use biz\merchant\services\MerchantService;
- use bizGhs\merchant\services\ShopService;
- use biz\wx\services\WxOpenService;
- use bizGhs\admin\services\AdminService;
- use bizGhs\shop\services\ShopAdminService;
- use common\components\jwt;
- use common\components\noticeUtil;
- use common\components\stringUtil;
- use Yii;
- use common\components\util;
- class BaseController extends PublicController
- {
- public $admin, $adminId, $adminAvatar, $account;
- public $ghsId = 0, $ghsName, $ghs, $ghsExtend, $ghsLogo, $signPackage, $shopId = 0;
- 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();
- //模拟用户
- $adminId = 1;
- $ghsId = 0;
- $ghs = [];
- $ghsExtend = [];
- $admin = [];
- if (empty($adminId)) {
- $this->validate = false;
- } else {
- $admin = AdminService::getById($adminId);
- if (empty($admin)) {
- util::fail('帐号无效');
- }
- $adminId = $admin['id'];
- //$shopId = Yii::$app->redis->executeCommand('GET', ['LOGIN_ADMIN_SHOP' . $adminId]);
- //取不到门店id可能被清缓存,需要重新登陆,$shopId = 0 则表示非管理员,没有关联的门店,只可以访问官网
- $staff = ShopAdminService::getByCondition(['adminId' => $adminId]);
- $shopId = isset($staff['shopId']) ? $staff['shopId'] : 0;
- if (is_numeric($shopId) == false) {
- util::notLogin('登陆已失效,请重新登陆');
- }
- if (!empty($shopId)) {
- $shop = ShopService::getById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店');
- }
- $ghsId = $shop['ghsId'];
- $ghs = MerchantService::getMerchantById($ghsId);
- $ghsExtend = MerchantExtendService::getByMerchantId($ghsId);
- }
- $this->shopId = $shopId;
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLogin)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin('您还没有登陆哦');
- }
- $this->admin = $admin;
- $this->adminId = $adminId;
- $this->ghsId = $ghsId;
- $this->ghs = $ghs;
- $this->ghsExtend = $ghsExtend;
- return parent::beforeAction($action);
- }
- }
|