| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace mall\controllers;
- use biz\shop\classes\ShopClass;
- use bizHd\custom\classes\CustomClass;
- use bizMall\hd\classes\HdClass;
- use bizMall\shop\classes\MainClass;
- use bizMall\user\classes\UserClass;
- use common\components\dict;
- use common\components\jwt;
- use common\components\util;
- use Yii;
- class BaseController extends PublicController
- {
- public $validate = true;
- public $guestAccess = [];
- public $userId = 0, $user, $shopId, $shop;
- public $sjId, $sj, $sjExtend, $customId = 0, $custom, $hd, $hdId, $mainId = 0, $main;
- public $isWx;
- public function beforeAction($action)
- {
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
- $this->isWx = util::isWx();
- $userId = jwt::getLoginId();
- if (empty($userId)) {
- if (!in_array($action->id, $this->guestAccess)) {
- util::fail('请先登录哈');
- }
- }
- $userId = intval($userId);
- $this->userId = $userId;
- $user = UserClass::getById($userId, true);
- if (empty($user)) {
- if (!in_array($action->id, $this->guestAccess)) {
- util::fail('请先登录呢');
- }
- }
- $this->user = $user;
- $shopId = Yii::$app->request->get('account'); // 从 $_GET 中取
- $shopId = empty($shopId) ? Yii::$app->request->post('account') : $shopId; // 从 $_POST 中取
- $shopId = intval($shopId);
- if (!empty($shopId)) {
- $this->shopId = $shopId;
- $shop = ShopClass::getById($shopId, true);
- if (!empty($shop)) {
- $this->shop = $shop;
- $mainId = $shop->mainId ?? 0;
- $main = MainClass::getById($mainId, true);
- $this->main = $main;
- $this->mainId = $mainId;
- $hdId = Yii::$app->request->get('hdId', 0);
- if (empty($hdId)) {
- //兼容早期代码,勿删,扫码付款页也用到,只写POST方式
- $hdId = Yii::$app->request->post('hdId', 0);
- }
- if (!empty($hdId)) {
- $hd = HdClass::getById($hdId, true);
- if (!empty($hd)) {
- if (!empty($this->userId) && $hd->userId == $this->userId && $shopId == $hd->shopId) {
- $this->hd = $hd;
- $this->hdId = $hdId;
- $customId = $hd->customId ?? 0;
- $custom = CustomClass::getById($customId, true);
- $this->custom = $custom;
- $this->customId = $customId;
- }
- }
- }
- }
- }
- return parent::beforeAction($action);
- }
- }
|