| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace mall\controllers;
- use biz\shop\classes\ShopClass;
- use bizHd\custom\classes\CustomClass;
- 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 $guestAccessAction = [];
- public $userId = 0, $user, $shopId;
- public $sjId, $sj, $sjExtend, $customId = 0;
- public $isWx;
- public function beforeAction($action)
- {
- $userId = jwt::getLoginId();
- $header = httpUtil::getHeader();
- $shopId = isset($header['account']) ? $header['account'] : 0;
- if (empty($shopId)) {
- util::fail('没有找到门店');
- }
- $shop = ShopClass::getById($shopId);
- if (empty($shop)) {
- util::fail('没有找到门店哦');
- }
- $sjId = $shop['merchantId'] ?? 0;
- if (empty($sjId)) {
- util::fail('没有找到商家哦');
- }
- $sj = MerchantService::getMerchantById($sjId);
- if (empty($sj)) {
- util::fail('没有找到商家');
- }
- $this->sjId = $sjId;
- $this->sj = $sj;
- $this->shopId = $shopId;
- $this->sjExtend = MerchantExtendService::getByMerchantId($sjId);
- $this->isWx = util::isWx();
- if (empty($userId)) {
- $this->validate = false;
- } else {
- $this->validate = true;
- $this->userId = $userId;
- $userInfo = UserService::getUserInfo($userId);
- if (empty($userInfo)) {
- util::fail('没有用户信息');
- }
- $this->user = $userInfo;
- $customId = CustomClass::getCurrentCustomId($sjId, $userInfo);
- $this->customId = $customId;
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->guestAccessAction)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- return parent::beforeAction($action);
- }
- }
|