SysRegionService.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Services;
  3. use App\Models\SysRegion;
  4. use Slowlyo\OwlAdmin\Services\AdminService;
  5. /**
  6. * 行政区划
  7. *
  8. * @method SysRegion getModel()
  9. * @method SysRegion|\Illuminate\Database\Query\Builder query()
  10. */
  11. class SysRegionService extends AdminService
  12. {
  13. protected string $modelName = SysRegion::class;
  14. /**
  15. * 获取省份列表
  16. */
  17. public function getProvinceList()
  18. {
  19. return $this->query()->where('depth', 1)->get();
  20. }
  21. /**
  22. * 获取省份(与getProvinceList相同)
  23. */
  24. public function getProvince()
  25. {
  26. return $this->getProvinceList();
  27. }
  28. /**
  29. * 获取指定省份的城市列表
  30. */
  31. public function getCity($provinceId)
  32. {
  33. return $this->query()->where('parent_id', $provinceId)
  34. ->where('depth', 2)
  35. ->get();
  36. }
  37. /**
  38. * 获取指定城市的区域列表
  39. */
  40. public function getArea($cityId)
  41. {
  42. return $this->query()->where('parent_id', $cityId)
  43. ->where('depth', 3)
  44. ->get();
  45. }
  46. /**
  47. * 获取所有省份
  48. */
  49. public function getAllProvince()
  50. {
  51. return $this->getProvinceList();
  52. }
  53. /**
  54. * 获取所有城市
  55. */
  56. public function getAllCity()
  57. {
  58. return $this->query()->where('depth', 2)->get();
  59. }
  60. /**
  61. * 获取所有区域
  62. */
  63. public function getAllArea()
  64. {
  65. return $this->query()->where('depth', 3)->get();
  66. }
  67. /**
  68. * 获取所有街道
  69. */
  70. public function getAllStreet()
  71. {
  72. return $this->query()->where('depth', 4)->get();
  73. }
  74. }