Browse Source

Merge branch 'crm/crm_16.7' of http://8.136.199.33:3000/hongze/hz_crm_api into debug

zhangchuanxing 2 weeks ago
parent
commit
34c58aabaf
2 changed files with 111 additions and 148 deletions
  1. 110 147
      controllers/statistic/rai_data_summary.go
  2. 1 1
      models/statistic_report/rai_data_summary.go

+ 110 - 147
controllers/statistic/rai_data_summary.go

@@ -62,6 +62,12 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 
 	adminIdArr := strings.Split(adminId, ",")
 	serviceAdminIdArr := strings.Split(serviceAdminId, ",")
+	if adminId == "" {
+		adminIdArr = make([]string, 0)
+	}
+	if serviceAdminId == "" {
+		serviceAdminIdArr = make([]string, 0)
+	}
 
 	dataTypeArr := []string{}
 	if dataType == "季度" {
@@ -96,6 +102,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
 		return
 	}
+
 	var sellerDevelop []*system.AdminItem     // 开拓组销售
 	var sellerService []*system.AdminItem     // 服务组销售
 	var sellerDevelopIds = make(map[int]bool) // 开拓组销售的map
@@ -110,6 +117,23 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		mapsellerId[v.AdminId] = true
 	}
 
+	mapsellerDevelop := make(map[int]bool) // 开拓组销售Map
+	mapsellerService := make(map[int]bool) // 服务组销售Map
+	condition = " AND role_type_code IN ('rai_seller','rai_group')   "
+	sellerListAll, err := system.GetSysUserItemsOrderByCreated(condition, pars)
+	if err != nil {
+		br.Msg = "获取管理账号失败"
+		br.ErrMsg = "获取管理账号失败,Err:" + err.Error()
+		return
+	}
+
+	for _, v := range sellerListAll {
+		if strings.Contains(v.RealName, "6") {
+			mapsellerService[v.AdminId] = true
+		} else {
+			mapsellerDevelop[v.AdminId] = true
+		}
+	}
 	//拼接起始时间查询
 	startDate := fmt.Sprintf("%d-01-01", startYear)
 	endDate := fmt.Sprintf("%d-12-31", endYear)
@@ -188,6 +212,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	mapNewCustomerInvoicingMoney := make(map[string]float64)        // 财务系统新客开票金额(金额)
 	mapNewCustomerPaymentsReceivedMoney := make(map[string]float64) // 财务系统新客到款金额(金额)
 
+	mapNewContractMoneyServer := make(map[string]float64)              // 新签合同(金额)
+	mapNewContractNumServer := make(map[string]int)                    // 新签合同(数量)
 	mapExpiredContractMoneyServer := make(map[string]float64)          // 到期合同(金额)
 	mapExpiredContractNumServer := make(map[string]int)                // 到期合同(数量)_服务组
 	mapExpiredContractCompanyNumServer := make(map[string]int)         // 到期公司(数量)_服务组
@@ -209,32 +235,12 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	var keySigned string
 
 	mapCompanyData := make(map[string]bool)
-	//新签部分的数据
+	//新签部分的数据(开拓组)
 	for _, v := range listRaiData {
-		//if !mapsellerId[v.SellerIdInit] {
-		//	continue
-		//}
-
-		startDateTime := utils.StrDateToDate(v.StartDate)
-		monthNum := startDateTime.Month()
-		yearStr := strconv.Itoa(startDateTime.Year())
-		if dataType == "季度" {
-			if monthNum < 4 {
-				yearStr += "Q1"
-			} else if monthNum > 3 && monthNum < 7 {
-				yearStr += "Q2"
-			} else if monthNum > 6 && monthNum < 10 {
-				yearStr += "Q3"
-			} else if monthNum > 9 {
-				yearStr += "Q4"
-			}
-		} else if dataType == "半年度" {
-			if monthNum < 7 {
-				yearStr += "H1"
-			} else {
-				yearStr += "H2"
-			}
+		if !mapsellerDevelop[v.SellerIdInit] {
+			continue
 		}
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
 		keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdLast)
@@ -262,32 +268,44 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		}
 	}
 
