| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace admin\controllers;
- use biz\admin\services\AdminToMerchantService;
- use biz\auth\services\MenuService;
- use biz\goods\services\CategoryRelateService;
- use biz\goods\services\UsageRelationService;
- use biz\merchant\services\AdminService;
- use biz\merchant\services\MerchantService;
- use common\components\error;
- use common\components\jwt;
- use common\components\stringUtil;
- use common\components\validate;
- use common\services\xhUserService;
- use Yii;
- use common\services\xhWxOpenService;
- use common\services\xhMerchantAssetService;
- use common\services\xhMerchantExtendService;
- use common\services\xhMerchantService;
- use common\services\xhAdminService;
- use common\components\util;
- use common\components\weixinUtil;
- use common\components\jsSDK;
- use common\services\xhAdminToMerchantService;
- use yii\web\Cookie;
- class BaseController extends PublicController
- {
- public $admin, $adminId, $adminAvatar, $account;
- public $merchantId = 0, $merchantName, $merchant, $merchantExtend, $merchantAsset, $merchantLogo, $signPackage;
- public $openMerchant, $openMerchantId;
- public $appId;
- public $isWeixin = false;
- public $isLogin = false;
- public $withoutLogin = [];//不需要登陆的方法名
- public $validate = true;
-
- public function beforeAction($action)
- {
- //token验证
- $adminId = jwt::getLoginId();
- if (empty($adminId)) {
- $this->validate = false;
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLogin)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- $admin = AdminService::getById($adminId);
- if (empty($admin)) {
- util::fail('没有找到管理员');
- }
- $merchantId = AdminToMerchantService::getDefaultMerchant($adminId);
- if (empty($merchantId)) {
- util::fail('没有找到商家信息');
- }
- $merchant = MerchantService::getById($merchantId);
- Yii::$app->params['adminId'] = $adminId;
- Yii::$app->params['admin'] = $admin;
- Yii::$app->params['merchantId'] = $merchantId;
- Yii::$app->params['merchant'] = $merchant;
- $this->adminId = $adminId;
- $this->merchantId = $merchantId;
- return parent::beforeAction($action);
- }
-
- }
|