| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace hd\controllers;
- use biz\sj\classes\SjClass;
- use bizHd\admin\classes\AdminClass;
- use biz\shop\classes\ShopAdminClass;
- use biz\sj\classes\MerchantExtendClass;
- use bizHd\merchant\services\ShopService;
- use bizHd\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, $customId = 0, $custom;
- public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $main, $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) && in_array($action->id, $this->guestAccess) == false) {
- util::notLogin();
- }
- $admin = AdminClass::getById($adminId, true);
- if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
- util::notLogin();
- }
- $adminId = $admin->id ?? 0;
- $this->admin = $admin;
- $this->adminId = $adminId;
- //后台
- $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);
- 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信息');
- }
- $this->main = $main;
- $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
- if (empty($shopAdmin)) {
- util::logout('没有找到员工信息');
- }
- if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
- util::fail('您不是本店员工哦');
- }
- if (isset($shopAdmin->status) == false || $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;
- }
- $this->formParams();
- return parent::beforeAction($action);
- }
- /**
- * 把必要参数放 $_POST 或 $_GET 中
- */
- private function formParams()
- {
- // 将参数放入 $_POST 中(如果是 POST 请求)
- if (Yii::$app->request->isPost) {
- $_POST['adminId'] = intval($this->adminId);
- $_POST['mainId'] = intval($this->mainId);
- $_POST['shopId'] = intval($this->shopId);
- }
-
- // 将参数放入 $_GET 中(如果是 GET 请求)
- if (Yii::$app->request->isGet) {
- $_GET['adminId'] = intval($this->adminId);
- $_GET['mainId'] = intval($this->mainId);
- $_GET['shopId'] = intval($this->shopId);
- }
- }
- }
|