| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package base
- import (
- "context"
- "github.com/gogf/gf/errors/gerror"
- "github.com/gogf/gf/frame/g"
- "dashoo.cn/micro/app/dao/base"
- model "dashoo.cn/micro/app/model/base"
- "dashoo.cn/micro/app/service"
- )
- type districtService struct {
- *service.ContextService
- Dao *base.BaseDistrictDao
- }
- func NewDistrictService(ctx context.Context) (svc *districtService, err error) {
- svc = new(districtService)
- if svc.ContextService, err = svc.Init(ctx); err != nil {
- return nil, err
- }
- svc.Dao = base.NewBaseDistrictDao(svc.Tenant)
- return svc, nil
- }
- //区域省市区 树形结构
- func (d *districtService) ListToTree(pid int) []*model.T {
- var distributorList []model.BaseDistrict
- g.Log().Info("ID", pid)
- d.Dao.M.Where(base.BaseDistrict.Columns.ParentId, pid).Scan(&distributorList)
- treeList := []*model.T{}
- for _, v := range distributorList {
- if v.ParentId == pid {
- child := d.ListToTree(v.Id)
- node := &model.T{
- Id: v.Id,
- ParentId: v.ParentId,
- DistName: v.DistName,
- }
- node.Children = child
- treeList = append(treeList, node)
- }
- }
- g.Log().Info("xc11", treeList)
- return treeList
- }
- func (d *districtService) GetProvinceInfo() (list []*model.Province) {
- Model := d.Dao.M
- err := Model.Where(base.BaseDistrict.Columns.ParentId, 0).Scan(&list)
- if err != nil {
- g.Log().Error(err)
- err = gerror.New("获取数据失败")
- return
- }
- return
- }
|