| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- namespace ghs\controllers;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\MerchantExtendClass;
- use biz\sj\services\MerchantExtendService;
- use biz\sj\services\MerchantService;
- use bizGhs\merchant\services\ShopService;
- use bizHd\wx\services\WxOpenService;
- use bizGhs\admin\services\AdminService;
- use bizGhs\shop\services\ShopAdminService;
- use common\components\httpUtil;
- use common\components\jwt;
- use common\components\noticeUtil;
- use common\components\stringUtil;
- use Yii;
- use common\components\util;
- class BaseController extends PublicController
- {
- public $admin, $adminId, $adminAvatar, $account;
- public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop = [], $shopId = 0, $lookShopId = 0, $shopAdminId = 0, $shopAdmin = [];
- public $appId;
- public $isWx = false;
- public $isLogin = false;
- public $guestAccess = [];//不需要登陆的方法名
- //ssh 2020.3.8
- public function beforeAction($action)
- {
- //定义平台类型 1花店 2供货商
- Yii::$app->params['ptStyle'] = 2;
- //token验证
- $adminId = jwt::getLoginId();
- //$adminId = 18;
- if (empty($adminId)) {
- util::notLogin();
- }
- $this->adminId = $adminId;
- $admin = AdminService::getById($adminId);
- if (empty($admin)) {
- util::fail('帐号无效');
- }
- $this->admin = $admin;
- $header = httpUtil::getHeader();
- $lookShopId = $header['shop-id'] ?? 0;
- if (!empty($lookShopId)) {
- //商城和下单页
- if (in_array($action->id, $this->guestAccess) == false) {
- util::fail('您没有权限访问哦~');
- }
- $shop = ShopClass::getById($lookShopId);
- if (empty($shop)) {
- util::fail('没有找到店铺');
- }
- $this->lookShopId = $lookShopId;
- $sjId = $shop['merchantId'] ?? 0;
- $sj = MerchantService::getMerchantById($sjId);
- $sjExtend = MerchantExtendClass::getByMerchantId($sjId);
- $this->sj = $sj;
- $this->sjExtend = $sjExtend;
- } else {
- //后台
- $currentShopId = $admin['currentShopId'] ?? 0;
- if(empty($currentShopId)){
- if( in_array($action->id, $this->guestAccess) == false){
- util::fail('您没有权限访问哦!');
- }
- }else{
- $this->shopId = $currentShopId;
- $shop = ShopClass::getShopInfo($currentShopId);
- $this->shop = $shop;
- 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 = MerchantExtendService::getByMerchantId($sjId);
- $this->sjExtend = $sjExtend;
- }
- }
- return parent::beforeAction($action);
- }
- }
|