| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace www\controllers;
- use biz\merchant\services\MerchantService;
- use biz\saas\services\StaffService;
- use biz\user\services\UserService;
- use biz\weixin\services\WxOpenService;
- use common\components\jwt;
- use common\components\util;
- use Yii;
- use yii\web\Controller;
- /**
- * 平台次级基类,次于PublicController
- */
- class BaseController extends PublicController
- {
- public $staff, $staffId, $userId, $user, $merchantId, $merchant;
- public $isLogin = false;
- public $withoutLogin = [];//不需要登陆的方法名
- public $validate = true;
- public $wxOpenId = 1;
- public $wxOpen;
- public function beforeAction($action)
- {
- //token验证
- $staffId = jwt::getLoginId();
- $userId = $staffId;
- if (empty($staffId)) {
- $this->validate = false;
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->withoutLogin)) {
- $this->validate = true;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- if (!empty($userId)) {
- $staff = UserService::getUserInfo($userId);
- $this->staff = $staff;
- $this->user = $staff;
- }
- $this->staffId = $staffId;
- $this->userId = $userId;
- $open = WxOpenService::getById($this->wxOpenId);
- $this->wxOpen = $open;
- $merchantId = isset($open['merchantId']) ? $open['merchantId'] : 0;
- $this->merchantId = $merchantId;
- if (!empty($merchantId)) {
- $this->merchant = MerchantService::getById($merchantId);
- }
- return parent::beforeAction($action);
- }
- }
|