base_district.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package base
  2. import (
  3. "context"
  4. "github.com/gogf/gf/frame/g"
  5. "dashoo.cn/micro/app/dao/base"
  6. model "dashoo.cn/micro/app/model/base"
  7. "dashoo.cn/micro/app/service"
  8. )
  9. type districtService struct {
  10. *service.ContextService
  11. Dao *base.BaseDistrictDao
  12. }
  13. func NewDistrictService(ctx context.Context) (svc *districtService, err error) {
  14. svc = new(districtService)
  15. if svc.ContextService, err = svc.Init(ctx); err != nil {
  16. return nil, err
  17. }
  18. svc.Dao = base.NewBaseDistrictDao(svc.Tenant)
  19. return svc, nil
  20. }
  21. //区域省市区 树形结构
  22. func (d *districtService) ListToTree(pid int) []*model.T {
  23. var distributorList []model.BaseDistrict
  24. d.Dao.M.Where(base.BaseDistrict.Columns.ParentId, pid).Scan(&distributorList)
  25. treeList := []*model.T{}
  26. for _, v := range distributorList {
  27. if v.ParentId == pid {
  28. child := d.ListToTree(v.Id)
  29. node := &model.T{
  30. Id: v.Id,
  31. ParentId: v.ParentId,
  32. DistName: v.DistName,
  33. }
  34. node.Children = child
  35. treeList = append(treeList, node)
  36. }
  37. }
  38. g.Log().Info("xc11", treeList)
  39. return treeList
  40. }