+	//新签部分的数据(服务组)
+	for _, v := range listRaiData {
+		if !mapsellerDevelop[v.ShareSellerInit] {
+			continue
+		}
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
+
+		keyMap = fmt.Sprint(yearStr, "_Server_", v.SellerIdLast)
+		keySigned = fmt.Sprint(yearStr, "_Server_", v.CompanyId, "_SID_", v.SellerIdLast)
+		keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
+
+		if v.RaiContractType == "新签合同" {
+			mapNewContractMoneyServer[keyMap] += v.Money
+			mapNewContractNumServer[keyMap]++
+			mapNewContractMoneyServer[keyMapTtoal] += v.Money
+			mapNewContractNumServer[keyMapTtoal]++
+		}
+
+		mapSignedClientMoneyServer[keyMap] += v.Money
+		mapSignedClientMoneyServer[keyMapTtoal] += v.Money
+
+		if !mapCompanyData[keySigned] && v.RaiContractType == "新签合同" {
+			mapSignedClientNumServer[keyMap]++
+			mapSignedClientNumServer[keyMapTtoal]++
+			mapCompanyData[keySigned] = true
+		}
+	}
+
 	//续约部分的数据(开拓组)
 	mapKeyMapCompanyData := make(map[string]bool)
 	for _, v := range listInheritData {
-		if len(adminIdArr) > 0 && utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
+		if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
 			continue
 		}
-		startDateTime := utils.StrDateToDate(v.InheritEndDate)
-		monthNum := startDateTime.Month()
-		yearStr := strconv.Itoa(startDateTime.Year())
-		if dataType == "季度" {
-			if monthNum < 4 {
-				yearStr += "Q1"
-			} else if monthNum > 3 && monthNum < 7 {
-				yearStr += "Q2"
-			} else if monthNum > 6 && monthNum < 10 {
-				yearStr += "Q3"
-			} else if monthNum > 9 {
-				yearStr += "Q4"
-			}
-		} else if dataType == "半年度" {
-			if monthNum < 7 {
-				yearStr += "H1"
-			} else {
-				yearStr += "H2"
-			}
+		if !mapsellerDevelop[v.SellerIdInit] {
+			continue
 		}
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
@@ -320,29 +338,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 
 	//续约部分的数据(服务组)
 	for _, v := range listInheritData {
-		if len(serviceAdminIdArr) > 0 && utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdLast)) {
+		if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdLast)) {
 			continue
 		}
-		startDateTime := utils.StrDateToDate(v.InheritEndDate)
-		monthNum := startDateTime.Month()
-		yearStr := strconv.Itoa(startDateTime.Year())
-		if dataType == "季度" {
-			if monthNum < 4 {
-				yearStr += "Q1"
-			} else if monthNum > 3 && monthNum < 7 {
-				yearStr += "Q2"
-			} else if monthNum > 6 && monthNum < 10 {
-				yearStr += "Q3"
-			} else if monthNum > 9 {
-				yearStr += "Q4"
-			}
-		} else if dataType == "半年度" {
-			if monthNum < 7 {
-				yearStr += "H1"
-			} else {
-				yearStr += "H2"
-			}
+		if !mapsellerService[v.ShareSellerIdLast] {
+			continue
 		}
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_", v.CompanyId)
@@ -378,29 +380,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	mapKeyMapCompanyNoData := make(map[string]bool)
 	//开拓组数据
 	for _, v := range listEndData {
-		if len(adminIdArr) > 0 && utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
+		if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.SellerIdLast)) {
 			continue
 		}
