area.go 916 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package services
  2. import (
  3. "fmt"
  4. "lzyd-user-api/common"
  5. "lzyd-user-api/models"
  6. )
  7. /**
  8. 获取所有省份
  9. */
  10. func QueryProvinceCode() []models.ReqProvince {
  11. var province []models.ReqProvince
  12. sql := `SELECT id, code, name
  13. FROM province`
  14. common.DB.Raw(sql).Find(&province)
  15. fmt.Println("你获取的是:", province)
  16. return province
  17. }
  18. /**
  19. 根据省code查询市
  20. */
  21. func QueryCityCode(code string) []models.ReqCity {
  22. var city []models.ReqCity
  23. sql := `SELECT id, code, name, province_code
  24. FROM city
  25. WHERE province_code = ?`
  26. common.DB.Raw(sql, code).Find(&city)
  27. fmt.Println("你获取的是:", city)
  28. return city
  29. }
  30. /**
  31. 根据市code查询区
  32. */
  33. func QueryAreaCode(code string) []models.ReqArea {
  34. var area []models.ReqArea
  35. sql := `SELECT id, code, name, city_code
  36. FROM area
  37. WHERE city_code = ?`
  38. common.DB.Raw(sql, code).Find(&area)
  39. fmt.Println("你获取的是:", area)
  40. return area
  41. }