瀏覽代碼

Merge branch 'feature/crm14.9_contract_change' of hongze/hz_crm_api into master

xyxie 1 年之前
父節點
當前提交
4db5a83740
共有 2 個文件被更改,包括 34 次插入18 次删除
  1. 32 16
      controllers/statistic_report.go
  2. 2 2
      models/company/company_renewal_record.go

+ 32 - 16
controllers/statistic_report.go

@@ -6301,7 +6301,8 @@ func (this *StatisticReportController) UnusualRenewCompanyStatistics() {
 		List:        list,
 		SummaryList: summaryList,
 	}
-
+	unusualRenewTotal := make(map[int]int)
+	adminDataUnusualRenewTotal := make(map[int]int)
 	// 每日期组数据的汇总客户id
 	companyIdIndexMap := make(map[int][]string)
 	for k, v := range subAdmins {
@@ -6315,22 +6316,26 @@ func (this *StatisticReportController) UnusualRenewCompanyStatistics() {
 				EndDate:         adminData.EndDate,
 			})
 
+			unusualRenewTotal[index] = unusualRenewTotal[index] + adminData.UnusualRenewMap[v.AdminId]
+
 			if adminData.UnusualRenewIdMap[v.AdminId] != `` {
 				tmpCompanyIdList, ok := companyIdIndexMap[index]
 				if !ok {
 					tmpCompanyIdList = make([]string, 0)
 				}
 				companyIdIndexMap[index] = append(tmpCompanyIdList, adminData.UnusualRenewIdMap[v.AdminId])
+				adminDataUnusualRenewTotal[index] = adminData.FormalCompanyTotal
 			}
 
 			if k == 0 {
-				unusualRate := ``
+				/*unusualRate := ``
 				if adminData.UnusualRenewTotal > 0 && adminData.FormalCompanyTotal > 0 {
 					unusualRate = decimal.NewFromInt(int64(adminData.UnusualRenewTotal)*100).Div(decimal.NewFromInt(int64(adminData.FormalCompanyTotal))).Round(2).String() + `%`
-				}
+				}*/
+
 				summaryList = append(summaryList, statistic_report.SummaryUnusualRenewRecordNum{
-					UnusualRenewNum: adminData.UnusualRenewTotal,
-					UnusualRate:     unusualRate,
+					UnusualRenewNum: 0,
+					UnusualRate:     "0",
 				})
 			}
 		}
@@ -6343,6 +6348,19 @@ func (this *StatisticReportController) UnusualRenewCompanyStatistics() {
 
 	// 汇总数据
 	for index, _ := range summaryList {
+		totalSum, ok1 := unusualRenewTotal[index]
+		if ok1 {
+			summaryList[index].UnusualRenewNum = totalSum
+			unusualRate := ``
+			formalCompanyTotal, ok2 := adminDataUnusualRenewTotal[index]
+			if ok2 {
+				if totalSum > 0 && formalCompanyTotal > 0 {
+					unusualRate = decimal.NewFromInt(int64(totalSum)*100).Div(decimal.NewFromInt(int64(formalCompanyTotal))).Round(2).String() + `%`
+					summaryList[index].UnusualRate = unusualRate
+				}
+			}
+
+		}
 		tmpCompanyIdList, ok := companyIdIndexMap[index]
 		if ok {
 			summaryList[index].UnusualRenewIds = strings.Join(tmpCompanyIdList, ",")
@@ -6412,20 +6430,18 @@ func (this *StatisticReportController) UnusualRenewCompanyList() {
 		tmpDate = tmpDate.AddDate(0, 1, 0)
 
 	}
-	// 只查询咨询组销售下的客户
-	groupId := 0
-	if utils.RunMode == "release" {
-		groupId = 37
-	} else {
-		groupId = 61
+	// 只查询ficc销售下的客户
+	roleTypeCode := "('ficc_seller','ficc_group','ficc_team')"
+	researcherList, err := roadshow.GetSellerList(roleTypeCode, "")
+	if err != nil {
+		return
 	}
-	subAdmins, err := system.GetAdminByGroupId(groupId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取销售失败"
 		br.ErrMsg = "获取销售失败,Err:" + err.Error()
 		return
 	}
-	if len(subAdmins) == 0 {
+	if len(researcherList) == 0 {
 		resp = &company.GetUnusualRenewListGroupMonthResp{
 			List: allList,
 		}
@@ -6436,12 +6452,12 @@ func (this *StatisticReportController) UnusualRenewCompanyList() {
 		return
 	}
 	subAdminIds := make([]string, 0)
-	for _, v := range subAdmins {
+	for _, v := range researcherList {
 		subAdminIds = append(subAdminIds, strconv.Itoa(v.AdminId))
 	}
-	shareSellerIds := strings.Join(subAdminIds, ",")
+	sellerIds := strings.Join(subAdminIds, ",")
 
-	list, err := company.GetUnusualRenewList(startDateTimer, endDateTimer, productId, shareSellerIds)
+	list, err := company.GetUnusualRenewList(startDateTimer, endDateTimer, productId, sellerIds)
 	if err != nil {
 		br.Msg = "数据异常"
 		br.ErrMsg = "数据异常,Err:" + err.Error()

+ 2 - 2
models/company/company_renewal_record.go

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