Admin.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Utils;
  3. class Admin
  4. {
  5. const ROLE_JISHU_ADMIN = 'administrator';
  6. const ROLE_MERCHANT = 'merchantsAdmin';
  7. const ROLE_ADMIN = 'normalAdministrator';
  8. const ROLE_AREA_ADMIN = 'areaAdmin';
  9. const ROLE_CUSTOMER = 'customerService';
  10. /**
  11. * 当前登录管理员
  12. *
  13. * @return \App\Models\AdminUser|\Illuminate\Contracts\Auth\Authenticatable
  14. */
  15. public static function user()
  16. {
  17. return static::guard()->user();
  18. }
  19. /**
  20. * 当前登录管理员是不是超级管理员
  21. *
  22. * @return bool
  23. */
  24. public static function isAdministrator()
  25. {
  26. return static::user() && static::user()->isAdministrator();
  27. }
  28. /**
  29. * 当前登录管理员是不是普通超级管理员
  30. *
  31. * @return bool
  32. */
  33. public static function isNormalAdministrator()
  34. {
  35. return static::user() && static::user()->isNormalAdministrator();
  36. }
  37. /**
  38. * 判断当前管理员是否是区域管理员
  39. *
  40. * @return
  41. * */
  42. public static function isAreaAdmin()
  43. {
  44. return static::user() && static::user()->isAreaAdmin();
  45. }
  46. /**
  47. * 是否为商户
  48. * @return bool
  49. * Author: Mead
  50. */
  51. public static function isMerchantAdmin()
  52. {
  53. return static::user() && static::user()->isMerchantAdmin();
  54. }
  55. /**
  56. * 把路径自动拼上后端的路径前缀
  57. *
  58. * @param string $path
  59. *
  60. * @return string
  61. */
  62. public static function url($path = '')
  63. {
  64. $prefix = 'admin-api';
  65. $path = trim($path, '/');
  66. if (is_null($path) || strlen($path) == 0) {
  67. $path = $prefix;
  68. } else {
  69. $path = $prefix . '/' . $path;
  70. }
  71. return $path;
  72. }
  73. /**
  74. * @return \Illuminate\Contracts\Auth\Guard|\Tymon\JWTAuth\JWTGuard
  75. */
  76. public static function guard()
  77. {
  78. return auth('admin');
  79. }
  80. }