ziwen 2 жил өмнө
parent
commit
1aa91e7340

+ 3 - 3
controller/crm/company_seller.go

@@ -73,14 +73,14 @@ func (rg *CompanySellerController) GroupList(c *gin.Context) {
 // @Success 200 {object} crm.SellerAdminWithGroupList
 // @router /crm/company_seller/all_list [get]
 func (rg *CompanySellerController) AllList(c *gin.Context) {
-	sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
+	ficcList, raiLits, e := crmService.GetSellerDepartmentListWithGroupAndTeamByDepartment()
 	if e != nil {
 		resp.FailData("获取销售失败", "Err:"+e.Error(), c)
 		return
 	}
 	respItem := crm.AllSellerResp{
-		FiccSeller: sellerList,
-		RaiSeller:  sellerList,
+		FiccSeller: ficcList,
+		RaiSeller:  raiLits,
 	}
 	resp.OkData("获取成功", respItem, c)
 }

+ 64 - 1
services/crm/company_seller.go

@@ -200,4 +200,67 @@ func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
 	resp.FiccList = ficcList
 	resp.RaiList = raiList
 	return
-}
+}
+
+// GetSellerDepartmentAndGroupMap 获取销售部门列表-包含大组和小组
+func GetSellerDepartmentListWithGroupAndTeamByDepartment() (ficcList []*crm.SellerAdminWithGroupTeam,raiList []*crm.SellerAdminWithGroupTeam, err error) {
+	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+	ficcList = make([]*crm.SellerAdminWithGroupTeam, 0)
+	raiList = make([]*crm.SellerAdminWithGroupTeam, 0)
+	// 获取组别列表
+	groupCond := "department_id in (?)"
+	groupPars := make([]interface{}, 0)
+	groupPars = append(groupPars, departmentIds)
+	groupOB := new(crm.SysGroup)
+	groupList, e := groupOB.List(groupCond, groupPars)
+	if e != nil {
+		err = errors.New("获取组别列表失败, Err: " + e.Error())
+		return
+	}
+	groupMap := make(map[int]*crm.SysGroup)
+	for i := range groupList {
+		groupMap[groupList[i].GroupId] = groupList[i]
+	}
+
+	// 获取销售部门所有销售信息
+	adminCond := "department_id in (?) AND enabled = 1"
+	adminPars := make([]interface{}, 0)
+	adminPars = append(adminPars, departmentIds)
+	adminOB := new(crm.Admin)
+	adminList, e := adminOB.List(adminCond, adminPars)
+	if e != nil {
+		err = errors.New("获取销售列表失败, Err: " + e.Error())
+		return
+	}
+
+	// 销售列表
+	for i := range adminList {
+		v := new(crm.SellerAdminWithGroupTeam)
+		v.DepartmentId = adminList[i].DepartmentId
+		v.SellerId = adminList[i].AdminId
+		v.SellerName = adminList[i].RealName
+		g := groupMap[adminList[i].GroupId]
+		if g != nil {
+			if g.ParentId > 0 {
+				// 三级分组
+				p := groupMap[g.ParentId]
+				if p != nil {
+					v.GroupId = p.GroupId
+					v.GroupName = p.GroupName
+					v.TeamId = g.GroupId
+					v.TeamName = g.GroupName
+				}
+			} else {
+				// 二级分组
+				v.GroupId = g.GroupId
+				v.GroupName = g.GroupName
+			}
+		}
+		if v.DepartmentId == crm.SellerDepartmentId {
+			ficcList = append(ficcList, v)
+		} else {
+			raiList = append(raiList, v)
+		}
+	}
+	return
+}