package service import ( "SSO/models" "SSO/utils" ) func GetAllProvince() []*models.District { var province []*models.District err := readUserDb.Model(&models.District{}).Where("level = 1").Find(&province).Error if err != nil { utils.ErrorLog("获取所有省份失败: %v", err) return nil } else { return province } } func GetCitiesWithProvinceID(provinceID int) []*models.District { var cities []*models.District err := readUserDb.Model(&models.District{}).Where("level = 2 AND upid = ?", provinceID).Find(&cities).Error if err != nil { utils.ErrorLog("获取省份 id 为 %v 下的城市失败: %v", provinceID, err) return nil } else { return cities } } func GetDistrictsWithCityID(cityID int) []*models.District { var districts []*models.District err := readUserDb.Model(&models.District{}).Where("level = 3 AND upid = ?", cityID).Find(&districts).Error if err != nil { utils.ErrorLog("获取城市 id 为 %v 下的区县失败: %v", cityID, err) return nil } else { return districts } }