BaseController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace pt\controllers;
  3. use bizHd\saas\services\StaffService;
  4. use common\components\jwt;
  5. use common\components\util;
  6. use Yii;
  7. class BaseController extends PublicController
  8. {
  9. public $staff, $staffId, $userId, $user;
  10. public $isLogin = false;
  11. public $guestAccessAction = [];//不需要登陆的方法名
  12. public $validate = true;
  13. public function beforeAction($action)
  14. {
  15. //6表示总后台
  16. Yii::$app->params['ptStyle'] = 6;
  17. $staffId = jwt::getLoginId();
  18. if (empty($staffId)) {
  19. $this->validate = false;
  20. }
  21. //游客可以访问的方法
  22. if (in_array($action->id, $this->guestAccessAction)) {
  23. $this->validate = true;
  24. } else {
  25. $staff = StaffService::getById($staffId);
  26. if (empty($staff)) {
  27. util::fail('没有找到管理员');
  28. }
  29. $this->staff = $staff;
  30. $this->user = $staff;
  31. }
  32. if ($this->validate == false) {
  33. util::notLogin();
  34. }
  35. $this->staffId = $staffId;
  36. return parent::beforeAction($action);
  37. }
  38. }