|
@@ -33,7 +33,7 @@ func NewDistrictService(ctx context.Context) (svc *districtService, err error) {
|
|
|
func (s *districtService) ListToTree(Id int64) (treeList []*model.T, err error) {
|
|
func (s *districtService) ListToTree(Id int64) (treeList []*model.T, err error) {
|
|
|
ms := make(map[int]*model.T)
|
|
ms := make(map[int]*model.T)
|
|
|
var distributorList []model.BaseDistrict
|
|
var distributorList []model.BaseDistrict
|
|
|
- err = s.Dao.Order("parent_id asc").Scan(&distributorList)
|
|
|
|
|
|
|
+ err = s.Dao.Order("id asc").Scan(&distributorList)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
g.Log().Error(err)
|
|
|
return
|
|
return
|
|
@@ -53,8 +53,23 @@ func (s *districtService) ListToTree(Id int64) (treeList []*model.T, err error)
|
|
|
}
|
|
}
|
|
|
treeList = append(treeList, v)
|
|
treeList = append(treeList, v)
|
|
|
}
|
|
}
|
|
|
|
|
+ s.SortToTree(treeList)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
+func (s *districtService) SortToTree(treeList []*model.T) []*model.T {
|
|
|
|
|
+ length := len(treeList)
|
|
|
|
|
+ for i := 0; i < length-1; i++ {
|
|
|
|
|
+ for j := i + 1; j < length; j++ {
|
|
|
|
|
+ if treeList[i].Id > treeList[j].Id {
|
|
|
|
|
+ treeList[i], treeList[j] = treeList[j], treeList[i]
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ for i := 0; i < length; i++ {
|
|
|
|
|
+ treeList[i].Children = s.SortToTree(treeList[i].Children)
|
|
|
|
|
+ }
|
|
|
|
|
+ return treeList
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
// GetProvinceList 返回所有省份的
|
|
// GetProvinceList 返回所有省份的
|
|
|
func (s *districtService) GetProvinceList() (list []*model.Province, err error) {
|
|
func (s *districtService) GetProvinceList() (list []*model.Province, err error) {
|