| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- <?php
- namespace pt\controllers;
- use bizHd\saas\services\StaffService;
- use common\components\jwt;
- use common\components\util;
- use Yii;
- class BaseController extends PublicController
- {
- public $staff, $staffId, $userId, $user;
- public $isLogin = false;
- public $guestAccessAction = [];//不需要登陆的方法名
- public $validate = true;
- public function beforeAction($action)
- {
- //6表示总后台
- Yii::$app->params['ptStyle'] = 6;
- $staffId = jwt::getLoginId();
- if (empty($staffId)) {
- $this->validate = false;
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->guestAccessAction)) {
- $this->validate = true;
- } else {
- $staff = StaffService::getById($staffId);
- if (empty($staff)) {
- util::fail('没有找到管理员');
- }
- $this->staff = $staff;
- $this->user = $staff;
- }
- if ($this->validate == false) {
- util::notLogin();
- }
- $this->staffId = $staffId;
- return parent::beforeAction($action);
- }
- }
|