Browse Source

no message

zhangchuanxing 1 week ago
parent
commit
ec9b686190
2 changed files with 50 additions and 23 deletions
  1. 21 21
      controllers/statistic/rai_data_summary.go
  2. 29 2
      services/company_contract.go

+ 21 - 21
controllers/statistic/rai_data_summary.go

@@ -158,17 +158,17 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
 		return
 	}
-	var companyIds []int
+	var companyContractIds []int
 	for _, v := range listRaiData {
-		companyIds = append(companyIds, v.CompanyId)
+		companyContractIds = append(companyContractIds, v.CompanyId)
 	}
-	companyIds = append(companyIds, 0)
+	companyContractIds = append(companyContractIds, 0)
 
 	//续约部分的数据
 	var conditionInherit string
 	var parsInherit []interface{}
-	conditionInherit = ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ?  AND a.rai_contract_type = '续约合同'   AND  a.company_id NOT IN (` + utils.GetOrmInReplace(len(companyIds)) + `) `
-	parsInherit = append(parsInherit, startDate, endDate, companyIds)
+	conditionInherit = ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ?  AND a.rai_contract_type = '续约合同'   AND  a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(companyContractIds)) + `) `
+	parsInherit = append(parsInherit, startDate, endDate, companyContractIds)
 	listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
 	if err != nil {
 		br.Msg = "获取数据信息失败"
@@ -905,15 +905,16 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 	var condition string
 	var pars []interface{}
 
-	//新签合同的客户ID
-	var companyIdsNew []int
+	//新签合同的ID
+	var companyContractIdsNew []int
 	{
 		var conditionNew string
 		var parsNew []interface{}
+		fmt.Println("sellerId", sellerId)
 		if sellerId != "" {
-			conditionNew += ` AND a.sys_user_id IN (` + sellerId + `) `
+			conditionNew += ` AND a.seller_id_last IN (` + sellerId + `) `
 		}
-		conditionNew = " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? AND a.rai_contract_type = '新签合同'  "
+		conditionNew += " AND  a.product_id = 2  AND  a.status = 1  AND  a.start_date >= ?  AND  a.start_date <= ? AND a.rai_contract_type = '新签合同'  "
 		parsNew = append(parsNew, startDate, endDate)
 		listNewData, err := statistic_report.GetRaiDataSummaryList(conditionNew, parsNew)
 		if err != nil {
@@ -922,11 +923,11 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		for _, v := range listNewData {
-			companyIdsNew = append(companyIdsNew, v.CompanyId)
+			companyContractIdsNew = append(companyContractIdsNew, v.CompanyId)
 		}
 	}
-	companyIdsNew = append(companyIdsNew, 0)
-	lenArrCompany := len(companyIdsNew)
+	companyContractIdsNew = append(companyContractIdsNew, 0)
+	lenArrCompany := len(companyContractIdsNew)
 
 	switch popupType {
 	case "新增试用":
@@ -1096,9 +1097,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 				condition += ` AND a.seller_id_last  IN (` + sellerId + `) `
 			}
 		}
-
-		condition += ` AND  a.status = 1  AND a.inherit_end_date >= ?  AND a.inherit_end_date <= ?  AND  a.inherit_company_contract_id > 0  AND a.rai_contract_type = '续约合同'  AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
-		pars = append(pars, startDate, endDate, companyIdsNew)
+		condition += ` AND  a.status = 1  AND a.inherit_end_date >= ?  AND a.inherit_end_date <= ?  AND  a.inherit_company_contract_id > 0  AND a.rai_contract_type = '续约合同'  AND a.company_contract_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		pars = append(pars, startDate, endDate, companyContractIdsNew)
 
 		total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -1155,8 +1155,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			conditionEnd += ` AND a.seller_id_last  IN (` + sellerId + `) `
 		}
 
-		condition += ` AND  a.status = 1  AND a.inherit_end_date >= ?  AND a.inherit_end_date <= ?  AND  inherit_company_contract_id > 0    AND a.rai_contract_type = '续约合同' AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
-		pars = append(pars, startDate, endDate, companyIdsNew)
+		condition += ` AND  a.status = 1  AND a.inherit_end_date >= ?  AND a.inherit_end_date <= ?  AND  inherit_company_contract_id > 0    AND a.rai_contract_type = '续约合同' AND a.company_contract_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		pars = append(pars, startDate, endDate, companyContractIdsNew)
 		listRaiData, err := statistic_report.GetRaiDataSummaryList(condition, pars)
 		if err != nil {
 			br.Msg = "获取数据信息失败"
@@ -1387,8 +1387,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		}
 
 		//续约部分的数据
-		conditionInherit += ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ? AND  a.inherit_company_contract_id > 0  AND a.rai_contract_type = '续约合同'  AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
-		parsInherit = append(parsInherit, startDate, endDate, companyIdsNew)
+		conditionInherit += ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ? AND  a.inherit_company_contract_id > 0  AND a.rai_contract_type = '续约合同'  AND a.company_contract_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
 		listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
 		if err != nil {
 			br.Msg = "获取数据信息失败"
@@ -1467,8 +1467,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 				mapCompany[v.CompanyId] = true
 			}
 		}
-		conditionInherit += ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ?  AND a.rai_contract_type = '续约合同'   AND a.company_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
-		parsInherit = append(parsInherit, startDate, endDate, companyIdsNew)
+		conditionInherit += ` AND  a.product_id = 2  AND  a.status = 1  AND  a.inherit_end_date >= ?  AND  a.inherit_end_date <= ?  AND a.rai_contract_type = '续约合同'   AND a.company_contract_id NOT  IN (` + utils.GetOrmInReplace(lenArrCompany) + `)  `
+		parsInherit = append(parsInherit, startDate, endDate, companyContractIdsNew)
 		listInheritData, err := statistic_report.GetRaiDataSummaryInheritList(conditionInherit, parsInherit)
 		if err != nil {
 			br.Msg = "获取数据信息失败"

+ 29 - 2
services/company_contract.go

@@ -592,7 +592,7 @@ func UpdateCompanyContracthideBycompanyId(companyId, productId int) {
 func init_CRM_16_7() {
 	var condition string
 	var pars []interface{}
-	condition = "  AND  product_id = 2 AND status != 2  ORDER BY start_date ASC   "
+	condition = "  AND  product_id = 2 AND status != 2  AND rai_contract_type  = '续约合同'  AND inherit_company_contract_id = 0  ORDER BY start_date ASC   "
 	companyContractList, e := company.GetCompanyContractList(condition, pars)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		fmt.Println(e)
@@ -629,7 +629,7 @@ func UpdateCompanyContractInheritEndDate(companyContractId int) {
 
 	var condition string
 	var pars []interface{}
-	condition = "  AND  product_id = 2 AND status != 2  AND company_id = ? AND end_date <= ? AND DATE_ADD( end_date, INTERVAL 1 YEAR ) >= ?  ORDER BY start_date ASC  LIMIT	 1  "
+	condition = "  AND  product_id = 2 AND status =1   AND company_id = ? AND end_date <= ? AND DATE_ADD( end_date, INTERVAL 1 YEAR ) >= ?  ORDER BY end_date ASC  LIMIT	 1  "
 	pars = append(pars, contractInfo.CompanyId, startDate, startDate)
 	companyContractList, e := company.GetCompanyContractList(condition, pars)
 	if e != nil {
@@ -645,7 +645,34 @@ func UpdateCompanyContractInheritEndDate(companyContractId int) {
 				return
 			}
 		}
+		return
+	}
+	pars = make([]interface{}, 0)
+
+	//上一份合同找不到的话,就找开始时间早于当前合同开始时间的,结束时间晚于当前合同开始时间的
+	condition = "  AND  product_id = 2 AND status = 1   AND company_id = ? AND start_date > ? AND   end_date > ?  ORDER BY end_date ASC  LIMIT	 1  "
+	pars = append(pars, contractInfo.CompanyId, startDate, startDate)
+	companyContractList2, e := company.GetCompanyContractList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyContractList, Err: " + e.Error())
+		return
+	}
+	if len(companyContractList2) == 1 {
+		for _, v := range companyContractList2 {
+			e = company.UpdateCompanyContractInheritEndDate(v.EndDate, v.CompanyContractId, contractInfo.CompanyContractId)
+			if e != nil {
+				err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
+				return
+			}
+		}
+		return
 	}
 
+	//上面两个要是都找不到,就把自身的结束时间作为,续约的结束时间
+	e = company.UpdateCompanyContractInheritEndDate(contractInfo.EndDate, contractInfo.CompanyContractId, contractInfo.CompanyContractId)
+	if e != nil {
+		err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
+		return
+	}
 	return
 }