|
|
@@ -5,6 +5,7 @@ namespace mall\controllers;
|
|
|
use biz\shop\classes\ShopClass;
|
|
|
use biz\sj\classes\SjClass;
|
|
|
use bizHd\custom\classes\CustomClass;
|
|
|
+use bizMall\hd\classes\HdClass;
|
|
|
use bizMall\merchant\services\MerchantExtendService;
|
|
|
use bizMall\merchant\services\MerchantService;
|
|
|
use bizMall\shop\classes\MainClass;
|
|
|
@@ -22,42 +23,58 @@ class BaseController extends PublicController
|
|
|
|
|
|
public $validate = true;
|
|
|
public $guestAccess = [];
|
|
|
- public $userId = 0, $user = null, $shopId, $shop;
|
|
|
- public $sjId, $sj, $sjExtend, $customId = 0, $custom = [], $mainId = 0, $main = [];
|
|
|
+ public $userId = 0, $user, $shopId, $shop;
|
|
|
+ public $sjId, $sj, $sjExtend, $customId = 0, $custom, $hd, $mainId = 0, $main;
|
|
|
public $isWx;
|
|
|
|
|
|
public function beforeAction($action)
|
|
|
{
|
|
|
Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'mall');
|
|
|
$this->isWx = util::isWx();
|
|
|
- $shopId = Yii::$app->request->get('account', 0);
|
|
|
- $this->shopId = $shopId;
|
|
|
- if (!empty($shopId)) {
|
|
|
- $shop = ShopClass::getById($shopId, true);
|
|
|
- if (!empty($shop)) {
|
|
|
- $mainId = $shop->mainId ?? 0;
|
|
|
- $main = MainClass::getById($mainId, true);
|
|
|
- $this->main = $main;
|
|
|
- $this->mainId = $mainId;
|
|
|
- $this->shop = $shop;
|
|
|
- $sjId = $shop->sjId ?? 0;
|
|
|
- $this->sjId = $sjId;
|
|
|
- $sj = SjClass::getById($this->sjId, true);
|
|
|
- if (empty($sj)) {
|
|
|
- util::fail('没有商家信息');
|
|
|
- }
|
|
|
- $this->sj = $sj;
|
|
|
- $this->sjExtend = MerchantExtendService::getBySjId($this->sjId);
|
|
|
- }
|
|
|
- }
|
|
|
$userId = jwt::getLoginId();
|
|
|
if (!empty($userId)) {
|
|
|
$this->userId = $userId;
|
|
|
$user = UserClass::getById($userId, true);
|
|
|
- if (!empty($user)) {
|
|
|
- $this->user = $user;
|
|
|
+ if (empty($user)) {
|
|
|
+ if (!in_array($action->id, $this->guestAccess)){
|
|
|
+ util::fail('请先登录');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->user = $user;
|
|
|
+ $shopId = Yii::$app->request->get('account', 0);
|
|
|
+ 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);
|
|
|
+ $hd = HdClass::getById($hdId, true);
|
|
|
+ if (!empty($hd)) {
|
|
|
+ if ($hd->userId != $this->userId) {
|
|
|
+ util::fail('不是你的花店,无法访问哦');
|
|
|
+ }
|
|
|
+ if ($shopId != $hd->shopId) {
|
|
|
+ util::fail('花店信息有问题哦');
|
|
|
+ }
|
|
|
+ $this->hd = $hd;
|
|
|
+ $customId = $hd->customId ?? 0;
|
|
|
+ $custom = CustomClass::getById($customId, true);
|
|
|
+ $this->custom = $custom;
|
|
|
+ } else {
|
|
|
+ $respond = CustomClass::buildRelation($shop, $user);
|
|
|
+ $hd = $respond['hd'];
|
|
|
+ $custom = $respond['custom'];
|
|
|
+ $this->hd = $hd;
|
|
|
+ $this->custom = $custom;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return parent::beforeAction($action);
|
|
|
}
|
|
|
|