-		startDateTime := utils.StrDateToDate(v.EndDate)
-		monthNum := startDateTime.Month()
-		yearStr := strconv.Itoa(startDateTime.Year())
-		if dataType == "季度" {
-			if monthNum < 4 {
-				yearStr += "Q1"
-			} else if monthNum > 3 && monthNum < 7 {
-				yearStr += "Q2"
-			} else if monthNum > 6 && monthNum < 10 {
-				yearStr += "Q3"
-			} else if monthNum > 9 {
-				yearStr += "Q4"
-			}
-		} else if dataType == "半年度" {
-			if monthNum < 7 {
-				yearStr += "H1"
-			} else {
-				yearStr += "H2"
-			}
+		if !mapsellerDevelop[v.SellerIdInit] {
+			continue
 		}
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
@@ -440,29 +426,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 
 	//服务组数据
 	for _, v := range listEndData {
-		if len(serviceAdminIdArr) > 0 && utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdLast)) {
+		if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.ShareSellerIdLast)) {
 			continue
 		}
-		startDateTime := utils.StrDateToDate(v.EndDate)
-		monthNum := startDateTime.Month()
-		yearStr := strconv.Itoa(startDateTime.Year())
-		if dataType == "季度" {
-			if monthNum < 4 {
-				yearStr += "Q1"
-			} else if monthNum > 3 && monthNum < 7 {
-				yearStr += "Q2"
-			} else if monthNum > 6 && monthNum < 10 {
-				yearStr += "Q3"
-			} else if monthNum > 9 {
-				yearStr += "Q4"
-			}
-		} else if dataType == "半年度" {
-			if monthNum < 7 {
-				yearStr += "H1"
-			} else {
-				yearStr += "H2"
-			}
+		if !mapsellerService[v.ShareSellerIdLast] {
+			continue
 		}
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_", v.CompanyId)
@@ -507,29 +477,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 
 	//开拓组财务系统数据
 	for _, v := range listFmsData {
-		if len(adminIdArr) > 0 && utils.InArrayByStr(adminIdArr, strconv.Itoa(v.RaiSellerId)) {
+		if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.RaiSellerId)) {
 			continue
 		}
-		startDateTime := v.StartDate
-		monthNum := startDateTime.Month()
-		yearStr := strconv.Itoa(startDateTime.Year())
-		if dataType == "季度" {
-			if monthNum < 4 {
-				yearStr += "Q1"
-			} else if monthNum > 3 && monthNum < 7 {
-				yearStr += "Q2"
-			} else if monthNum > 6 && monthNum < 10 {
-				yearStr += "Q3"
-			} else if monthNum > 9 {
-				yearStr += "Q4"
-			}
-		} else if dataType == "半年度" {
-			if monthNum < 7 {
-				yearStr += "H1"
-			} else {
-				yearStr += "H2"
-			}
-		}
+		//if !mapsellerDevelop[v.RaiSellerId] {
+		//	continue
+		//}
+		yearStr := getYearStar(v.StartDate, dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
 		keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
@@ -550,29 +504,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 
 	//服务组财务系统数据
 	for _, v := range listFmsData {
-		if len(serviceAdminIdArr) > 0 && utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.RaiSellerId)) {
+		if len(serviceAdminIdArr) > 0 && !utils.InArrayByStr(serviceAdminIdArr, strconv.Itoa(v.RaiSellerId)) {
 			continue
 		}
-		startDateTime := v.StartDate
-		monthNum := startDateTime.Month()
-		yearStr := strconv.Itoa(startDateTime.Year())
-		if dataType == "季度" {
-			if monthNum < 4 {
-				yearStr += "Q1"
-			} else if monthNum > 3 && monthNum < 7 {
-				yearStr += "Q2"
-			} else if monthNum > 6 && monthNum < 10 {
-				yearStr += "Q3"
-			} else if monthNum > 9 {
-				yearStr += "Q4"
-			}
-		} else if dataType == "半年度" {
-			if monthNum < 7 {
-				yearStr += "H1"
-			} else {
-				yearStr += "H2"
-			}
+		if !mapsellerService[v.RaiSellerId] {
+			continue
 		}
+		yearStr := getYearStar(v.StartDate, dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
 		keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
@@ -771,7 +709,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 				sellerServiceIds = append(sellerServiceIds, sellerItem.SellerId)
 				sellerItem.SellerName = vS.RealName
 				sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMap])
-				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMap], 2), " / ", mapNewContractNum[keyMap])                         // 新签合同(金额/数量)-(数据)
+				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoneyServer[keyMap], 2), " / ", mapNewContractNumServer[keyMap])             // 新签合同(金额/数量)-(数据)
 				sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoneyServer[keyMap], 2), " / ", mapExpiredContractNumServer[keyMap]) //"到期合同(金额/数量)-(数据)"
 				sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoneyServer[keyMap], 2), " / ", mapRenewedContractNumServer[keyMap]) // "续约合同(金额/数量)-(数据)"
 				var renewalRateMoey string
