sso

district_controller.go 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package controllers
  2. import (
  3. "SSO/enums"
  4. "SSO/service"
  5. )
  6. type DistrictController struct {
  7. BaseController
  8. }
  9. // /provinces [get]
  10. func (this *DistrictController) GetProvinces() {
  11. provinces := service.GetAllProvince()
  12. if len(provinces) == 0 {
  13. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  14. this.ServeJSON()
  15. return
  16. } else {
  17. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  18. "list": provinces,
  19. })
  20. this.ServeJSON()
  21. return
  22. }
  23. }
  24. // /city [get]
  25. // @param province_id:int
  26. func (this *DistrictController) GetCities() {
  27. pid, _ := this.GetInt("province_id", 0)
  28. if pid == 0 {
  29. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  30. this.ServeJSON()
  31. return
  32. }
  33. cities := service.GetCitiesWithProvinceID(pid)
  34. if len(cities) == 0 {
  35. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  36. this.ServeJSON()
  37. return
  38. } else {
  39. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  40. "list": cities,
  41. })
  42. this.ServeJSON()
  43. return
  44. }
  45. }
  46. // /district [get]
  47. // @param city_id:int
  48. func (this *DistrictController) GetDistricts() {
  49. cid, _ := this.GetInt("city_id", 0)
  50. if cid == 0 {
  51. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  52. this.ServeJSON()
  53. return
  54. }
  55. cities := service.GetDistrictsWithCityID(cid)
  56. if len(cities) == 0 {
  57. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBSelectNoResult)
  58. this.ServeJSON()
  59. return
  60. } else {
  61. this.Data["json"] = enums.MakeSuccessResponseJSON(map[string]interface{}{
  62. "list": cities,
  63. })
  64. this.ServeJSON()
  65. return
  66. }
  67. }