|
@@ -3,7 +3,6 @@ package controllers
|
|
|
import (
|
|
|
"eta/eta_mini_crm/models"
|
|
|
"eta/eta_mini_crm/models/response"
|
|
|
- "eta/eta_mini_crm/services"
|
|
|
)
|
|
|
|
|
|
type SellerController struct {
|
|
@@ -28,71 +27,74 @@ func (this *SellerController) List() {
|
|
|
if getAllEnabled { //获取所有状态的用户
|
|
|
enabled = false
|
|
|
}
|
|
|
- list := make([]response.DepartmentSellers, 0)
|
|
|
- // 获取第一层的部门
|
|
|
- departmentList, err := models.GetSysDepartmentListByLevel(1)
|
|
|
+ departmentList, err := models.GetSysDepartmentList()
|
|
|
if err != nil {
|
|
|
br.Msg = "获取部门失败"
|
|
|
br.ErrMsg = "获取部门失败,系统异常,Err:" + err.Error()
|
|
|
return
|
|
|
}
|
|
|
- for _, dep := range departmentList {
|
|
|
- departmentAndSellerList1, err := services.GetSysDepartmentAndSellerById(dep.SysDepartmentId, enabled)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取部门失败"
|
|
|
- br.ErrMsg = "获取部门失败,系统异常,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- for _, departmentAndSeller1 := range departmentAndSellerList1 {
|
|
|
- if departmentAndSeller1.SysDepartmentId == 0 {
|
|
|
- continue
|
|
|
- }
|
|
|
- departmentAndSellerList2, err := services.GetSysDepartmentAndSellerById(departmentAndSeller1.SysDepartmentId, enabled)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取部门失败"
|
|
|
- br.ErrMsg = "获取部门失败,系统异常,Err:" + err.Error()
|
|
|
- return
|
|
|
- }
|
|
|
- departmentAndSeller1.ChildrenList = departmentAndSellerList2
|
|
|
- for _, departmentAndSeller2 := range departmentAndSellerList2 {
|
|
|
- if departmentAndSeller2.SysDepartmentId == 0 {
|
|
|
- continue
|
|
|
- }
|
|
|
- departmentAndSellerList3, err := services.GetSysDepartmentAndSellerById(departmentAndSeller2.SysDepartmentId, enabled)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取部门失败"
|
|
|
- br.ErrMsg = "获取部门失败,系统异常,Err:" + err.Error()
|
|
|
- return
|
|
|
+ seller, err := models.GetSysUserListByIsEnabled(enabled)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取销售失败"
|
|
|
+ br.ErrMsg = "获取销售失败,系统异常,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 遍历获取销售的层级结构
|
|
|
+ list := make([]*response.DepartmentSellers, 0)
|
|
|
+ for _, dep1 := range departmentList {
|
|
|
+ if dep1.ParentId == 0 {
|
|
|
+ v1 := new(response.DepartmentSellers)
|
|
|
+ v1.SysDepartmentId = dep1.SysDepartmentId
|
|
|
+ v1.SysDepartmentName = dep1.SysDepartmentName
|
|
|
+ for _, s := range seller {
|
|
|
+ if s.SysDepartmentId1 == dep1.SysDepartmentId {
|
|
|
+ s1 := new(response.DepartmentSellers)
|
|
|
+ s1.SysUserId = s.SysUserId
|
|
|
+ s1.SysRealName = s.SysRealName
|
|
|
+ v1.ChildrenList = append(v1.ChildrenList, s1)
|
|
|
}
|
|
|
- departmentAndSeller2.ChildrenList = departmentAndSellerList3
|
|
|
- for _, departmentAndSeller3 := range departmentAndSellerList3 {
|
|
|
- if departmentAndSeller3.SysDepartmentId == 0 {
|
|
|
- continue
|
|
|
+ }
|
|
|
+ for _, dep2 := range departmentList {
|
|
|
+ if dep2.ParentId == dep1.SysDepartmentId {
|
|
|
+ v2 := new(response.DepartmentSellers)
|
|
|
+ v2.SysDepartmentId = dep2.SysDepartmentId
|
|
|
+ v2.SysDepartmentName = dep2.SysDepartmentName
|
|
|
+ for _, s := range seller {
|
|
|
+ if s.SysDepartmentId2 == dep2.SysDepartmentId {
|
|
|
+ s1 := new(response.DepartmentSellers)
|
|
|
+ s1.SysUserId = s.SysUserId
|
|
|
+ s1.SysRealName = s.SysRealName
|
|
|
+ v2.ChildrenList = append(v2.ChildrenList, s1)
|
|
|
+ }
|
|
|
}
|
|
|
- departmentAndSellerList4, err := services.GetSysDepartmentAndSellerById(departmentAndSeller3.SysDepartmentId, enabled)
|
|
|
- if err != nil {
|
|
|
- br.Msg = "获取部门失败"
|
|
|
- br.ErrMsg = "获取部门失败,系统异常,Err:" + err.Error()
|
|
|
- return
|
|
|
+ v1.ChildrenList = append(v1.ChildrenList, v2)
|
|
|
+ for _, dep3 := range departmentList {
|
|
|
+ if dep3.ParentId == dep2.SysDepartmentId {
|
|
|
+ v3 := new(response.DepartmentSellers)
|
|
|
+ v3.SysDepartmentId = dep3.SysDepartmentId
|
|
|
+ v3.SysDepartmentName = dep3.SysDepartmentName
|
|
|
+ for _, s := range seller {
|
|
|
+ if s.SysDepartmentId3 == dep3.SysDepartmentId {
|
|
|
+ s1 := new(response.DepartmentSellers)
|
|
|
+ s1.SysUserId = s.SysUserId
|
|
|
+ s1.SysRealName = s.SysRealName
|
|
|
+ v3.ChildrenList = append(v3.ChildrenList, s1)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v2.ChildrenList = append(v2.ChildrenList, v3)
|
|
|
+ }
|
|
|
}
|
|
|
- departmentAndSeller3.ChildrenList = departmentAndSellerList4
|
|
|
}
|
|
|
}
|
|
|
+ list = append(list, v1)
|
|
|
}
|
|
|
|
|
|
- item1 := response.DepartmentSellers{
|
|
|
- SysDepartmentId: dep.SysDepartmentId,
|
|
|
- SysDepartmentName: dep.SysDepartmentName,
|
|
|
- ChildrenList: departmentAndSellerList1,
|
|
|
- }
|
|
|
- list = append(list, item1)
|
|
|
}
|
|
|
+ resp := new(response.DepartmentGroupSellersResp)
|
|
|
+ resp.List = list
|
|
|
|
|
|
br.Msg = "获取成功"
|
|
|
br.Success = true
|
|
|
br.Ret = 200
|
|
|
- br.Data = response.DepartmentGroupSellersResp{
|
|
|
- List: list,
|
|
|
- }
|
|
|
-
|
|
|
+ br.Data = resp
|
|
|
}
|