| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace pt\controllers;
- use bizHd\saas\services\StaffService;
- use common\components\jwt;
- use common\components\util;
- use Faker\Provider\bn_BD\Utils;
- use Yii;
- class BaseController extends PublicController
- {
- public $staff, $staffId;
- public $isLogin = false;
- public $guestAccess = [];//不需要登陆的方法名
- public $validate = true;
- public function beforeAction($action)
- {
- //6表示总后台
- Yii::$app->params['ptStyle'] = 6;
- $staffId = jwt::getLoginId();
- if (empty($staffId)) {
- $this->validate = false;
- }
- //临时开放花材管理权限给商家
- $limitId = 4;
- if (getenv('YII_ENV') == 'production') {
- $limitId = 2;
- }
- if ($staffId == $limitId) {
- $currentRoute = $this->id . '/' . $action->id;
- $arr = [
- 'staff/login-detail',
- 'item/list',
- 'item-class/list',
- 'item-class/get-all-class',
- 'unit/get-all-unit',
- 'upload/save-img',
- 'item/add',
- ];
- if (!in_array($currentRoute, $arr)) {
- util::fail('没有找到资源');
- }
- }
- //游客可以访问的方法
- if (in_array($action->id, $this->guestAccess)) {
- $this->validate = true;
- } else {
- $staff = StaffService::getById($staffId, true);
- if (empty($staff)) {
- util::logout();
- }
- if ($staff->status == 0) {
- util::logout("账号已冻结");
- }
- $this->staff = $staff;
- }
- if (!$this->validate) {
- util::notLogin();
- }
- $this->staffId = $staffId;
- return parent::beforeAction($action);
- }
- }
|