AuthUser.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Base\Services;
  3. use Illuminate\Support\Facades\Auth;
  4. use App\User\Facades\CompanyDepartmentRelationFacade;
  5. use App\Base\Facades\ApiFacade;
  6. trait AuthUser
  7. {
  8. /**
  9. * 获取登录用户ID
  10. * @return int
  11. */
  12. public function getAuthAdminId()
  13. {
  14. $user = $this->getAuthUser();
  15. return $user['id'] ?? 0;
  16. }
  17. /**
  18. * 获取登录用户
  19. * @return \Illuminate\Contracts\Auth\Authenticatable|null
  20. */
  21. public function getAuthUser()
  22. {
  23. return Auth::user();
  24. }
  25. /**
  26. * 获取头部token
  27. * @return mixed
  28. */
  29. public function getAuthToken()
  30. {
  31. $user = $this->getAuthUser();
  32. return $user['token'];
  33. }
  34. /**
  35. * 获取角色ID
  36. * @return int
  37. */
  38. public function getAuthRoleId()
  39. {
  40. $user = $this->getAuthUser();
  41. return $user['role_id'];
  42. }
  43. /**
  44. * 是否为管理员
  45. * @param $typeId
  46. * @return bool
  47. */
  48. protected function isAdmin($roleId = 1)
  49. {
  50. return $roleId == $this->getAuthRoleId();
  51. }
  52. }