BaseController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 ($staffId == 4) {
  23. $currentRoute = $this->id . '/' . $action->id;
  24. $arr = [
  25. 'staff/login-detail',
  26. 'item/list',
  27. 'item-class/list',
  28. 'item-class/get-all-class',
  29. 'unit/get-all-unit',
  30. 'upload/save-img',
  31. 'item/add',
  32. ];
  33. if (in_array($currentRoute, $arr) == false) {
  34. util::fail('没有找到资源');
  35. }
  36. }
  37. //游客可以访问的方法
  38. if (in_array($action->id, $this->guestAccess)) {
  39. $this->validate = true;
  40. } else {
  41. $staff = StaffService::getById($staffId, true);
  42. if (empty($staff)) {
  43. util::logout();
  44. }
  45. if ($staff->status == 0) {
  46. util::logout("账号已冻结");
  47. }
  48. $this->staff = $staff;
  49. }
  50. if ($this->validate == false) {
  51. util::notLogin();
  52. }
  53. $this->staffId = $staffId;
  54. return parent::beforeAction($action);
  55. }
  56. }