| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace shop\controllers;
- use biz\admin\classes\AdminClass;
- use biz\admin\services\ShopAdminService;
- use biz\custom\classes\CustomClass;
- use biz\merchant\classes\MerchantExtendClass;
- use biz\merchant\classes\ShopClass;
- use biz\merchant\services\AdminService;
- use biz\merchant\services\MerchantExtendService;
- use biz\merchant\services\MerchantService;
- use biz\merchant\services\ShopService;
- use biz\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, $custom;
- public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0;
- public $appId;
- public $isWx = false;
- public $isLogin = false;
- //不需要登陆的方法名
- public $withoutLoginAction = [];
- //需求带account请求头才能访问的方法
- public $needShopIdAction = [];
- public $validate = true;
- //shish 2020.3.8
- public function beforeAction($action)
- {
- //token验证
- //$adminId = jwt::getLoginId();
- $adminId = 18569;
- $admin = AdminClass::getAdminById($adminId, true);
- if (empty($admin)) {
- util::fail('帐号无效');
- }
- $adminId = $admin['id'];
- $header = httpUtil::getHeader();
- $shopId = $header['shop-id'] ?? 0;
- if (!empty($shopId)) {
- $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 {
- if (in_array($action->id, $this->needShopIdAction)) {
- util::fail('您正在访问店铺,但没有找到店铺id');
- }
- $shopId = $admin['currentShopId'] ?? 0;
- if (!empty($shopId)) {
- $shop = ShopService::getById($shopId);
- $sjId = $shop['merchantId'];
- $sj = MerchantService::getMerchantById($sjId);
- $this->sj = $sj;
- $this->shopId = $shopId;
- $this->sjId = $sjId;
- $this->sjExtend = MerchantExtendClass::getByMerchantId($sjId);
- }
- }
- $this->admin = $admin;
- $this->adminId = $adminId;
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLoginAction)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- return parent::beforeAction($action);
- }
- }
|