BaseController.php 1.8 KB

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