BaseController.php 1.0 KB

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