Ver código fonte

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

zhangchuanxing 2 dias atrás
pai
commit
d8a10d6d6f

+ 68 - 40
controllers/statistic/rai_data_summary.go

@@ -34,6 +34,8 @@ type StatisticRaiDataSummaryController struct {
 // @Param   DevelopButton   query   int	  false       "开拓组开关,枚举值:1:开启,0:关闭 ,默认关闭"
 // @Param   ServerButton   query   int	  false       "服务组开关,枚举值:1:开启,0:关闭 ,默认关闭"
 // @Param   ContractButtonType   query   string	  false       "开关类型,:`新签`,`续约`,`收入` 多个用英文逗号隔开, "
+// @Param   StartDate   query   string	  false       "开始时间 "
+// @Param   EndDate   query   string	  false       "结束时间 "
 // @Param   IsExport   query   bool  false       "是否导出excel,默认是false"
 // @Success 200 {object} statistic_report.RaiDataSummaryListResp
 // @router /rai_data_summary/list [get]
@@ -59,6 +61,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	endYear, _ := this.GetInt("EndYear")
 	developButton, _ := this.GetBool("DevelopButton")
 	serverButton, _ := this.GetBool("ServerButton")
+	startDate := this.GetString("StartDate")
+	endDate := this.GetString("EndDate")
 
 	adminIdArr := strings.Split(adminId, ",")
 	serviceAdminIdArr := strings.Split(serviceAdminId, ",")
@@ -143,9 +147,16 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		mapsellerId[v.AdminId] = true
 	}
 
+	var isCustomizeDate bool // 是否有自定义的时间
 	//拼接起始时间查询
-	startDate := fmt.Sprintf("%d-01-01", startYear)
-	endDate := fmt.Sprintf("%d-12-31", endYear)
+	if startDate == "" {
+		startDate = fmt.Sprintf("%d-01-01", startYear)
+		endDate = fmt.Sprintf("%d-12-31", endYear)
+	} else {
+		isCustomizeDate = true
+		startYear = 1
+		endYear = 1
+	}
 
 	//新签部分的数据
 	var conditionRai string
@@ -179,7 +190,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	//确认不续约、到期合同部分的数据
 	var conditionEnd string
 	var parsEnd []interface{}
-	conditionEnd = " AND  a.product_id = 2  AND  a.status = 1  AND  a.end_date >= ?  AND  a.end_date <= ? AND  a.end_date < ? "
+	conditionEnd = " AND  a.product_id = 2  AND  a.status = 1  AND  a.due_end_date >= ?  AND  a.due_end_date <= ? AND  a.due_end_date < ? "
 	parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
 	listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
 	if err != nil {
@@ -250,7 +261,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerDevelop[v.SellerIdInit] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdInit)
 		keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdInit)
@@ -278,7 +289,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerService[v.ShareSellerIdInit] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdInit)
 		keySigned = fmt.Sprint(yearStr, "_Server_", v.CompanyId, "_SID_", v.ShareSellerIdInit)
@@ -310,7 +321,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerDevelop[v.SellerIdLast] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
@@ -349,7 +360,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerService[v.ShareSellerIdLast] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.InheritEndDate), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_", v.CompanyId)
@@ -391,7 +402,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerDevelop[v.SellerIdLast] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.EndDate), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.DueEndDate), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_", v.SellerIdLast, "_CID_", v.CompanyId)
@@ -437,7 +448,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerService[v.ShareSellerIdLast] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.EndDate), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.DueEndDate), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast)
 		keyMapCompany = fmt.Sprint(yearStr, "_Server_", v.ShareSellerIdLast, "_CID_", v.CompanyId)
@@ -488,7 +499,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerDevelop[v.RaiSellerId] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
 		keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
@@ -522,7 +533,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerService[v.RaiSellerId] {
 			continue
 		}
-		yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType, isCustomizeDate)
 
 		keyMap = fmt.Sprint(yearStr, "_Server_", v.RaiSellerId)
 		keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
