| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace mall\controllers;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\SjClass;
- use bizHd\custom\classes\CustomClass;
- use bizMall\merchant\services\MerchantExtendService;
- use bizMall\merchant\services\MerchantService;
- use bizMall\user\classes\UserClass;
- use bizMall\user\services\UserService;
- use common\components\dict;
- use common\components\httpUtil;
- use common\components\jwt;
- use common\components\util;
- use function GuzzleHttp\Promise\iter_for;
- use Yii;
- class BaseController extends PublicController
- {
- public $validate = true;
- public $guestAccess = [];
- public $userId = 0, $user, $shopId, $shop;
- public $sjId, $sj, $sjExtend, $customId = 0, $custom = [];
- public $isWx;
- public function beforeAction($action)
- {
- //定义平台类型 1花店 2供应商 3商城
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
- $shopId = Yii::$app->request->get('account', 0);
- $this->shopId = $shopId;
- if (!empty($shopId)) {
- $shop = ShopClass::getById($shopId, true);
- if (!empty($shop)) {
- $this->shop = $shop;
- $sjId = $shop->sjId ?? 0;
- $this->sjId = $sjId;
- $sj = SjClass::getById($this->sjId, true);
- if (empty($sj)) {
- util::fail('没有找到商家信息');
- }
- $this->sj = $sj;
- }
- }
- if (httpUtil::isMiniProgram()) {
- $userId = jwt::getLoginId();
- if (empty($userId)) {
- util::fail('您还没有登陆');
- }
- $this->userId = $userId;
- $user = UserClass::getById($userId, true);
- if (empty($user)) {
- util::fail('没有找到客户信息');
- }
- $this->user = $user;
- $this->isWx = util::isWx();
- if (!empty($shop)) {
- $this->sjExtend = MerchantExtendService::getBySjId($this->sjId);
- $userInfo = isset($user->attributes) ? $user->attributes : [];
- $custom = CustomClass::replaceCustom($this->sjId, $userInfo, $shopId);
- if (!empty($custom)) {
- $this->custom = $custom;
- $customId = $custom['id'] ?? 0;
- $this->customId = $customId;
- } else {
- if (in_array($action->id, $this->guestAccess) == false) {
- util::fail('没有找到客户信息哦');
- }
- }
- }
- } else {
- //非登陆情况的请求,支付宝扫码付款需要用到
- }
- return parent::beforeAction($action);
- }
- }
|