BaseController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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;
  10. public $isLogin = false;
  11. public $guestAccess = [];//不需要登陆的方法名
  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->guestAccess)) {
  23. $this->validate = true;
  24. } else {
  25. $staff = StaffService::getById($staffId, true);
  26. if (empty($staff)) {
  27. util::logout();
  28. }
  29. if ($staff->status == 0) {
  30. util::logout("账号已冻结");
  31. }
  32. $this->staff = $staff;
  33. }
  34. if ($this->validate == false) {
  35. util::notLogin();
  36. }
  37. $this->staffId = $staffId;
  38. return parent::beforeAction($action);
  39. }
  40. }