@@ -579,6 +590,10 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 				yearStr += "H2"
 			}
 		}
+		if isCustomizeDate {
+			yearStr = ""
+		}
+
 		keyMap = fmt.Sprint(yearStr, "_", v.SysUserId)
 		mapAddTrialNum[keyMap]++
 
@@ -598,7 +613,11 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	for i := startYear; i <= endYear; i++ {
 		for _, Dv := range dataTypeArr {
 			item := new(statistic_report.RaiDataSummaryResp)
-			item.DataType = fmt.Sprint(i, Dv)
+			if isCustomizeDate {
+				item.DataType = "" //传了自定义时间之后,把key值,置空
+			} else {
+				item.DataType = fmt.Sprint(i, Dv)
+			}
 			keyMapTtoal = fmt.Sprint(item.DataType, "_Develop")
 			keyMapTtoalServer = fmt.Sprint(item.DataType, "_Server_")
 			for _, vS := range sellerDevelop {
@@ -850,6 +869,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 // @Param   DataType   query   string  false       "报表类型,枚举值:`季度`,`年度`,`半年度`"
 // @Param   PopupType   query   string	  false       "弹窗数据类型,枚举值:"
 // @Param   IsServerSeller   query   bool	  false       "是否属于服务组销售"
+// @Param   StartDate   query   string	  false       "开始时间 "
+// @Param   EndDate   query   string	  false       "结束时间 "
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Success 200 {object} statistic_report.RaiDataSummaryPopupTypeResp
@@ -874,6 +895,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 	sellerId := this.GetString("SellerId")
 	popupType := this.GetString("PopupType")
 	isServerSeller, _ := this.GetBool("IsServerSeller")
+	startDate := this.GetString("StartDate")
+	endDate := this.GetString("EndDate")
 
 	var startSize int
 	if pageSize <= 0 {
@@ -884,30 +907,32 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 	}
 	startSize = utils.StartIndex(currentIndex, pageSize)
 
-	var startDate string
-	var endDate string
-	year := (dataType[:4])
-	if strings.Contains(dataType, "Q1") {
-		startDate = year + "-01-01"
-		endDate = year + "-03-31"
-	} else if strings.Contains(dataType, "Q2") {
-		startDate = year + "-04-01"
-		endDate = year + "-06-30"
-	} else if strings.Contains(dataType, "Q3") {
-		startDate = year + "-07-01"
-		endDate = year + "-09-30"
-	} else if strings.Contains(dataType, "Q4") {
-		startDate = year + "-10-01"
-		endDate = year + "-12-31"
-	} else if strings.Contains(dataType, "H1") {
-		startDate = year + "-01-01"
-		endDate = year + "-06-31"
-	} else if strings.Contains(dataType, "H2") {
-		startDate = year + "-07-01"
-		endDate = year + "-12-31"
-	} else {
-		startDate = year + "-01-01"
-		endDate = year + "-12-31"
+	//var startDate string
+	//var endDate string
+	if startDate == "" {
+		year := (dataType[:4])
+		if strings.Contains(dataType, "Q1") {
+			startDate = year + "-01-01"
+			endDate = year + "-03-31"
+		} else if strings.Contains(dataType, "Q2") {
+			startDate = year + "-04-01"
+			endDate = year + "-06-30"
+		} else if strings.Contains(dataType, "Q3") {
+			startDate = year + "-07-01"
+			endDate = year + "-09-30"
+		} else if strings.Contains(dataType, "Q4") {
+			startDate = year + "-10-01"
+			endDate = year + "-12-31"
+		} else if strings.Contains(dataType, "H1") {
+			startDate = year + "-01-01"
+			endDate = year + "-06-31"
+		} else if strings.Contains(dataType, "H2") {
+			startDate = year + "-07-01"
+			endDate = year + "-12-31"
+		} else {
+			startDate = year + "-01-01"
+			endDate = year + "-12-31"
+		}
 	}
 
 	resp := new(statistic_report.RaiDataSummaryPopupTypeResp)
@@ -1061,7 +1086,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 
 		}
 
-		condition += ` 	AND a.product_id = 2  AND  a.status = 1  AND a.end_date >= ?  AND a.end_date <= ?   AND a.end_date < ? `
+		condition += ` 	AND a.product_id = 2  AND  a.status = 1  AND a.due_end_date >= ?  AND a.due_end_date <= ?   AND a.due_end_date < ? `
 		pars = append(pars, startDate, endDate, time.Now().Format(utils.FormatDate))
 
 		total, err := company.GetIncrementalNewCompanyProductMergeCount(condition, pars)
@@ -1198,7 +1223,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		}
 
 		//到期合同数据
-		conditionEnd += ` AND  a.status = 1  AND a.end_date >= ?  AND a.end_date <= ?   AND a.end_date < ? `
+		conditionEnd += ` AND  a.status = 1  AND a.due_end_date >= ?  AND a.due_end_date <= ?   AND a.due_end_date < ? `
 		parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
 		listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
 		if err != nil {
@@ -1354,7 +1379,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 
-		conditionEnd += `  AND  a.product_id = 2  AND  a.status = 1  AND a.end_date >= ?  AND a.end_date <= ?   AND a.end_date < ? `
+		conditionEnd += `  AND  a.product_id = 2  AND  a.status = 1  AND a.due_end_date >= ?  AND a.due_end_date <= ?   AND a.due_end_date < ? `
 		parsEnd = append(parsEnd, startDate, endDate, time.Now().Format(utils.FormatDate))
 
 		listEndData, err := statistic_report.GetRaiDataSummaryList(conditionEnd, parsEnd)
@@ -1724,7 +1749,10 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 }
 
 // 时间筛选项的转换
-func getYearStar(startDate time.Time, dataType string) (yearStr string) {
+func getYearStar(startDate time.Time, dataType string, isCustomizeDate bool) (yearStr string) {
+	if isCustomizeDate {
+		return //如果有自定的时间,就传空值
+	}
 	startDateTime := startDate
 	monthNum := startDateTime.Month()
 	yearStr = strconv.Itoa(startDateTime.Year())

+ 20 - 2
models/company/company_contract.go

@@ -230,6 +230,8 @@ type CompanyContractResp struct {
 	PackageType       int       `description:"套餐类型,0:无,1:大套餐,2:小套餐"`
 	RaiPackageType    int       `description:"权益套餐类型: 0-无; 1-70w大套餐; 2-45w大套餐"`
 	PermissionName    string    `description:"权限名"`
+	InheritEndDate    string    `description:"所继承上一份合同的结束日期,权益自定义续约合同统计使用"`
+	DueEndDate        string    `description:"所继承上一份合同的结束日期,权益自定义到期合同统计使用"`
 }
 
 // 获取合同列表
@@ -485,10 +487,26 @@ func UpdateCompanyContracthide(companyContractId []string) (err error) {
 	return
 }
 
-// 更新合同类型
+// 更新续约时间
 func UpdateCompanyContractInheritEndDate(inheritEndDate string, inheritCompanyContracId, companyContractId int) (err error) {
 	o := orm.NewOrm()
-	sql := `UPDATE company_contract SET inherit_end_date = ? , inherit_company_contract_id = ?   WHERE company_contract_id=? `
+	sql := `UPDATE company_contract SET inherit_end_date = ? ,inherit_company_contract_id = ?   WHERE company_contract_id=? `
 	_, err = o.Raw(sql, inheritEndDate, inheritCompanyContracId, companyContractId).Exec()
 	return
 }
+
+// 更新到期时间
+func UpdateCompanyContractDueEndDate(dueEndDate string, companyContractId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_contract SET due_end_date = ?    WHERE company_contract_id=? `
+	_, err = o.Raw(sql, dueEndDate, companyContractId).Exec()
+	return
+}
+
+// 更新到期时间
+func UpdateCompanyContractDueEndDateMerge(inheritEndDate, dueEndDate string, inheritCompanyContracId, mergeCompanyContractId, companyContractId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE company_contract SET  inherit_end_date = ? , due_end_date = ?  ,inherit_company_contract_id = ? , merge_company_contract_id = ?   WHERE company_contract_id=? `
+	_, err = o.Raw(sql, inheritEndDate, dueEndDate, inheritCompanyContracId, mergeCompanyContractId, companyContractId).Exec()
+	return
+}

+ 2 - 0
models/statistic_report/rai_data_summary.go

@@ -91,6 +91,7 @@ type IncrementalList struct {
 	Operation         string `description:"操作"`
 	RaiContractType   string `description:"权益合同类型:枚举值:'新签合同','续约合同','补充协议'"`
 	InheritEndDate    string `description:"所继承上一份合同的结束日期,权益自定义续约合同统计使用"`
+	DueEndDate        string `description:"所继承上一份合同的结束日期,权益自定义到期合同统计使用"`
 }
 
 // GetRaiDataSummaryList 获取增量客户报表列表数据(根据合同来展示)
@@ -98,6 +99,7 @@ func GetRaiDataSummaryList(condition string, pars []interface{}) (items []*Incre
 	o := orm.NewOrm()
 	sql := `SELECT a.start_date,
 			   a.end_date,
+			   a.due_end_date,
 			   a.company_contract_id,
 			   a.money,
 			   a.company_id,

+ 72 - 7
services/company_contract.go

@@ -592,7 +592,8 @@ func UpdateCompanyContracthideBycompanyId(companyId, productId int) {
 func init_CRM_16_7() {
 	var condition string
 	var pars []interface{}
-	condition = "  AND  product_id = 2 AND status != 2  AND rai_contract_type  = '续约合同' AND is_hand = 0  ORDER BY start_date ASC   "
+	condition = "    AND  product_id = 2 AND status != 2  AND rai_contract_type  = '续约合同' AND is_hand = 0  ORDER BY company_contract_id ASC   "
+	condition = "    AND  product_id = 2 AND status != 2    ORDER BY company_contract_id ASC   "
 	companyContractList, e := company.GetCompanyContractList(condition, pars)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		fmt.Println(e)
@@ -602,6 +603,7 @@ func init_CRM_16_7() {
 		fmt.Println(k)
 		UpdateCompanyContractInheritEndDate(v.CompanyContractId)
 		time.Sleep(100 * time.Millisecond)
+		//UpdateCompanyContractDueEndDate(v.CompanyContractId)
 	}
 	fmt.Println("init_CRM_16_7end")
 }
@@ -620,23 +622,32 @@ func UpdateCompanyContractInheritEndDate(companyContractId int) {
 			go alarm_msg.SendAlarmMsg(fmt.Sprint("判断权益合同,是否续约了上一份的合同,并修改对应续约信息失败,UpdateCompanyContractInheritEndDate ", err), 3)
 		}
 	}()
+	go UpdateCompanyContractDueEndDate(companyContractId)
 	contractInfo, e := company.GetCompanyContractDetailByCompanyContractId(companyContractId)
 	if e != nil {
 		err = errors.New("GetCompanyContractDetailByCompanyContractId, Err: " + e.Error())
 		return
 	}
+	if contractInfo.RaiContractType == "新签合同" {
+		e = company.UpdateCompanyContractDueEndDate(contractInfo.EndDate, contractInfo.CompanyContractId)
+		if e != nil {
+			err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
+			return
+		}
+		return
+	}
 	startDate := contractInfo.StartDate
 
 	var condition string
 	var pars []interface{}
-	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  "
+	condition = "  AND  product_id = 2 AND status =1  AND  merge_company_contract_id = 0   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 {
 		err = errors.New("GetCompanyContractList, Err: " + e.Error())
 		return
 	}
-
+	//fmt.Println("companyContractList", len(companyContractList), "id", contractInfo.CompanyContractId, "contractInfo.EndDate", contractInfo.EndDate)
 	if len(companyContractList) == 1 {
 		for _, v := range companyContractList {
 			e = company.UpdateCompanyContractInheritEndDate(v.EndDate, v.CompanyContractId, contractInfo.CompanyContractId)
@@ -650,7 +661,7 @@ func UpdateCompanyContractInheritEndDate(companyContractId int) {
 	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  "
+	condition = "  AND  product_id = 2 AND status = 1  AND  merge_company_contract_id = 0   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 {
@@ -668,11 +679,65 @@ func UpdateCompanyContractInheritEndDate(companyContractId int) {
 		return
 	}
 
-	//上面两个要是都找不到,就把自身的结束时间作为,续约的结束时间
-	e = company.UpdateCompanyContractInheritEndDate(contractInfo.StartDate, contractInfo.CompanyContractId, contractInfo.CompanyContractId)
+	////上面两个要是都找不到,就把自身的结束时间作为,续约的结束时间
+	//e = company.UpdateCompanyContractInheritEndDate(contractInfo.StartDate, contractInfo.CompanyContractId, contractInfo.CompanyContractId)
+	//if e != nil {
+	//	err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
+	//	return
+	//}
+	return
+}
+
+// 判断权益合同,是否续约了上一份的合同,并修改对应续约信息
+func UpdateCompanyContractDueEndDate(companyContractId int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("判断权益合同,是否续约了上一份的合同,并修改对应续约信息失败,UpdateCompanyContractInheritEndDate ", err), 3)
+		}
+	}()
+	contractInfo, e := company.GetCompanyContractDetailByCompanyContractId(companyContractId)
 	if e != nil {
-		err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
+		err = errors.New("GetCompanyContractDetailByCompanyContractId, Err: " + e.Error())
+		return
+	}
+	if contractInfo.RaiContractType == "新签合同" {
+		fmt.Println("新签合同")
 		return
 	}
+	endDate := contractInfo.EndDate
+	startDate := contractInfo.StartDate
+
+	var condition string
+	var pars []interface{}
+	condition = `  AND  product_id = 2 AND status =1  AND  merge_company_contract_id = 0   AND company_contract_id < ? AND company_id = ? 
+				AND DATE_ADD( end_date, INTERVAL - 1 YEAR ) < ? AND DATE_ADD( end_date, INTERVAL 1 YEAR ) > ? 
+				AND DATE_ADD( start_date, INTERVAL - 1 YEAR ) < ? AND DATE_ADD( start_date, INTERVAL 1 YEAR ) > ?
+				ORDER BY company_contract_id DESC,  end_date  DESC LIMIT	 1  `
+	pars = append(pars, contractInfo.CompanyContractId, contractInfo.CompanyId, endDate, endDate, startDate, startDate)
+	companyContractList, e := company.GetCompanyContractList(condition, pars)
+	if e != nil {
+		err = errors.New("GetCompanyContractList, Err: " + e.Error())
+		return
+	}
+	//fmt.Println("companyContractList", len(companyContractList), "id", contractInfo.CompanyContractId, "contractInfo.EndDate", contractInfo.EndDate)
+	if len(companyContractList) == 1 {
+		for _, v := range companyContractList {
+			e = company.UpdateCompanyContractDueEndDateMerge(v.InheritEndDate, v.DueEndDate, v.CompanyContractId, v.CompanyContractId, contractInfo.CompanyContractId)
+			if e != nil {
+				err = errors.New("UpdateCompanyContractDueEndDateMerge, Err: " + e.Error())
+				return
+			}
+		}
+		return
+	} else {
+		//因为没有1年内的合并对象,结束时间作为自己的到期时间
+		e = company.UpdateCompanyContractDueEndDate(contractInfo.EndDate, contractInfo.CompanyContractId)
+		if e != nil {
+			err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
+			return
+		}
+	}
 	return
 }