浏览代码

Merge branch 'bzq/dev' of eta_mini/eta_mini_crm into debug

鲍自强 9 月之前
父节点
当前提交
b724d7ea47
共有 5 个文件被更改,包括 63 次插入82 次删除
  1. 53 51
      controllers/seller.go
  2. 1 1
      models/response/seller.go
  3. 8 1
      models/sys_user.go
  4. 0 28
      services/sys_department.go
  5. 1 1
      services/sys_user.go

+ 53 - 51
controllers/seller.go

@@ -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
 }

+ 1 - 1
models/response/seller.go

@@ -9,5 +9,5 @@ type DepartmentSellers struct {
 }
 
 type DepartmentGroupSellersResp struct {
-	List []DepartmentSellers
+	List []*DepartmentSellers
 }

+ 8 - 1
models/sys_user.go

@@ -140,7 +140,7 @@ func GetSysUserCountByRoleId(roleId int) (count int, err error) {
 	return
 }
 
-func GetSysUserList(condition string, pars []interface{}, startSize, pageSize int) (items []*SysUser, err error) {
+func GetSysUserListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*SysUser, err error) {
 	sql := `SELECT * FROM sys_user u WHERE 1=1 `
 	if condition != "" {
 		sql += condition
@@ -151,6 +151,13 @@ func GetSysUserList(condition string, pars []interface{}, startSize, pageSize in
 	return
 }
 
+func GetSysUserListByIsEnabled(isEnabled bool) (items []*SysUser, err error) {
+	sql := `SELECT * FROM sys_user u WHERE 1=1 AND is_enabled=?`
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, isEnabled).QueryRows(&items)
+	return
+}
+
 func GetSysUserIdList() (items []int, err error) {
 	sql := ` SELECT sys_user_id FROM sys_user WHERE 1=1 `
 	o := orm.NewOrm()

+ 0 - 28
services/sys_department.go

@@ -2,7 +2,6 @@ package services
 
 import (
 	"eta/eta_mini_crm/models"
-	"eta/eta_mini_crm/models/response"
 	"strconv"
 	"strings"
 )
@@ -68,30 +67,3 @@ func GetSysDepartmentPathIdsById(sysDepartmentId int) (pathIds []int, err error)
 	}
 	return
 }
-
-// GetSysDepartmentAndSellerById 根据当前部门id,获取部门下的子目录以及销售(系统用户)
-func GetSysDepartmentAndSellerById(sysDepartmentId int, enabled bool) (items []*response.DepartmentSellers, err error) {
-	depList, err := models.GetChildSysDepartmentListById(sysDepartmentId)
-	if err != nil {
-		return
-	}
-	for _, dep := range depList {
-		depItem := &response.DepartmentSellers{
-			SysDepartmentId:   dep.SysDepartmentId,
-			SysDepartmentName: dep.SysDepartmentName,
-		}
-		items = append(items, depItem)
-	}
-	userList, err := models.GetSysUserByDepartmentId(sysDepartmentId, enabled)
-	if err != nil {
-		return
-	}
-	for _, user := range userList {
-		userItem := &response.DepartmentSellers{
-			SysUserId:   user.SysUserId,
-			SysRealName: user.SysRealName,
-		}
-		items = append(items, userItem)
-	}
-	return
-}

+ 1 - 1
services/sys_user.go

@@ -4,7 +4,7 @@ import "eta/eta_mini_crm/models"
 
 func GetSysUserList(condition string, pars []interface{}, startSize, pageSize int) (items []*models.SysUserMapping, err error) {
 	// 查询系统用户
-	sysUserList, err := models.GetSysUserList(condition, pars, startSize, pageSize)
+	sysUserList, err := models.GetSysUserListByCondition(condition, pars, startSize, pageSize)
 	if err != nil {
 		return
 	}