area.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package controllers
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "lzyd-user-api/common"
  6. "lzyd-user-api/models"
  7. "lzyd-user-api/services"
  8. "regexp"
  9. )
  10. // @tags area
  11. // @Description 获取省市区
  12. // @Summary 获取省市区
  13. // @Produce json
  14. // @Param p_code query string false "地区code"
  15. // @Success 200 {string} json "{"code":200,"message":"success","data":{"token":"","customer":{"id":"","code":"","name":""}}}"
  16. // @Router /area/getArea [get]
  17. func GetArea(c *gin.Context) {
  18. PCode := c.Query("p_code")
  19. var (
  20. code = common.Success
  21. )
  22. if len(PCode) == 0 {
  23. var (
  24. model []models.ReqProvince
  25. )
  26. model = services.QueryProvinceCode()
  27. common.GenResp(c, code, "SUCCESS", model)
  28. return
  29. }
  30. //PCode_int, _ := strconv.Atoi(PCode)
  31. reg := regexp.MustCompile(`0000`)
  32. fmt.Println(reg.FindAllString(PCode, -1))
  33. if len(reg.FindAllString(PCode, -1)) > 0 {
  34. var (
  35. model []models.ReqCity
  36. )
  37. model = services.QueryCityCode(PCode)
  38. common.GenResp(c, code, "SUCCESS", model)
  39. return
  40. }
  41. if len(reg.FindAllString(PCode, -1)) == 0 {
  42. var (
  43. model []models.ReqArea
  44. )
  45. model = services.QueryAreaCode(PCode)
  46. common.GenResp(c, code, "SUCCESS", model)
  47. return
  48. }
  49. //model = services.QueryAreaCode(PCode)
  50. //if model.Id == 0 {
  51. // code = common.SystemHasNoUser
  52. //}
  53. //if common.Success == code {
  54. // // 修改上一次登录时间
  55. // //_ = model.UpdateLoginTime()
  56. // common.GenResp(c, code, "SUCCESS", model)
  57. //} else {
  58. // common.GenResp(c, code, "内部错误", nil)
  59. //}
  60. }