| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace mall\controllers;
- use bizMall\merchant\services\MerchantExtendService;
- use bizMall\merchant\services\MerchantService;
- use bizMall\user\services\UserService;
- use common\components\httpUtil;
- use common\components\jwt;
- use common\components\util;
- 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();
- $merchantId = isset($header['account']) ? $header['account'] : 0;
- $shopId = isset($header['shopId']) ? $header['shopId'] : 0;
- if (empty($merchantId)) {
- util::fail('商家无效');
- }
- $merchant = MerchantService::getMerchantById($merchantId);
- if (empty($merchant)) {
- util::fail('商家信息无效');
- }
- $this->merchantId = $merchantId;
- $this->merchant = $merchant;
- $this->shopId = $shopId;
- $this->merchantExtend = MerchantExtendService::getByMerchantId($merchantId);
- $this->isWx = util::isWx();
- if (empty($userId)) {
- $this->validate = false;
- } else {
- $this->validate = true;
- $this->userId = $userId;
- $userInfo = UserService::getUserInfo($userId);
- $this->user = $userInfo;
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLogin)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- return parent::beforeAction($action);
- }
- }
|