BaseConfig.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace General\Services;
  3. use General\Models\Manage\Manage;
  4. /**
  5. * 基础配置
  6. * @property-read int $login_user_id
  7. * @property-read string $login_user_role
  8. * @property-read string $login_user_account
  9. * @property-read object $login_user
  10. * @property-read bool $has_edit_role
  11. */
  12. trait BaseConfig
  13. {
  14. public function __get(string $name)
  15. {
  16. if (!isset($this->$name)) {
  17. return $this->$name();
  18. }
  19. }
  20. //获取当前登录用户ID
  21. private function login_user_id()
  22. {
  23. return $this->login_user->id;
  24. }
  25. //获取当前登录用户角色
  26. private function login_user_role()
  27. {
  28. return $this->login_user->role;
  29. }
  30. //获取当前登录用户
  31. private function login_user_account()
  32. {
  33. return $this->login_user->account;
  34. }
  35. private function login_user()
  36. {
  37. if (empty(session('manage_user'))) {
  38. if (env('APP_ENV') == 'local')
  39. return Manage::where('account', 'zsy_admin')->first();
  40. }
  41. $user = unserialize(session('manage_user'));
  42. return $user;
  43. }
  44. // 编辑权限
  45. private function has_edit_role()
  46. {
  47. $accounts = [
  48. "zsy_sdb",
  49. "zsy_zlj",
  50. "zsy_gdy",
  51. "zsy_lkf",
  52. "zsy_pxp"
  53. ];
  54. return in_array($this->login_user_account, $accounts) ? true : false;
  55. }
  56. }