sso

district_service.go 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package service
  2. import (
  3. "SSO/models"
  4. "SSO/utils"
  5. )
  6. func GetAllProvince() []*models.District {
  7. var province []*models.District
  8. err := readUserDb.Model(&models.District{}).Where("level = 1").Find(&province).Error
  9. if err != nil {
  10. utils.ErrorLog("获取所有省份失败: %v", err)
  11. return nil
  12. } else {
  13. return province
  14. }
  15. }
  16. func GetCitiesWithProvinceID(provinceID int) []*models.District {
  17. var cities []*models.District
  18. err := readUserDb.Model(&models.District{}).Where("level = 2 AND upid = ?", provinceID).Find(&cities).Error
  19. if err != nil {
  20. utils.ErrorLog("获取省份 id 为 %v 下的城市失败: %v", provinceID, err)
  21. return nil
  22. } else {
  23. return cities
  24. }
  25. }
  26. func GetDistrictsWithCityID(cityID int) []*models.District {
  27. var districts []*models.District
  28. err := readUserDb.Model(&models.District{}).Where("level = 3 AND upid = ?", cityID).Find(&districts).Error
  29. if err != nil {
  30. utils.ErrorLog("获取城市 id 为 %v 下的区县失败: %v", cityID, err)
  31. return nil
  32. } else {
  33. return districts
  34. }
  35. }