| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace client\controllers;
- use biz\stat\services\StatVisitService;
- use Yii;
- use biz\merchant\services\MerchantExtendService;
- use biz\merchant\services\MerchantService;
- use biz\user\services\UserService;
- use common\components\httpUtil;
- use common\components\jwt;
- use common\components\util;
- /**
- * Created by PhpStorm.
- * User: shish <shish@zhhinc.com>
- * Date: 2019/11/18 0018
- * Time: 14:58
- */
- class BaseController extends PublicController
- {
-
- public $validate = true;
- public $withoutLogin = [];//不需要登陆可以访问的方法
- public $userId = 0, $user, $shopId;
- public $merchantId, $merchant, $merchantExtend;
- public $isWx;
-
- public function beforeAction($action)
- {
- //token验证
- $userId = jwt::getLoginId();
- $header = httpUtil::getHeader();
- $account = isset($header['account']) ? $header['account'] : 0;
- $shopId = isset($header['shopId']) ? $header['shopId'] : 0;
- if (empty($account)) {
- util::fail('商家无效');
- }
- $merchant = MerchantService::getMerchantById($account);
- if (empty($merchant)) {
- util::fail('商家信息无效');
- }
- $this->merchantId = $account;
- $this->merchant = $merchant;
- $this->shopId = $shopId;
- $this->merchantExtend = MerchantExtendService::getByMerchantId($account);
- $this->isWx = util::isWx();
-
- //收集访问量
- StatVisitService::gatherVisit($account);
-
- if (empty($userId)) {
- $this->validate = false;
- } else {
- $this->validate = true;
- $this->userId = $userId;
- $userInfo = UserService::getUserInfo($userId);
- $this->user = $userInfo;
- //客户短时间访问二家商家的商城,登陆信息一致性问题
- if ($userInfo['merchantId'] != $account) {
- util::logout();
- }
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLogin)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- return parent::beforeAction($action);
- }
-
- }
|