AuthAdminUser.php 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Facades\Auth;
  4. use Illuminate\Support\Facades\Cache;
  5. trait AuthAdminUser
  6. {
  7. /**
  8. * 获取登录用户ID
  9. * @return int
  10. */
  11. public function getAuthUserId()
  12. {
  13. $user = $this->getAuthUser();
  14. return $user['id'];
  15. }
  16. /**
  17. * 获取公司ID
  18. * @return int
  19. */
  20. public function getAuthSalt()
  21. {
  22. $user = $this->getAuthUser();
  23. return $user['salt'];
  24. }
  25. /**
  26. * 获取公司ID
  27. * @return int
  28. */
  29. public function getAuthToken()
  30. {
  31. $user = $this->getAuthUser();
  32. return $user['token'];
  33. }
  34. /**
  35. * 获取登录用户
  36. * @return \Illuminate\Contracts\Auth\Authenticatable|null
  37. */
  38. public function getAuthUser()
  39. {
  40. // todo 用redis缓存来获取
  41. $user=Auth::user();
  42. return $user;
  43. }
  44. }