area_code_service.go 947 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package user
  2. import (
  3. logger "eta/eta_mini_ht_api/common/component/log"
  4. "eta/eta_mini_ht_api/models/user"
  5. )
  6. type AreaCodeDTO struct {
  7. CodeName string `json:"codeName"`
  8. CodeValue string `json:"codeValue"`
  9. }
  10. func GetAreaCodes() (areaCodes []AreaCodeDTO, err error) {
  11. list, err := user.GetAreaCodes()
  12. if err != nil {
  13. logger.Error("获取手机区号失败:%v", err)
  14. return
  15. }
  16. for _, areaCode := range list {
  17. areaCodes = append(areaCodes, convertToAreaCodeDTO(areaCode))
  18. }
  19. return
  20. }
  21. func GetValidAreaCodes() (areaCodes []AreaCodeDTO, err error) {
  22. list, err := user.GetValidAreaCodes()
  23. if err != nil {
  24. logger.Error("获取手机区号失败:%v", err)
  25. return
  26. }
  27. for _, areaCode := range list {
  28. areaCodes = append(areaCodes, convertToAreaCodeDTO(areaCode))
  29. }
  30. return
  31. }
  32. func convertToAreaCodeDTO(areaCode user.AreaCode) AreaCodeDTO {
  33. return AreaCodeDTO{
  34. CodeName: areaCode.CodeName,
  35. CodeValue: areaCode.CodeValue,
  36. }
  37. }