BaseController.php 993 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. //token验证
  18. //$staffId = jwt::getLoginId();
  19. $staffId = 1;
  20. $userId = 1;
  21. if (empty($staffId)) {
  22. $this->validate = false;
  23. }
  24. //游客可以访问的方法
  25. if (in_array($action->id, $this->guestAccessAction)) {
  26. $this->validate = true;
  27. }
  28. if ($this->validate == false) {
  29. util::notLogin();
  30. }
  31. $staff = StaffService::getById($staffId);
  32. if (empty($staff)) {
  33. util::fail('没有找到管理员');
  34. }
  35. $this->staff = $staff;
  36. $this->staffId = $staffId;
  37. $this->user = $staff;
  38. $this->userId = $userId;
  39. return parent::beforeAction($action);
  40. }
  41. }