| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace hd\controllers;
- use biz\admin\classes\AdminClass as ClassesAdminClass;
- use biz\sj\classes\SjClass;
- use bizHd\admin\classes\AdminClass;
- use biz\shop\classes\ShopAdminClass;
- use biz\sj\classes\MerchantExtendClass;
- use biz\sj\services\MerchantService;
- use bizHd\merchant\services\ShopService;
- use common\components\dict;
- 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, $shop = [], $shopAdminId = 0, $shopAdmin = [];
- public $appId;
- public $isWx = false;
- public $isLogin = false;
- //游客可以访问的方法
- public $guestAccess = [];
- //ssh 2020.3.8
- public function beforeAction($action)
- {
- //定义平台类型 1花店 2供应商 3商城
- Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd');
- //token验证
- $adminId = jwt::getLoginId();
- if (getenv('YII_ENV', 'local') != 'production') {
- //$adminId = 253;
- }
- if (empty($adminId)) {
- util::notLogin();
- }
- $admin = AdminClass::getById($adminId, true);
- if (empty($admin)) {
- util::notLogin();
- }
- $adminId = $admin->id;
- $this->admin = $admin;
- $this->adminId = $adminId;
- // 只能供应商访问
- if ($admin->style != ClassesAdminClass::STYLE_HD) {
- util::fail('您没有权限访问哦!');
- }
- //后台
- $currentShopId = $admin->currentShopId ?? 0;
- if (empty($currentShopId)) {
- if (in_array($action->id, $this->guestAccess) == false) {
- util::fail('您不是员工没有权限访问');
- }
- } else {
- $this->shopId = $currentShopId;
- $shop = ShopService::getById($currentShopId, true);
- $this->shop = $shop;
- if (empty($shop)) {
- util::fail('没有找到店铺');
- }
- $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], 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 = MerchantExtendClass::getBySjId($sjId, true);
- $this->sjExtend = $sjExtend;
- }
- return parent::beforeAction($action);
- }
- }
|