Browse Source

Merge branch 'seller_census'

zwxi 1 year ago
parent
commit
b5fea42871
3 changed files with 113 additions and 111 deletions
  1. 52 63
      controller/census/seller.go
  2. 3 1
      models/crm/company_seller.go
  3. 58 47
      services/crm/company_seller.go

+ 52 - 63
controller/census/seller.go

@@ -449,18 +449,12 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		page.SetCurrent(1)
 	}
 
-	//var departmentId int
-	//if req.SellerType == 1 {
-	//	departmentId = crm.SellerDepartmentId
-	//} else if req.SellerType == 2 {
-	//	departmentId = crm.RaiSellerDepartmentId
-	//} else if req.SellerType == 0 {
-	//	resp.Fail("请选择销售类型", c)
-	//	return
-	//} else {
-	//	resp.Fail("请选择正确的销售类型", c)
-	//	return
-	//}
+	var departmentId int
+	if req.SellerType == 1 {
+		departmentId = crm.SellerDepartmentId
+	} else if req.SellerType == 2 {
+		departmentId = crm.RaiSellerDepartmentId
+	}
 
 	var totalMoneySlice []float64
 	historyTime, _ := time.Parse(utils.FormatDate, "2023-04-01")
@@ -490,13 +484,11 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		historyCond += ` AND new_company = 0 `
 	}
 
-	if req.SellerIds != "" {
-		sellerIds := strings.Split(req.SellerIds, ",")
-		//cond += ` AND (a.seller_id in ? ) `
-		historyCond += ` AND (seller_id in ? ) `
-		//pars = append(pars, sellerIds)
-		historyPars = append(historyPars, sellerIds)
-	}
+	//if req.SellerIds != "" {
+	//	sellerIds := strings.Split(req.SellerIds, ",")
+	//	historyCond += ` AND (seller_id in ? ) `
+	//	historyPars = append(historyPars, sellerIds)
+	//}
 
 	//groupIds := make([]int, 0)
 	//if req.GroupId > 0 {
@@ -520,26 +512,38 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 	//	historyPars = append(historyPars, groupIds)
 	//}
 
