| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace hd\controllers;
- use bizHd\admin\classes\AdminClass;
- use bizHd\admin\services\ShopAdminService;
- use bizHd\custom\classes\CustomClass;
- use biz\shop\classes\ShopAdminClass;
- use biz\sj\classes\MerchantExtendClass;
- use bizHd\merchant\classes\ShopClass;
- use bizHd\merchant\services\AdminService;
- use biz\sj\services\MerchantExtendService;
- use biz\sj\services\MerchantService;
- use bizHd\merchant\services\ShopService;
- use bizHd\wx\services\WxOpenService;
- use common\components\httpUtil;
- use common\components\jwt;
- use Yii;
- use common\components\util;
- class BaseController extends PublicController
- {
-
- public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
- public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $shopAdminId = 0, $shopAdmin = [];
- public $appId;
- public $isWx = false;
- public $isLogin = false;
- //游客可以访问的方法
- public $guestAccessAction = [];
-
- //shish 2020.3.8
- public function beforeAction($action)
- {
- //token验证
- $adminId = jwt::getLoginId();
- if (empty($adminId)) {
- util::notLogin();
- }
- $sjId = 0;
- $sj = [];
- $sjExtend = [];
- $currentShopId = 0;
- $admin = AdminClass::getAdminById($adminId, true);
- if (empty($admin)) {
- util::notLogin();
- }
- $adminId = $admin['id'];
- $this->admin = $admin;
- $this->adminId = $adminId;
- $header = httpUtil::getHeader();
- $shopId = $header['shop-id'] ?? 0;
-
- if (!empty($shopId)) {
- //商城
- if (in_array($action->id, $this->guestAccessAction) == false) {
- util::fail('您没有权限访问哦');
- }
- $shop = ShopClass::getById($shopId);
- if (empty($shop)) {
- util::fail('没有找到店铺');
- }
- $sjId = $shop['merchantId'] ?? 0;
- $custom = CustomClass::getCustom(['sjId' => $sjId, 'adminId' => $adminId]);
- $customId = $custom['id'] ?? 0;
- if (empty($customId)) {
- util::fail('没有找到客户信息');
- }
- $this->custom = $custom;
- $this->customId = $customId;
- $this->sjId = $sjId;
- $sj = MerchantService::getMerchantById($sjId);
- $this->sj = $sj;
- $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
- } else {
- //后台
- $currentShopId = $admin['currentShopId'] ?? 0;
- if (empty($currentShopId) && in_array($action->id, $this->guestAccessAction) == false) {
- util::fail('您没有权限访问哦~');
- }
- $this->shopId = $currentShopId;
- $shop = ShopService::getById($currentShopId);
- if (empty($shop)) {
- util::fail('没有找到店铺');
- }
- $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0]);
- if (empty($shopAdmin)) {
- util::fail('没有找到员工信息');
- }
- $this->shopAdmin = $shopAdmin;
- $this->shopAdminId = $shopAdmin['id'] ?? 0;
- $sjId = $shop['merchantId'];
- $this->sjId = $sjId;
- $sj = MerchantService::getMerchantById($sjId);
- $this->sj = $sj;
- $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
- $this->sjExtend = $sjExtend;
- }
- return parent::beforeAction($action);
- }
-
- }
|