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
3bc9851f8b

+ 502 - 21
controllers/statistic/rai_data_summary.go

@@ -9,6 +9,7 @@ import (
 	"hongze/hz_crm_api/models/fms"
 	"hongze/hz_crm_api/models/statistic_report"
 	"hongze/hz_crm_api/models/system"
+	"hongze/hz_crm_api/services"
 	cygxService "hongze/hz_crm_api/services/cygx"
 	"hongze/hz_crm_api/utils"
 	"strconv"
@@ -151,22 +152,6 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	mapNewCustomerInvoicingMoney := make(map[string]float64)        // 财务系统新客开票金额(金额)
 	mapNewCustomerPaymentsReceivedMoney := make(map[string]float64) // 财务系统新客到款金额(金额)
 
-	//mapAddTrialNumTotal := make(map[string]float64)                      // 新增试用-(数据)_总计
-	//mapNewContractMoneyTotal := make(map[string]float64)                 // 新签合同(金额)_总计
-	//mapNewContractNumTotal := make(map[string]int)                       // 新签合同(数量)_总计
-	//mapExpiredContractMoneyTotal := make(map[string]float64)             // 到期合同(金额)_总计
-	//mapExpiredContractNumTotal := make(map[string]int)                   // 到期合同(数量)_总计
-	//mapRenewedContractMoneyTotal := make(map[string]float64)             // 续约合同(金额)_总计
-	//mapRenewedContractNumTotal := make(map[string]int)                   // 续约合同(数量)_总计
-	//confirmedNoRenewalContractMoneyTotal := make(map[string]float64)     // 确认不续约合同(金额)_总计
-	//confirmedNoRenewalContractNumTotal := make(map[string]int)           // 确认不续约合同(数量)_总计
-	//mapSignedClientNumTotal := make(map[string]int)                      // 签约客户(数量)_总计
-	//mapSignedClientMoneyTotal := make(map[string]float64)                // 签约客户(金额)_总计
-	//mapInvoiceAmountMoneyTotal := make(map[string]float64)               // 财务系统开票金额(金额)_总计
-	//mapPaymentAmountMoneyTotal := make(map[string]float64)               // 财务系统到款金额(金额)_总计
-	//mapNewCustomerInvoicingMoneyTotal := make(map[string]float64)        // 财务系统新客开票金额(金额)_总计
-	//mapNewCustomerPaymentsReceivedMoneyTotal := make(map[string]float64) // 财务系统新客到款金额(金额)_总计
-
 	var keyMap string
 	var keyMapTtoal string
 	var keyMapTtoalServer string
@@ -264,7 +249,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 			}
 		}
 
-		keyMap := fmt.Sprint(yearStr, "_", v.RaiSellerId)
+		keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
 
 		if sellerDevelopIds[v.RaiSellerId] == true {
 			keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
@@ -315,7 +300,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 				yearStr += "H2"
 			}
 		}
-		keyMap := fmt.Sprint(yearStr, "_", v.SysUserId)
+		keyMap = fmt.Sprint(yearStr, "_", v.SysUserId)
 		mapAddTrialNum[keyMap]++
 
 		//var keyMapTtoal string
@@ -632,10 +617,10 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		startDate = year + "-01-01"
 		endDate = year + "-12-31"
 	}
-	fmt.Println(startDate)
-	fmt.Println(endDate)
+
 	resp := new(statistic_report.RaiDataSummaryPopupTypeResp)
 	var listResp []*statistic_report.RaiDataSummaryDetailResp
+	var listGroup []*models.CompanyContractGroupList
 	var trialTotal int
 
 	var condition string
@@ -681,8 +666,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 				listResp = append(listResp, item)
 			}
 		}
-	case "新签合同":
 
+	case "新签合同":
 		if sellerId > 0 {
 			condition += ` AND a.seller_id_init = ? `
 			pars = append(pars, sellerId)
@@ -730,12 +715,508 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 				item.PermissionName = mappermissionName[v.CompanyContractId]
 				listResp = append(listResp, item)
 			}
