| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace ghs\controllers;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopClass;
- use biz\shop\classes\ShopExtClass;
- use biz\sj\classes\SjClass;
- use biz\sj\services\MerchantExtendService;
- use bizGhs\admin\services\AdminService;
- use bizGhs\shop\classes\MainClass;
- use common\components\dict;
- use common\components\jwt;
- use Yii;
- use common\components\util;
- class BaseController extends PublicController
- {
- public $admin, $adminId, $account;
- public $sjId = 0, $sj = [], $sjExtend = [];
- public $shop, $shopExt = [], $shopId = 0;
- public $mainId = 0, $main = [];
- public $shopAdminId = 0, $shopAdmin;
- public $appId;
- //不需要登陆的方法名
- public $guestAccess = [];
- //ssh 2020.3.8
- public function beforeAction($action)
- {
- //定义平台类型 1花店 2供货商
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'ghs');
- // $headers = Yii::$app->getRequest()->getHeaders();
- // $requestVersion = $headers->get('appVersion');
- // $currentVersion = dict::getDict('appVersion');
- // if ($requestVersion < $currentVersion) {
- // if (in_array($action->id, $this->guestAccess) == false) {
- // //util::fail('请先升级系统');
- // }
- // }
- //token验证
- $adminId = jwt::getLoginId();
- //将石少华的号模拟成别人的号进行测试,有多处需要同步修改,关键词 simulate_other ssh 20250717
- $simulateKey = 'simulate_admin_id';
- $simulateId = Yii::$app->redis->executeCommand('GET', [$simulateKey]);
- if (!empty($simulateId) && $simulateId > 0) {
- if (getenv('YII_ENV') == 'production') {
- if ($adminId == 4) {
- $adminId = $simulateId;
- }
- } else {
- if ($adminId == 919) {
- $adminId = $simulateId;
- }
- }
- }
- if (empty($adminId) && in_array($action->id, $this->guestAccess) == false) {
- util::notLogin();
- }
- $this->adminId = $adminId;
- $admin = AdminService::getById($adminId, true);
- if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
- util::logout('帐号无效');
- }
- $this->admin = $admin;
- //后台
- $currentShopId = $admin->currentGhsShopId ?? 0;
- if (empty($currentShopId)) {
- if (in_array($action->id, $this->guestAccess) == false) {
- util::fail('请注册登录');
- }
- } else {
- $this->shopId = $currentShopId;
- $shop = ShopClass::getById($currentShopId, true);
- if (empty($shop)) {
- util::fail('没有找到您的门店');
- }
- $this->shop = $shop;
- $mainId = $shop->mainId ?? 0;
- $this->mainId = $mainId;
- $main = MainClass::getById($mainId, true);
- if (empty($main)) {
- util::fail('没有main信息17,shopId:' . $this->shopId);
- }
- $this->main = $main;
- $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
- if (empty($shopExt)) {
- util::fail('门店信息有问题,请联系管理员');
- }
- $this->shopExt = $shopExt;
- $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
- if (empty($shopAdmin)) {
- util::logout('没有找到员工');
- }
- // if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) { //第95行查询时已限定 'delStatus' => 0, $shopAdmin->delStatus == 1 永远不会成立
- // util::fail('您不是本店员工哦');
- // }
- if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
- util::fail('您已被平台禁止登录');
- }
- $this->shopAdmin = $shopAdmin;
- $this->shopAdminId = $shopAdmin->id ?? 0;
- $sjId = $shop->sjId;
- $this->sjId = $sjId;
- $sj = SjClass::getById($sjId, true);
- $this->sj = $sj;
- $sjExtend = MerchantExtendService::getBySjId($sjId, true);
- $this->sjExtend = $sjExtend;
- }
- return parent::beforeAction($action);
- }
- }
|