-	if req.CompanyType == 1 {
+
+
+	// 获取销售分组信息
+	sellerList, e := crmService.GetSellerDepartmentListWithEnable()
+	if e != nil {
+		resp.FailData("获取销售失败", "Err:"+e.Error(), c)
+		return
+	}
+
+	ficcSellerIds := make([]string,0)
+	raiSellerIds := make([]string,0)
+	sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
+	for i := range sellerList {
+		sellerMap[sellerList[i].SellerId] = sellerList[i]
+		if sellerList[i].DepartmentId == crm.SellerDepartmentId {
+			ficcSellerIds = append(ficcSellerIds, strconv.Itoa(sellerList[i].SellerId))
+		} else if sellerList[i].DepartmentId == crm.RaiSellerDepartmentId {
+			raiSellerIds = append(raiSellerIds, strconv.Itoa(sellerList[i].SellerId))
+		}
+	}
+	sellerIds := make([]string,0)
+
+	if req.SellerType == 1 {
 		cond += ` AND b.contract_type = 1 `
 		historyCond += ` AND new_company = 1 `
-	} else if req.CompanyType == 2 {
+		sellerIds = ficcSellerIds
+	} else if req.SellerType == 2 {
 		cond += ` AND b.contract_type IN (2,3,4) `
 		historyCond += ` AND new_company = 0 `
+		sellerIds = raiSellerIds
 	}
 
-	//if req.SellerIds != "" {
-	//	sellerIds := strings.Split(req.SellerIds, ",")
-	//	cond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
-	//	pars = append(pars, sellerIds, sellerIds)
-	//	prevCond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
-	//	prevPars = append(prevPars, sellerIds, sellerIds)
-	//	histrtyCond += ` AND seller_id in ? `
-	//	prevHistoryCond += ` AND seller_id in ? `
-	//	historyPars = append(historyPars, sellerIds)
-	//	prevHistoryPars = append(prevHistoryPars, sellerIds)
-	//}
-
 	st := startDate
 	ed := endDate
 	groupInvoiceMap := make(map[int]float64)
@@ -565,8 +569,8 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 			//	amountPars = append(amountPars, groupIds)
 			//}
 
-			if req.SellerIds != "" {
-				sellerIds := strings.Split(req.SellerIds, ",")
+			if req.SellerType != 0 {
+				//sellerIds := strings.Split(req.SellerIds, ",")
 				amountCond += ` AND (( b.seller_id IN ? AND a.invoice_id <> 0 AND b.invoice_time > "2023-04-01")`
 				amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time > "2023-04-01")) `
 				amountPars = append(amountPars, sellerIds, sellerIds)
@@ -649,8 +653,8 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 			//	amountCond += ` AND IF ( a.invoice_id = 0, d.seller_group_id, b.seller_group_id ) IN (?) `
 			//	amountPars = append(amountPars, groupIds)
 			//}
-			if req.SellerIds != "" {
-				sellerIds := strings.Split(req.SellerIds, ",")
+			if req.SellerType != 0 {
+				//sellerIds := strings.Split(req.SellerIds, ",")
 				amountCond += ` AND (( b.seller_id IN ? AND a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
 				amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) `
 				amountPars = append(amountPars, sellerIds, st, ed, sellerIds, st, ed)
@@ -747,8 +751,8 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 			//	amountCond += ` AND IF ( a.invoice_id = 0, d.seller_group_id, b.seller_group_id ) IN (?) `
 			//	amountPars = append(amountPars, groupIds)
 			//}
-			if req.SellerIds != "" {
-				sellerIds := strings.Split(req.SellerIds, ",")
+			if req.SellerType != 0 {
+				//sellerIds := strings.Split(req.SellerIds, ",")
 				amountCond += ` AND (( b.seller_id IN ? AND a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
 				amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) `
 				amountPars = append(amountPars, sellerIds, st, ed, sellerIds, st, ed)
@@ -815,22 +819,18 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 
 	fmt.Println("totalMoneySlice:", len(totalMoneySlice))
 
-	//if req.SellerType == 1 {
-	//	departmentId = crm.SellerDepartmentId
-	//} else if req.SellerType == 2 {
-	//	departmentId = crm.RaiSellerDepartmentId
-	//} else if req.SellerType == 0 {
-	//	resp.FailMsg("查询错误", "请选择正确的销售类型", c)
-	//	return
-	//} else {
-	//	resp.FailMsg("查询错误", "请选择正确的销售类型", c)
-	//	return
-	//}
-
 	adminOB := new(crm.Admin)
 	adminPars := make([]interface{}, 0)
 	adminCond := ` 1=1 `
-	//adminCond = fmt.Sprintf(adminCond, departmentId)
+	if req.SellerType != 0 {
+		adminCond += ` AND department_id = ? `
+		adminPars = append(adminPars, departmentId)
+	}
+	if req.SellerIds != "" {
+		adminSellerIds := strings.Split(req.SellerIds, ",")
+		adminCond += ` AND admin_id IN ? `
+		adminPars = append(adminPars, adminSellerIds)
+	}
 
 	if !req.ShowResign {
 		adminCond += ` AND enabled = 1 `
@@ -842,17 +842,6 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		return
 	}
 
-	// 获取销售分组信息
-	sellerList, e := crmService.GetSellerDepartmentListWithEnable()
-	if e != nil {
-		resp.FailData("获取销售失败", "Err:"+e.Error(), c)
-		return
-	}
-	sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
-	for i := range sellerList {
-		sellerMap[sellerList[i].SellerId] = sellerList[i]
-	}
-
 	list := make([]*fms.CensusSellerInvoiceItem, 0)
 
 	for _, v := range adminList {

+ 3 - 1
models/crm/company_seller.go

@@ -48,10 +48,12 @@ type SellerAdminWithGroupList struct {
 type SellerAdminWithGroupTree struct {
 	SellerId   int                        `json:"seller_id"`
 	SellerName string                     `json:"seller_name"`
+	ProductId  int                        `json:"product_id"`
+	Selected   bool                       `json:"selected"`
 	Child      []SellerAdminWithGroupTree `json:"child"`
 }
 
 type SellerAdminList struct {
 	SellerId   int    `json:"seller_id"`
 	SellerName string `json:"seller_name"`
-}
+}

+ 58 - 47
services/crm/company_seller.go

@@ -8,7 +8,7 @@ import (
 
 // GetSellerDepartmentAndGroupMap 获取销售部门列表-包含大组和小组
 func GetSellerDepartmentListWithGroupAndTeam() (sellerList []*crm.SellerAdminWithGroupTeam, err error) {
-	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+	departmentIds := []int{crm.SellerDepartmentId, crm.RaiSellerDepartmentId}
 	sellerList = make([]*crm.SellerAdminWithGroupTeam, 0)
 	// 获取组别列表
 	groupCond := "department_id in (?)"
@@ -91,11 +91,10 @@ func GetSellerTeamGroupMap() (teamGroupMap map[int]*crm.SysGroup, err error) {
 	return
 }
 
-
 // GetSellerDepartmentList 获取销售部门列表-大组
 func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
 	// 获取组别列表
-	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+	departmentIds := []int{crm.SellerDepartmentId, crm.RaiSellerDepartmentId}
 	groupCond := "department_id in (?)"
 	groupPars := make([]interface{}, 0)
 	groupPars = append(groupPars, departmentIds)
@@ -110,7 +109,7 @@ func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
 	for i := range groupList {
 		if groupList[i].ParentId > 0 {
 			teamMap[groupList[i].GroupId] = groupList[i]
-		}else{
+		} else {
 			groupMap[groupList[i].GroupId] = groupList[i]
 		}
 	}
@@ -132,41 +131,47 @@ func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
 	ficcList := make([]crm.SellerAdminList, 0)
 	raiList := make([]crm.SellerAdminList, 0)
 	for i := range adminList {
+		var productId int
 		v := crm.SellerAdminList{
-			SellerId:    adminList[i].AdminId,
-			SellerName:  adminList[i].RealName,
+			SellerId:   adminList[i].AdminId,
+			SellerName: adminList[i].RealName,
 		}
 		if adminList[i].DepartmentId == crm.SellerDepartmentId {
 			ficcList = append(ficcList, v)
-		}else if adminList[i].DepartmentId == crm.RaiSellerDepartmentId {
+			productId = 1
+		} else if adminList[i].DepartmentId == crm.RaiSellerDepartmentId {
 			raiList = append(raiList, v)
+			productId = 2
 		}
 		if t, ok := teamMap[adminList[i].GroupId]; ok { // 如果销售是在三级分组下面,则找到对应的二级分组
 			if g, ok1 := groupMap[t.ParentId]; ok1 {
 				tmp := crm.SellerAdminWithGroupTree{
-					SellerId:    adminList[i].AdminId,
-					SellerName:  adminList[i].RealName,
-					Child: nil,
+					SellerId:   adminList[i].AdminId,
+					SellerName: adminList[i].RealName,
+					ProductId:  productId,
+					Child:      nil,
 				}
 				groupSeller[g.GroupId] = append(groupSeller[g.GroupId], tmp)
-			}else{
-				fmt.Println("adminList[i]:",adminList[i].AdminId)
+			} else {
+				fmt.Println("adminList[i]:", adminList[i].AdminId)
 				err = errors.New("找不到对应的销售分组")
 				return
 			}
-		}else{
+		} else {
 			if g, ok1 := groupMap[adminList[i].GroupId]; ok1 {
 				tmp := crm.SellerAdminWithGroupTree{
-					SellerId:    adminList[i].AdminId,
-					SellerName:  adminList[i].RealName,
-					Child: nil,
+					SellerId:   adminList[i].AdminId,
+					SellerName: adminList[i].RealName,
+					ProductId:  productId,
+					Child:      nil,
 				}
 				groupSeller[g.GroupId] = append(groupSeller[g.GroupId], tmp)
-			}else{
+			} else {
 				tmp := crm.SellerAdminWithGroupTree{
-					SellerId:    adminList[i].AdminId,
-					SellerName:  adminList[i].RealName,
-					Child: nil,
+					SellerId:   adminList[i].AdminId,
+					SellerName: adminList[i].RealName,
+					ProductId:  productId,
+					Child:      nil,
 				}
 				departmentMap[adminList[i].DepartmentId] = append(departmentMap[adminList[i].DepartmentId], tmp)
 			}
@@ -176,27 +181,34 @@ func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
 	for k, v := range groupMap {
 		child, _ := groupSeller[k]
 		tmp := crm.SellerAdminWithGroupTree{
-			SellerId:   k,
+			SellerId:   k+10000,
 			SellerName: v.GroupName,
 			Child:      child,
 		}
+		if v.DepartmentId == crm.SellerDepartmentId {
+			tmp.ProductId = 1
+		} else if v.DepartmentId == crm.RaiSellerDepartmentId {
+			tmp.ProductId = 2
+		}
 		departmentMap[v.DepartmentId] = append(departmentMap[v.DepartmentId], tmp)
 	}
 	//分部门
 	allTitleMap := map[int]string{
-		crm.SellerDepartmentId:"FICC销售",
-		crm.RaiSellerDepartmentId:"权益销售",
+		crm.SellerDepartmentId:    "FICC销售",
+		crm.RaiSellerDepartmentId: "权益销售",
 	}
 	ficcTree, _ := departmentMap[crm.SellerDepartmentId]
 	raiTree, _ := departmentMap[crm.RaiSellerDepartmentId]
 	tmp1 := crm.SellerAdminWithGroupTree{
 		SellerId:   crm.SellerDepartmentId,
 		SellerName: allTitleMap[crm.SellerDepartmentId],
+		ProductId:  1,
 		Child:      ficcTree,
 	}
 	tmp2 := crm.SellerAdminWithGroupTree{
 		SellerId:   crm.RaiSellerDepartmentId,
 		SellerName: allTitleMap[crm.RaiSellerDepartmentId],
+		ProductId:  2,
 		Child:      raiTree,
 	}
 	allList := make([]crm.SellerAdminWithGroupTree, 0)
@@ -209,8 +221,8 @@ func GetSellerDepartmentList() (resp crm.SellerAdminWithGroupList, err error) {
 }
 
 // GetSellerDepartmentAndGroupMap 获取销售部门列表-包含大组和小组
-func GetSellerDepartmentListWithGroupAndTeamByDepartment() (ficcList []*crm.SellerAdminWithGroupTeam,raiList []*crm.SellerAdminWithGroupTeam, err error) {
-	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+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)
 	// 获取组别列表
@@ -274,7 +286,7 @@ func GetSellerDepartmentListWithGroupAndTeamByDepartment() (ficcList []*crm.Sell
 // GetSellerList 获取销售部门列表-大组和小组
 func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 	// 获取组别列表
-	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+	departmentIds := []int{crm.SellerDepartmentId, crm.RaiSellerDepartmentId}
 	groupCond := "department_id in (?)"
 	groupPars := make([]interface{}, 0)
 	groupPars = append(groupPars, departmentIds)
@@ -285,7 +297,7 @@ func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 		return
 	}
 	fullGroupMap := make(map[int]*crm.SysGroup)
-	for _, v := range fullGroups{
+	for _, v := range fullGroups {
 		fullGroupMap[v.GroupId] = v
 	}
 	// 获取销售部门所有销售信息
@@ -305,25 +317,25 @@ func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 	groupListMap := make(map[int][]crm.SellerAdminWithGroupTree)
 	teamListMap := make(map[int][]crm.SellerAdminWithGroupTree)
 	//departmentHasMap := make(map[int]bool)
-	groupHasMap  := make(map[int]bool)
+	groupHasMap := make(map[int]bool)
 	teamHasMap := make(map[int]bool)
 
 	for _, v := range adminList {
 		tmp := crm.SellerAdminWithGroupTree{
-			SellerId:    v.AdminId,
-			SellerName:  v.RealName,
+			SellerId:   v.AdminId,
+			SellerName: v.RealName,
 		}
 		if v.GroupId > 0 {
 			if groupInfo, ok := fullGroupMap[v.GroupId]; ok {
 				if groupInfo.ParentId > 0 {
 					teamListMap[v.GroupId] = append(teamListMap[v.GroupId], tmp)
-				}else{
+				} else {
 					groupListMap[groupInfo.GroupId] = append(groupListMap[groupInfo.GroupId], tmp)
 				}
-			}else {
+			} else {
 				departmentListMap[v.DepartmentId] = append(departmentListMap[v.DepartmentId], tmp)
 			}
-		}else if v.DepartmentId > 0{
+		} else if v.DepartmentId > 0 {
 			departmentListMap[v.DepartmentId] = append(departmentListMap[v.DepartmentId], tmp)
 		}
 	}
@@ -331,12 +343,12 @@ func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 		var team1 crm.SellerAdminWithGroupTree
 		//处理小组
 		if groupInfo.ParentId > 0 {
-			if _, ok2 :=teamHasMap[groupInfo.GroupId]; !ok2 {
+			if _, ok2 := teamHasMap[groupInfo.GroupId]; !ok2 {
 				if len(teamListMap[groupInfo.GroupId]) > 0 {
 					team1 = crm.SellerAdminWithGroupTree{
-						SellerId:    groupInfo.GroupId,
-						SellerName:  groupInfo.GroupName,
-						Child: teamListMap[groupInfo.GroupId],
+						SellerId:   groupInfo.GroupId,
+						SellerName: groupInfo.GroupName,
+						Child:      teamListMap[groupInfo.GroupId],
 					}
 					teamHasMap[groupInfo.GroupId] = true
 					groupListMap[groupInfo.ParentId] = append(groupListMap[groupInfo.ParentId], team1)
@@ -348,12 +360,12 @@ func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 		var group1 crm.SellerAdminWithGroupTree
 		//处理大组
 		if groupInfo.ParentId == 0 {
-			if _, ok2 :=groupHasMap[groupInfo.GroupId]; !ok2 {
+			if _, ok2 := groupHasMap[groupInfo.GroupId]; !ok2 {
 				if len(groupListMap[groupInfo.GroupId]) > 0 {
 					group1 = crm.SellerAdminWithGroupTree{
-						SellerId:    groupInfo.GroupId,
-						SellerName:  groupInfo.GroupName,
-						Child: groupListMap[groupInfo.GroupId],
+						SellerId:   groupInfo.GroupId,
+						SellerName: groupInfo.GroupName,
+						Child:      groupListMap[groupInfo.GroupId],
 					}
 					groupHasMap[groupInfo.GroupId] = true
 					departmentListMap[groupInfo.DepartmentId] = append(departmentListMap[groupInfo.DepartmentId], group1)
@@ -363,11 +375,10 @@ func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 		}
 	}
 
-
 	//分部门
 	allTitleMap := map[int]string{
-		crm.SellerDepartmentId:"FICC销售",
-		crm.RaiSellerDepartmentId:"权益销售",
+		crm.SellerDepartmentId:    "FICC销售",
+		crm.RaiSellerDepartmentId: "权益销售",
 	}
 	tmp1 := crm.SellerAdminWithGroupTree{
 		SellerId:   crm.SellerDepartmentId,
@@ -377,7 +388,7 @@ func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 	tmp2 := crm.SellerAdminWithGroupTree{
 		SellerId:   crm.RaiSellerDepartmentId,
 		SellerName: allTitleMap[crm.RaiSellerDepartmentId],
-		Child:       departmentListMap[crm.RaiSellerDepartmentId],
+		Child:      departmentListMap[crm.RaiSellerDepartmentId],
 	}
 	allList := make([]crm.SellerAdminWithGroupTree, 0)
 	allList = append(allList, tmp1)
@@ -389,7 +400,7 @@ func GetSellerList() (resp crm.SellerAdminWithGroupList, err error) {
 
 // 获取销售部门列表-包含禁用
 func GetSellerDepartmentListWithEnable() (sellerList []*crm.SellerAdminWithGroupTeam, err error) {
-	departmentIds := []int{crm.SellerDepartmentId,crm.RaiSellerDepartmentId}
+	departmentIds := []int{crm.SellerDepartmentId, crm.RaiSellerDepartmentId}
 	sellerList = make([]*crm.SellerAdminWithGroupTeam, 0)
 	// 获取组别列表
 	groupCond := "department_id in (?)"
@@ -443,4 +454,4 @@ func GetSellerDepartmentListWithEnable() (sellerList []*crm.SellerAdminWithGroup
 		sellerList = append(sellerList, v)
 	}
 	return
-}
+}