+
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+
+		}
+
+	case "到期合同":
+
+		if sellerId > 0 {
+			condition += ` AND a.seller_id_last = ? `
+			pars = append(pars, sellerId)
+		}
+
+		condition += ` AND  a.status = 1  AND a.start_date >= ?  AND a.start_date <= ?   AND a.end_date < ? `
+		pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
+
+		total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		trialTotal = total
+		//列表页数据
+		tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if len(tmpList) > 0 {
+			var companyContractIds []int
+			for _, v := range tmpList {
+				companyContractIds = append(companyContractIds, v.CompanyContractId)
+			}
+
+			//合并合同所对应的权限
+			mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+			for _, v := range tmpList {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.SellerNameLast
+				item.StartDate = v.StartDate
+				item.EndDate = v.EndDate
+				item.Money = v.Money
+				item.PermissionName = mappermissionName[v.CompanyContractId]
+				listResp = append(listResp, item)
+			}
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+		}
+
+	case "续约合同":
+		if sellerId > 0 {
+			condition += ` AND a.seller_id_last = ? `
+			pars = append(pars, sellerId)
+		}
+
+		condition += ` AND  a.status = 1  AND a.start_date >= ?  AND a.start_date <= ?  `
+		pars = append(pars, startDate, endDate)
+		condition += `  AND a.rai_contract_type = ? `
+		pars = append(pars, "续约合同")
+
+		total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		trialTotal = total
+		//列表页数据
+		tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if len(tmpList) > 0 {
+			var companyContractIds []int
+			for _, v := range tmpList {
+				companyContractIds = append(companyContractIds, v.CompanyContractId)
+			}
+
+			//合并合同所对应的权限
+			mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+			for _, v := range tmpList {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.SellerNameLast
+				item.StartDate = v.StartDate
+				item.EndDate = v.EndDate
+				item.Money = v.Money
+				item.PermissionName = mappermissionName[v.CompanyContractId]
+				listResp = append(listResp, item)
+			}
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+		}
+
+	case "续约率":
+		if sellerId > 0 {
+			condition += ` AND a.seller_id_last = ? `
+			pars = append(pars, sellerId)
+		}
+
+		condition += " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? "
+		pars = append(pars, startDate, endDate)
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+		var renewedContractMoney float64   // 续约金额
+		var renewedContractCompany float64 // 续约客户数
+		maprenewedContractCompany := make(map[int]bool)
+
+		var expiredContractMoney float64   //到期金额
+		var expiredContractCompany float64 // 到期客户数
+		mapexpiredContractCompany := make(map[int]bool)
+
+		for _, v := range listRaiData {
+			renewedContractMoney += v.Money
+			if !maprenewedContractCompany[v.CompanyId] {
+				renewedContractCompany++
+				maprenewedContractCompany[v.CompanyId] = true
+			}
+			startDateTime := utils.StrDateToDate(v.StartDate)
+			if startDateTime.Before(time.Now().AddDate(0, 0, -1)) { //到期合同数据
+				expiredContractMoney += v.Money
+				if !mapexpiredContractCompany[v.CompanyId] {
+					expiredContractCompany++
+					mapexpiredContractCompany[v.CompanyId] = true
+				}
+			}
+		}
+
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(renewedContractMoney, 2))
+		item.ExpiredContractMoney = fmt.Sprint(renewedContractCompany)
+		if renewedContractMoney == 0 || expiredContractMoney == 0 {
+			item.RenewalRate = "0%"
+		} else {
+			item.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractMoney/expiredContractMoney*100, 2), "%")
+		}
+
+		listResp = append(listResp, item)
+
+		item2 := new(statistic_report.RaiDataSummaryDetailResp)
+		item2.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
+		item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
+		if renewedContractCompany == 0 || expiredContractCompany == 0 {
+			item2.RenewalRate = "0%"
+		} else {
+			item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(renewedContractCompany/expiredContractCompany*100, 2), "%")
+		}
+
+		listResp = append(listResp, item2)
+
+	case "确认不续约合同":
+		noRenewedcompanyContractIds := services.GetCompanyContractNoRenewedAscribeListArr()
+		condition += ` AND  a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)  ` // 已确认
+		pars = append(pars, noRenewedcompanyContractIds)
+		if sellerId > 0 {
+			condition += ` AND a.seller_id_last = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += ` AND  a.product_id = 2  AND  a.status = 1  AND a.start_date >= ?  AND a.start_date <= ?   `
+		pars = append(pars, startDate, endDate)
+
+		total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		trialTotal = total
+		//列表页数据
+		tmpList, err := models.GetIncrementalCompanyMergeList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			return
+		}
+		if len(tmpList) > 0 {
+			var companyContractIds []int
+			for _, v := range tmpList {
+				companyContractIds = append(companyContractIds, v.CompanyContractId)
+			}
+
+			//合并合同所对应的权限
+			mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+			for _, v := range tmpList {
+				item := new(statistic_report.RaiDataSummaryDetailResp)
+				item.CompanyName = v.CompanyName
+				item.SellerName = v.SellerNameInit
+				item.StartDate = v.StartDate
+				item.EndDate = v.EndDate
+				item.Money = v.Money
+				item.PermissionName = mappermissionName[v.CompanyContractId]
+				listResp = append(listResp, item)
+			}
+
+			listGroup, err = models.GetCompanyContractGroupList(condition, pars)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+
+		}
+
+	case "确认不续约率":
+		noRenewedcompanyContractIdsMap := services.GetCompanyContractNoRenewedAscribeListMap()
+		if sellerId > 0 {
+			condition += ` AND a.seller_id_last = ? `
+			pars = append(pars, sellerId)
+		}
+
+		condition += " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? "
+		pars = append(pars, startDate, endDate)
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+		var norenewedContractMoney float64   // 不续约金额
+		var norenewedContractCompany float64 // 不续约客户数
+		mapnorenewedContractCompany := make(map[int]bool)
+
+		var expiredContractMoney float64   //到期金额
+		var expiredContractCompany float64 // 到期客户数
+		mapexpiredContractCompany := make(map[int]bool)
+
+		for _, v := range listRaiData {
+			if noRenewedcompanyContractIdsMap[v.CompanyContractId] {
+				norenewedContractMoney += v.Money
+				if !mapnorenewedContractCompany[v.CompanyId] {
+					norenewedContractCompany++
+					mapnorenewedContractCompany[v.CompanyId] = true
+				}
+				startDateTime := utils.StrDateToDate(v.StartDate)
+				if startDateTime.Before(time.Now().AddDate(0, 0, -1)) { //到期合同数据
+					expiredContractMoney += v.Money
+					if !mapexpiredContractCompany[v.CompanyId] {
+						expiredContractCompany++
+						mapexpiredContractCompany[v.CompanyId] = true
+					}
+				}
+			}
+		}
+
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney, 2))
+		item.ExpiredContractMoney = fmt.Sprint(norenewedContractCompany)
+		if norenewedContractMoney == 0 || expiredContractMoney == 0 {
+			item.RenewalRate = "0%"
+		} else {
+			item.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractMoney/expiredContractMoney*100, 2), "%")
+		}
+		listResp = append(listResp, item)
+
+		item2 := new(statistic_report.RaiDataSummaryDetailResp)
+		item2.RenewedContractMoney = fmt.Sprint(utils.SubFloatToString(expiredContractMoney, 2))
+		item2.ExpiredContractMoney = fmt.Sprint(expiredContractCompany)
+		if norenewedContractCompany == 0 || expiredContractCompany == 0 {
+			item2.RenewalRate = "0%"
+		} else {
+			item2.RenewalRate = fmt.Sprint(utils.SubFloatToString(norenewedContractCompany/expiredContractCompany*100, 2), "%")
 		}
+		listResp = append(listResp, item2)
+
+	case "签约客户数量":
+		if sellerId > 0 {
+			condition += ` AND a.seller_id_last = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? "
+		pars = append(pars, startDate, endDate)
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		var renewedContractCompany int // 续约客户数
+		var renewedContract int        // 续约合同数
+		maprenewedContractCompany := make(map[int]bool)
+
+		var newContractCompany int // 新签客户数
+		var newContract int        // 新签合同数
+		mapenewContractCompany := make(map[int]bool)
+		for _, v := range listRaiData {
+			if v.RaiContractType == "新签合同" {
+				newContract++
+				if !mapenewContractCompany[v.CompanyId] {
+					newContractCompany++
+					mapenewContractCompany[v.CompanyId] = true
+				}
+			} else if v.RaiContractType == "续约合同" {
+				renewedContract++
+				if !maprenewedContractCompany[v.CompanyId] {
+					renewedContractCompany++
+					maprenewedContractCompany[v.CompanyId] = true
+				}
+			}
+		}
+
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.RenewedContractCompany = renewedContractCompany
+		item.RenewedContract = renewedContract
+		item.NewContractCompany = newContractCompany
+		item.NewContract = newContract
+		listResp = append(listResp, item)
+
+	case "客单价":
+		if sellerId > 0 {
+			condition += ` AND a.seller_id_last = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? "
+		pars = append(pars, startDate, endDate)
+		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		var ontractMoney float64 // 签约总金额
+		var contractNum int      // 签约客户数
+
+		for _, v := range listRaiData {
+			ontractMoney += v.Money
+			contractNum++
+		}
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.ContractMoney = fmt.Sprint(utils.SubFloatToString(ontractMoney, 2))
+		item.ContractNum = contractNum
+		listResp = append(listResp, item)
+
+	case "开票金额":
+		if sellerId > 0 {
+			condition += ` AND a.rai_seller_id = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += " AND  a.is_deleted = 0    AND  a.start_date >= ?  AND  a.start_date <= ?  AND  invoiced_amount > 0   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range listFmsData {
+			item := new(statistic_report.RaiDataSummaryDetailResp)
+			item.CompanyName = v.CompanyName
+			item.SellerName = v.RaiSellerName
+			item.ContractCode = v.ContractCode
+			item.InvoicedAmount = v.InvoicedAmount
+			item.CreateTime = v.CreateTime.Format(utils.FormatDate)
+			listResp = append(listResp, item)
+		}
+
+	case "到款金额":
+		if sellerId > 0 {
+			condition += ` AND a.rai_seller_id = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += " AND  a.is_deleted = 0    AND  a.start_date >= ?  AND  a.start_date <= ?  AND  payment_amount > 0   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range listFmsData {
+			item := new(statistic_report.RaiDataSummaryDetailResp)
+			item.CompanyName = v.CompanyName
+			item.SellerName = v.RaiSellerName
+			item.ContractCode = v.ContractCode
+			item.PaymentAmount = v.PaymentAmount
+			item.CreateTime = v.CreateTime.Format(utils.FormatDate)
+			listResp = append(listResp, item)
+		}
+
+	case "未到款比例":
+		if sellerId > 0 {
+			condition += ` AND a.rai_seller_id = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += " AND  a.is_deleted = 0   AND  a.start_date >= ?  AND  a.start_date <= ?    AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterAmountList(condition, pars)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range listFmsData {
+			item := new(statistic_report.RaiDataSummaryDetailResp)
+			item.InvoicedAmount = v.InvoicedAmount
+			item.PaymentAmount = v.PaymentAmount
+			item.NotReceivedtAmount = v.InvoicedAmount - v.PaymentAmount
+			item.CreateTime = v.CreateTime.Format(utils.FormatDate)
+			listResp = append(listResp, item)
+		}
+
+	case "新客开票":
+		if sellerId > 0 {
+			condition += ` AND a.rai_seller_id = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += " AND  a.is_deleted = 0  AND contract_type = 1   AND  a.start_date >= ?  AND  a.start_date <= ?  AND  payment_amount > 0   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range listFmsData {
+			item := new(statistic_report.RaiDataSummaryDetailResp)
+			item.CompanyName = v.CompanyName
+			item.SellerName = v.RaiSellerName
+			item.ContractCode = v.ContractCode
+			item.PaymentAmount = v.PaymentAmount
+			item.CreateTime = v.CreateTime.Format(utils.FormatDate)
+			listResp = append(listResp, item)
+		}
+
+	case "新客到款":
+		if sellerId > 0 {
+			condition += ` AND a.rai_seller_id = ? `
+			pars = append(pars, sellerId)
+		}
+		condition += " AND  a.is_deleted = 0    AND contract_type = 1   AND  a.start_date >= ?  AND  a.start_date <= ?  AND  payment_amount > 0   AND product_ids LIKE '%2%' "
+		pars = append(pars, startDate, endDate)
+		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
+		}
+
+		for _, v := range listFmsData {
+			item := new(statistic_report.RaiDataSummaryDetailResp)
+			item.CompanyName = v.CompanyName
+			item.SellerName = v.RaiSellerName
+			item.ContractCode = v.ContractCode
+			item.PaymentAmount = v.PaymentAmount
+			item.CreateTime = v.CreateTime.Format(utils.FormatDate)
+			listResp = append(listResp, item)
+		}
+
 	}
 
 	if len(listResp) == 0 {
 		listResp = make([]*statistic_report.RaiDataSummaryDetailResp, 0)
 	}
+	if len(listGroup) > 0 {
+		for _, v := range listGroup {
+			if v.CompanyCount > 1 {
+				resp.CompanyMultiple++
+			}
+		}
+		resp.CompanyNum = len(listGroup)
+	}
 	resp.List = listResp
 	page := paging.GetPaging(currentIndex, pageSize, trialTotal)
 	resp.Paging = page

+ 30 - 0
models/fms/invoice_payment_summary.go

@@ -167,3 +167,33 @@ func GetContractRegisterListByStartDate(startDate, endDate string) (results []*C
 	_, err = o.Raw(sql, startDate, endDate).QueryRows(&results)
 	return
 }
+
+// 列表
+func GetContractRegisterList(condition string, pars []interface{}, startSize, pageSize int) (items []*ContractRegisterSummary, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := `SELECT * FROM contract_register  as a  WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,?  `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql, pars).QueryRows(&items)
+	}
+
+	return
+}
+
+// 获取开票金额与未到账金额的统计
+func GetContractRegisterAmountList(condition string, pars []interface{}) (items []*ContractRegisterSummary, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := `SELECT
+			SUM( invoiced_amount ) AS invoiced_amount,
+			SUM( payment_amount ) AS payment_amount FROM contract_register  as a  WHERE 1= 1  `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 22 - 0
models/statistic_report.go

@@ -956,6 +956,28 @@ func GetIncrementalCompanyMergeList(condition string, pars []interface{}, startS
 	return
 }
 
+// 增量客户统计报表列表数据结构
+type CompanyContractGroupList struct {
+	CompanyId    int `description:"企业客户id"`
+	CompanyCount int `description:"合同数"`
+}
+
+// GetIncrementalNewCompanyList 获取增量客户报表列表数据(根据合同来展示)
+func GetCompanyContractGroupList(condition string, pars []interface{}) (items []*CompanyContractGroupList, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			company_id,
+			COUNT( company_id )  company_count 
+		FROM
+			company_contract AS a  WHERE  product_id = 2  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY company_id `
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
 // GetIncrementalNewCompanyList 获取到期合同列表数据(根据合同来展示)
 func GetIncrementalCompanyMergeListEnd(condition string, pars []interface{}, startSize, pageSize int) (items []*IncrementalList, err error) {
 	o := orm.NewOrm()

+ 25 - 10
models/statistic_report/rai_data_summary.go

@@ -118,18 +118,33 @@ func GetRaiDataSummaryList(condition string, pars []interface{}) (items []*Incre
 }
 
 type RaiDataSummaryPopupTypeResp struct {
-	Paging *paging.PagingItem          `description:"分页数据"`
-	List   []*RaiDataSummaryDetailResp `description:"列表"`
+	CompanyNum      int                         `description:"企业客户数量"`
+	CompanyMultiple int                         `description:"户有多份合同的企业客户数量"`
+	Paging          *paging.PagingItem          `description:"分页数据"`
+	List            []*RaiDataSummaryDetailResp `description:"列表"`
 }
 
 // 增量客户统计报表列表数据结构
 type RaiDataSummaryDetailResp struct {
-	CompanyName    string  `description:"企业客户名称"`
-	SellerName     string  `description:"归属销售名称"`
-	AddType        string  `description:"新增类型"`
-	CreateTime     string  `description:"创建时间"`
-	StartDate      string  `description:"合同开始日期"`
-	EndDate        string  `description:"合同结束日期"`
-	Money          float64 `description:"合同金额"`
-	PermissionName string  `description:"权限名"`
+	CompanyName            string  `description:"企业客户名称"`
+	SellerName             string  `description:"归属销售名称"`
+	AddType                string  `description:"新增类型"`
+	CreateTime             string  `description:"创建时间"`
+	StartDate              string  `description:"合同开始日期"`
+	EndDate                string  `description:"合同结束日期"`
+	Money                  float64 `description:"合同金额"`
+	PermissionName         string  `description:"权限名"`
+	RenewedContractMoney   string  `description:"续约金额"`
+	ExpiredContractMoney   string  `description:"到期金额"`
+	RenewalRate            string  `description:"续约率"`
+	RenewedContractCompany int     `description:"续约客户数"`
+	RenewedContract        int     `description:"续约合同数"`
+	NewContractCompany     int     `description:"新签客户数"`
+	NewContract            int     `description:"新签合同数"`
+	ContractMoney          string  `description:"签约总金额"`
+	ContractNum            int     `description:"签约客户数"`
+	ContractCode           string  `description:"合同编号"`
+	InvoicedAmount         float64 ` description:"开票金额"`
+	PaymentAmount          float64 ` description:"到款金额"`
+	NotReceivedtAmount     float64 ` description:"未到账金额"`
 }

+ 52 - 0
services/company_ascribe.go

@@ -98,3 +98,55 @@ func GetCompanyContractAscribeContentMap(companyContractIds []int) (mapResp map[
 	}
 	return
 }
+
+// 获取不续约的合同ID的map映射
+func GetCompanyContractNoRenewedAscribeListMap() (mapCountResp map[int]bool) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go alarm_msg.SendAlarmMsg(" 处理公司归因展示失败 GetCompanyContractAscribeContentMap,Err:"+err.Error(), 3)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition = ` AND company_ascribe_id != 9 `
+	list, e := company.GetCompanyContractNoRenewedAscribeList(condition, pars, 0, 0)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyContractNoRenewedAscribeList, Err: " + e.Error())
+		return
+	}
+	mapCountResp = make(map[int]bool, 0)
+	for _, v := range list {
+		mapCountResp[v.CompanyContractId] = true
+	}
+	return
+}
+
+// 获取不续约的合同ID的数组
+func GetCompanyContractNoRenewedAscribeListArr() (companyContractIds []int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go alarm_msg.SendAlarmMsg(" 处理公司归因展示失败 GetCompanyContractNoRenewedAscribeListArr,Err:"+err.Error(), 3)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	condition = ` AND company_ascribe_id != 9 `
+	list, e := company.GetCompanyContractNoRenewedAscribeList(condition, pars, 0, 0)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyContractNoRenewedAscribeList, Err: " + e.Error())
+		return
+	}
+	companyContractIds = make([]int, 0)
+	if len(list) == 0 {
+		companyContractIds = append(companyContractIds, 0)
+	} else {
+		for _, v := range list {
+			companyContractIds = append(companyContractIds, v.CompanyContractId)
+		}
+	}
+	return
+}