Kaynağa Gözat

Merge branch 'feature/crm14.9_contract_change' into debug

xyxie 1 yıl önce
ebeveyn
işleme
1c30b2acdb

+ 36 - 3
controllers/statistic_report.go

@@ -6402,6 +6402,7 @@ func (this *StatisticReportController) UnusualRenewCompanyList() {
 
 	// 按月分组
 	monthMap := make(map[string]int)
+	monthCompanyMap := make(map[string]struct{})
 	monthList := make([]string, 0)
 	tmpDate, _ := time.ParseInLocation(utils.FormatYearMonthDate, startDate, time.Local)
 	tmpEndDate, _ := time.ParseInLocation(utils.FormatYearMonthDate, endDate, time.Local)
@@ -6411,8 +6412,36 @@ func (this *StatisticReportController) UnusualRenewCompanyList() {
 		tmpDate = tmpDate.AddDate(0, 1, 0)
 
 	}
+	// 只查询咨询组销售下的客户
+	groupId := 0
+	if utils.RunMode == "release" {
+		groupId = 37
+	} else {
+		groupId = 61
+	}
+	subAdmins, err := system.GetAdminByGroupId(groupId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取销售失败"
+		br.ErrMsg = "获取销售失败,Err:" + err.Error()
+		return
+	}
+	if len(subAdmins) == 0 {
+		resp = &company.GetUnusualRenewListGroupMonthResp{
+			List: allList,
+		}
+		br.Ret = 200
+		br.Success = true
+		br.Msg = "获取成功"
+		br.Data = resp
+		return
+	}
+	subAdminIds := make([]string, 0)
+	for _, v := range subAdmins {
+		subAdminIds = append(subAdminIds, strconv.Itoa(v.AdminId))
+	}
+	shareSellerIds := strings.Join(subAdminIds, ",")
 
-	list, err := company.GetUnusualRenewList(startDateTimer, endDateTimer, productId)
+	list, err := company.GetUnusualRenewList(startDateTimer, endDateTimer, productId, shareSellerIds)
 	if err != nil {
 		br.Msg = "数据异常"
 		br.ErrMsg = "数据异常,Err:" + err.Error()
@@ -6421,8 +6450,12 @@ func (this *StatisticReportController) UnusualRenewCompanyList() {
 	if len(list) > 0 {
 		for _, v := range list {
 			t := v.ModifyTime.Format(utils.FormatYearMonthDate)
-			if num, ok := monthMap[t]; ok {
-				monthMap[t] = num + 1
+			name := fmt.Sprintf("%s_%d", t, v.CompanyId)
+			if _, ok := monthCompanyMap[name]; !ok {
+				if num, ok1 := monthMap[t]; ok1 {
+					monthMap[t] = num + 1
+				}
+				monthCompanyMap[name] = struct{}{}
 			}
 		}
 	}

+ 3 - 2
models/company/company_renewal_record.go

@@ -44,7 +44,7 @@ WHERE
     AND a.source = 1 
 	AND a.product_id = ?
 GROUP BY
-	a.seller_id;
+	a.share_seller_id;
 `
 	_, err = o.Raw(sql, startDate, endDate, productId).QueryRows(&list)
 
@@ -78,7 +78,7 @@ type GetUnusualRenewListGroupMonthResp struct {
 }
 
 // GetUnusualRenewList 获取未续约公司列表
-func GetUnusualRenewList(startDate, endDate time.Time, productId int) (list []*CompanyRenewalRecord, err error) {
+func GetUnusualRenewList(startDate, endDate time.Time, productId int, shareSellerIds string) (list []*CompanyRenewalRecord, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT
 	* 
@@ -89,6 +89,7 @@ WHERE
 	AND modify_time BETWEEN ? 
 	AND ? 
 	AND product_id = ?
+	AND share_seller_id in (` + shareSellerIds + `)
 `
 	_, err = o.Raw(sql, startDate, endDate, productId).QueryRows(&list)
 

+ 3 - 2
services/statistic_report/unusual_renew_company.go

@@ -136,7 +136,8 @@ func getUnusualRenewSectionData(productId int, startDate, endDate time.Time, ch
 			if !ok {
 				tmp = 0
 			}
-			unusualRenewMap[v.ShareSellerId] = tmp + 1
+			companyIdSlice := strings.Split(v.CompanyIds, ",")
+			unusualRenewMap[v.ShareSellerId] = tmp + len(companyIdSlice)
 
 			// 客户id
 			tmpCompanyIdList2, ok := unusualRenewCompanyIdListMap[v.ShareSellerId]
@@ -145,7 +146,7 @@ func getUnusualRenewSectionData(productId int, startDate, endDate time.Time, ch
 			}
 			unusualRenewCompanyIdListMap[v.ShareSellerId] = append(tmpCompanyIdList2, fmt.Sprint(v.CompanyIds))
 
-			unusualRenewCompanyTotal++
+			unusualRenewCompanyTotal += len(companyIdSlice)
 		}
 
 		for sellerId, tmpCompanyIdList := range unusualRenewCompanyIdListMap {