@@ -829,7 +767,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 				sellerItem.SellerId = strings.Join(sellerServiceIds, ",")
 				sellerItem.SellerName = "服务组合计"
 				sellerItem.AddTrialCount = fmt.Sprint(mapAddTrialNum[keyMapTtoalServer])
-				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoney[keyMapTtoalServer], 2), " / ", mapNewContractNum[keyMapTtoalServer])                         // 新签合同(金额/数量)-(数据)
+				sellerItem.NewContractData = fmt.Sprint(utils.SubFloatToString(mapNewContractMoneyServer[keyMapTtoalServer], 2), " / ", mapNewContractNumServer[keyMapTtoalServer])             // 新签合同(金额/数量)-(数据)
 				sellerItem.ExpiredContractData = fmt.Sprint(utils.SubFloatToString(mapExpiredContractMoneyServer[keyMapTtoalServer], 2), " / ", mapExpiredContractNumServer[keyMapTtoalServer]) //"到期合同(金额/数量)-(数据)"
 				sellerItem.RenewedContractData = fmt.Sprint(utils.SubFloatToString(mapRenewedContractMoneyServer[keyMapTtoalServer], 2), " / ", mapRenewedContractNumServer[keyMapTtoalServer]) // "续约合同(金额/数量)-(数据)"
 				var renewalRateMoey string
@@ -1772,3 +1710,28 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// 时间筛选项的转换
+func getYearStar(startDate time.Time, dataType string) (yearStr string) {
+	startDateTime := startDate
+	monthNum := startDateTime.Month()
+	yearStr = strconv.Itoa(startDateTime.Year())
+	if dataType == "季度" {
+		if monthNum < 4 {
+			yearStr += "Q1"
+		} else if monthNum > 3 && monthNum < 7 {
+			yearStr += "Q2"
+		} else if monthNum > 6 && monthNum < 10 {
+			yearStr += "Q3"
+		} else if monthNum > 9 {
+			yearStr += "Q4"
+		}
+	} else if dataType == "半年度" {
+		if monthNum < 7 {
+			yearStr += "H1"
+		} else {
+			yearStr += "H2"
+		}
+	}
+	return
+}

+ 1 - 1
models/statistic_report/rai_data_summary.go

@@ -85,7 +85,7 @@ type IncrementalList struct {
 	SellerNameInit    string `description:"权益初始化销售"`
 	SellerIdInit      int    `description:"权益初始化销售ID"`
 	SellerIdLast      int    `description:"合同到期之前最后所属销售ID"`
-	ShareSellerInit   string `description:"共享销售员"`
+	ShareSellerInit   int    `description:"共享销售员"`
 	ShareSellerIdLast int    `description:"合同到期之前最后共享销售员ID"`
 	SysRealName       string `description:"操作者名称"`
 	Operation         string `description:"操作"`