AuthUser.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\Auth;
  4. use Illuminate\Support\Facades\Cache;
  5. trait AuthUser
  6. {
  7. /**
  8. * 获取登录用户ID
  9. * @return int
  10. */
  11. public function getAuthUserId()
  12. {
  13. $user = $this->getAuthUser();
  14. return $user['id'];
  15. }
  16. /**
  17. * 获取手机
  18. * @return string
  19. */
  20. public function getAuthPhone()
  21. {
  22. $user = $this->getAuthUser();
  23. return $user['phone']??'';
  24. }
  25. /**
  26. * 获取手机
  27. * @return string
  28. */
  29. public function getAuthEmail()
  30. {
  31. $user = $this->getAuthUser();
  32. return $user['email']??'';
  33. }
  34. /**
  35. * 获取公司ID
  36. * @return int
  37. */
  38. public function getAuthApiToken()
  39. {
  40. $user = $this->getAuthUser();
  41. return $user['api_token'];
  42. }
  43. /**
  44. * 获取登录用户
  45. * @return \Illuminate\Contracts\Auth\Authenticatable|null
  46. */
  47. public function getAuthUser()
  48. {
  49. // todo 用redis缓存来获取
  50. $user=Auth::user();
  51. return $user;
  52. }
  53. }