|
@@ -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")
|
|
|
}
|
|
@@ -625,18 +627,26 @@ func UpdateCompanyContractInheritEndDate(companyContractId int) {
|
|
|
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 +660,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 +678,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
|
|
|
}
|