| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?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, $adminAvatar, $account;
- public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shop, $shopExt = [], $shopId = 0, $mainId = 0, $main = [], $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'] = 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();
- if (getenv('YII_ENV', 'local') == 'local') {
- //$adminId = 730;
- }
- 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) {
- 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);
- }
- }
|