location.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package service
  2. import (
  3. "context"
  4. http "go-common/app/interface/bbq/app-bbq/api/http/v1"
  5. "go-common/app/interface/bbq/app-bbq/model"
  6. )
  7. // GetLocaitonAll .
  8. func (s *Service) GetLocaitonAll(c context.Context, arg *http.LocationRequest) (*http.LocationResponse, error) {
  9. result := &http.LocationResponse{}
  10. m, err := s.dao.GetLocationAll(c)
  11. if err != nil {
  12. return result, err
  13. }
  14. var coutries []*model.Location
  15. for _, item := range (*m)[arg.PID] {
  16. coutry := &model.Location{
  17. ID: item.ID,
  18. PID: item.PID,
  19. Name: item.Name,
  20. }
  21. var provices []*model.Location
  22. for _, v := range (*m)[item.ID] {
  23. provice := &model.Location{
  24. ID: v.ID,
  25. PID: v.PID,
  26. Name: v.Name,
  27. }
  28. var citys []*model.Location
  29. for _, u := range (*m)[v.ID] {
  30. city := &model.Location{
  31. ID: u.ID,
  32. PID: u.PID,
  33. Name: u.Name,
  34. }
  35. var area []*model.Location
  36. for _, w := range (*m)[u.ID] {
  37. var child []*model.Location
  38. area = append(area, &model.Location{
  39. ID: w.ID,
  40. PID: w.PID,
  41. Name: w.Name,
  42. Child: child,
  43. })
  44. }
  45. city.Child = area
  46. citys = append(citys, city)
  47. }
  48. provice.Child = citys
  49. provices = append(provices, provice)
  50. }
  51. coutry.Child = provices
  52. coutries = append(coutries, coutry)
  53. }
  54. result.List = coutries
  55. return result, err
  56. }
  57. // GetLocationChild .
  58. func (s *Service) GetLocationChild(c context.Context, arg *http.LocationRequest) (*http.LocationResponse, error) {
  59. result := &http.LocationResponse{}
  60. m, err := s.dao.GetLocationChild(c, arg.PID)
  61. if err != nil {
  62. return result, err
  63. }
  64. var provices []*model.Location
  65. for _, v := range (*m)[arg.PID] {
  66. var child []*model.Location
  67. provice := &model.Location{
  68. ID: v.ID,
  69. PID: v.PID,
  70. Name: v.Name,
  71. Child: child,
  72. }
  73. provices = append(provices, provice)
  74. }
  75. result.List = provices
  76. return result, err
  77. }