zhangchuanxing 1 săptămână în urmă
părinte
comite
a6e4a41543

+ 77 - 136
controllers/statistic/rai_data_summary.go

@@ -252,8 +252,8 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		}
 		yearStr := getYearStar(utils.StrDateToDate(v.StartDate), dataType)
 
-		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdLast)
-		keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdLast)
+		keyMap = fmt.Sprint(yearStr, "_", v.SellerIdInit)
+		keySigned = fmt.Sprint(yearStr, "_CID_", v.CompanyId, "_SID_", v.SellerIdInit)
 		keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
 
 		if v.RaiContractType == "新签合同" {
@@ -485,25 +485,32 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if len(adminIdArr) > 0 && !utils.InArrayByStr(adminIdArr, strconv.Itoa(v.RaiSellerId)) {
 			continue
 		}
-		//if !mapsellerDevelop[v.RaiSellerId] {
-		//	continue
-		//}
-		yearStr := getYearStar(v.StartDate, dataType)
+		if !mapsellerDevelop[v.RaiSellerId] {
+			continue
+		}
+		yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType)
 
 		keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
 		keyMapTtoal = fmt.Sprint(yearStr, "_Develop")
 
-		mapInvoiceAmountMoney[keyMap] += v.InvoicedAmount
-		mapPaymentAmountMoney[keyMap] += v.PaymentAmount
-
-		mapInvoiceAmountMoney[keyMapTtoal] += v.InvoicedAmount
-		mapPaymentAmountMoney[keyMapTtoal] += v.PaymentAmount
+		//开票记录
+		if v.InvoiceType == 1 {
+			mapInvoiceAmountMoney[keyMap] += v.Amount
+			mapInvoiceAmountMoney[keyMapTtoal] += v.Amount
+			if v.ContractType == 1 {
+				mapNewCustomerInvoicingMoney[keyMap] += v.Amount
+				mapNewCustomerInvoicingMoney[keyMapTtoal] += v.Amount
+			}
+		}
 
-		if v.ContractType == 1 {
-			mapNewCustomerInvoicingMoney[keyMap] += v.InvoicedAmount
-			mapNewCustomerPaymentsReceivedMoney[keyMap] += v.PaymentAmount
-			mapNewCustomerInvoicingMoney[keyMapTtoal] += v.InvoicedAmount
-			mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.PaymentAmount
+		//到款记录
+		if v.InvoiceType == 2 {
+			mapPaymentAmountMoney[keyMap] += v.Amount
+			mapPaymentAmountMoney[keyMapTtoal] += v.Amount
+			if v.ContractType == 1 {
+				mapNewCustomerPaymentsReceivedMoney[keyMap] += v.Amount
+				mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.Amount
+			}
 		}
 	}
 
@@ -515,22 +522,29 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 		if !mapsellerService[v.RaiSellerId] {
 			continue
 		}
-		yearStr := getYearStar(v.StartDate, dataType)
+		yearStr := getYearStar(utils.StrDateToDate(v.InvoiceTime), dataType)
 
-		keyMap = fmt.Sprint(yearStr, "_", v.RaiSellerId)
+		keyMap = fmt.Sprint(yearStr, "_Server_", v.RaiSellerId)
 		keyMapTtoal = fmt.Sprint(yearStr, "_Server_")
 
-		mapInvoiceAmountMoney[keyMap] += v.InvoicedAmount
-		mapPaymentAmountMoney[keyMap] += v.PaymentAmount
-
-		mapInvoiceAmountMoney[keyMapTtoal] += v.InvoicedAmount
-		mapPaymentAmountMoney[keyMapTtoal] += v.PaymentAmount
+		//开票记录
+		if v.InvoiceType == 1 {
+			mapInvoiceAmountMoney[keyMap] += v.Amount
+			mapInvoiceAmountMoney[keyMapTtoal] += v.Amount
+			if v.ContractType == 1 {
+				mapNewCustomerInvoicingMoney[keyMap] += v.Amount
+				mapNewCustomerInvoicingMoney[keyMapTtoal] += v.Amount
+			}
+		}
 
-		if v.ContractType == 1 {
-			mapNewCustomerInvoicingMoney[keyMap] += v.InvoicedAmount
-			mapNewCustomerPaymentsReceivedMoney[keyMap] += v.PaymentAmount
-			mapNewCustomerInvoicingMoney[keyMapTtoal] += v.InvoicedAmount
-			mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.PaymentAmount
+		//到款记录
+		if v.InvoiceType == 2 {
+			mapPaymentAmountMoney[keyMap] += v.Amount
+			mapPaymentAmountMoney[keyMapTtoal] += v.Amount
+			if v.ContractType == 1 {
+				mapNewCustomerPaymentsReceivedMoney[keyMap] += v.Amount
+				mapNewCustomerPaymentsReceivedMoney[keyMapTtoal] += v.Amount
+			}
 		}
 	}
 
@@ -582,7 +596,6 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryList() {
 	var items []*statistic_report.RaiDataSummaryResp
 
 	for i := startYear; i <= endYear; i++ {
-		//if len(dataTypeArr) > 0 {
 		for _, Dv := range dataTypeArr {
 			item := new(statistic_report.RaiDataSummaryResp)
 			item.DataType = fmt.Sprint(i, Dv)
@@ -911,7 +924,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		var conditionNew string
 		var parsNew []interface{}
 		if sellerId != "" {
-			conditionNew += ` AND a.seller_id_last IN (` + sellerId + `) `
+			conditionNew += ` AND a.seller_id_init 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 = '新签合同'  "
 		parsNew = append(parsNew, startDate, endDate)
@@ -1533,7 +1546,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		if sellerId != "" {
 			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
 		}
-		condition += " AND  a.is_deleted = 0    AND  a.start_date >= ?  AND  a.start_date <= ?  AND  invoiced_amount > 0   AND product_ids LIKE '%2%' "
+		condition += " AND  a.is_deleted = 0    AND  a.invoiced_amount > 0  AND b.invoice_type = 1   AND  b.invoice_time >= ?  AND  b.invoice_time <= ?   "
 		pars = append(pars, startDate, endDate)
 		total, err := fms.GetContractInvoiceCount(condition, pars)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -1542,6 +1555,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		trialTotal = total
+		condition += " GROUP BY b.contract_invoice_id   ORDER BY invoice_time  DESC "
 		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取数据信息失败"
@@ -1549,34 +1563,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		if len(listFmsData) > 0 {
-			var contractRegisterId []int
-			for _, v := range listFmsData {
-				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
-			}
-			lenArr := len(contractRegisterId)
-			var conditionFms string
-			var parsFms []interface{}
-			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
-			parsFms = append(parsFms, contractRegisterId)
-			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
-			if err != nil {
-				br.Msg = "获取数据信息失败"
-				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
-				return
-			}
-
-			mapInvoiceTime := make(map[int]string)
-			for _, v := range listInvoiceData {
-				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
-			}
-
 			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 = mapInvoiceTime[v.ContractRegisterId]
+				item.InvoicedAmount = v.Amount
+				item.CreateTime = v.InvoiceTime
 				listResp = append(listResp, item)
 			}
 		}
@@ -1585,7 +1578,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		if sellerId != "" {
 			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
 		}
-		condition += " AND  a.is_deleted = 0    AND  a.start_date >= ?  AND  a.start_date <= ?  AND  payment_amount > 0   AND product_ids LIKE '%2%' "
+		condition += " AND  a.is_deleted = 0    AND  a.payment_amount > 0  AND b.invoice_type = 2   AND  b.invoice_time >= ?  AND  b.invoice_time <= ?   "
 		pars = append(pars, startDate, endDate)
 		total, err := fms.GetContractInvoiceCount(condition, pars)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -1594,42 +1587,21 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		trialTotal = total
+		condition += " GROUP BY b.contract_invoice_id   ORDER BY invoice_time  DESC "
 		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取数据信息失败"
 			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
 			return
 		}
-
 		if len(listFmsData) > 0 {
-			var contractRegisterId []int
-			for _, v := range listFmsData {
-				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
-			}
-			lenArr := len(contractRegisterId)
-			var conditionFms string
-			var parsFms []interface{}
-			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
-			parsFms = append(parsFms, contractRegisterId)
-			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
-			if err != nil {
-				br.Msg = "获取数据信息失败"
-				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
-				return
-			}
-
-			mapInvoiceTime := make(map[int]string)
-			for _, v := range listInvoiceData {
-				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
-			}
-
 			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)
+				item.InvoicedAmount = v.Amount
+				item.CreateTime = v.InvoiceTime
 				listResp = append(listResp, item)
 			}
 		}
@@ -1638,29 +1610,38 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		if sellerId != "" {
 			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
 		}
-		condition += " AND  a.is_deleted = 0   AND  a.start_date >= ?  AND  a.start_date <= ?    AND product_ids LIKE '%2%' "
+		var condition2 string
+		var pars2 []interface{}
+		condition2 = condition + " AND  a.is_deleted = 0    AND  a.payment_amount > 0  AND b.invoice_type = 2   AND  b.invoice_time >= ?  AND  b.invoice_time <= ?   "
+		pars2 = append(pars2, startDate, endDate)
+
+		condition += " AND  a.is_deleted = 0    AND  a.invoiced_amount > 0  AND b.invoice_type = 1   AND  b.invoice_time >= ?  AND  b.invoice_time <= ?   "
 		pars = append(pars, startDate, endDate)
-		listFmsData, err := fms.GetContractRegisterAmountList(condition, pars)
+		amount1, err := fms.GetContractInvoiceAmountCount(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)
+		amount2, err := fms.GetContractInvoiceAmountCount(condition2, pars2) //到款金额总计
+		if err != nil {
+			br.Msg = "获取数据信息失败"
+			br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
+			return
 		}
 
+		item := new(statistic_report.RaiDataSummaryDetailResp)
+		item.InvoicedAmount = amount1
+		item.PaymentAmount = amount2
+		item.NotReceivedtAmount = amount1 - amount2
+		listResp = append(listResp, item)
+
 	case "新客开票":
 		if sellerId != "" {
 			condition += ` AND a.rai_seller_id  IN (` + sellerId + `) `
 		}
-		condition += " AND  a.is_deleted = 0  AND contract_type = 1   AND  a.start_date >= ?  AND  a.start_date <= ?   AND product_ids LIKE '%2%' "
+		condition += " AND  a.is_deleted = 0    AND  a.contract_type = 1 AND  a.invoiced_amount > 0  AND b.invoice_type = 1   AND  b.invoice_time >= ?  AND  b.invoice_time <= ?   "
 		pars = append(pars, startDate, endDate)
 		total, err := fms.GetContractInvoiceCount(condition, pars)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -1669,6 +1650,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		trialTotal = total
+		condition += " GROUP BY b.contract_invoice_id   ORDER BY invoice_time  DESC "
 		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取数据信息失败"
@@ -1676,34 +1658,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		if len(listFmsData) > 0 {
-			var contractRegisterId []int
-			for _, v := range listFmsData {
-				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
-			}
-			lenArr := len(contractRegisterId)
-			var conditionFms string
-			var parsFms []interface{}
-			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
-			parsFms = append(parsFms, contractRegisterId)
-			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
-			if err != nil {
-				br.Msg = "获取数据信息失败"
-				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
-				return
-			}
-
-			mapInvoiceTime := make(map[int]string)
-			for _, v := range listInvoiceData {
-				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
-			}
-
 			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 = mapInvoiceTime[v.ContractRegisterId]
+				item.InvoicedAmount = v.Amount
+				item.CreateTime = v.InvoiceTime
 				listResp = append(listResp, item)
 			}
 		}
@@ -1712,7 +1673,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 		if sellerId != "" {
 			condition += ` AND a.rai_seller_id  IN (` + 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%' "
+		condition += " AND  a.is_deleted = 0    AND a.contract_type = 1   AND  a.payment_amount > 0  AND b.invoice_type = 2   AND  b.invoice_time >= ?  AND  b.invoice_time <= ?   "
 		pars = append(pars, startDate, endDate)
 		total, err := fms.GetContractInvoiceCount(condition, pars)
 		if err != nil && err.Error() != utils.ErrNoRow() {
@@ -1721,6 +1682,7 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		trialTotal = total
+		condition += " GROUP BY b.contract_invoice_id   ORDER BY invoice_time  DESC "
 		listFmsData, err := fms.GetContractRegisterList(condition, pars, startSize, pageSize)
 		if err != nil {
 			br.Msg = "获取数据信息失败"
@@ -1728,34 +1690,13 @@ func (this *StatisticRaiDataSummaryController) RaiDataSummaryDetail() {
 			return
 		}
 		if len(listFmsData) > 0 {
-			var contractRegisterId []int
-			for _, v := range listFmsData {
-				contractRegisterId = append(contractRegisterId, v.ContractRegisterId)
-			}
-			lenArr := len(contractRegisterId)
-			var conditionFms string
-			var parsFms []interface{}
-			conditionFms += ` AND  contract_register_id IN  (` + utils.GetOrmInReplace(lenArr) + `)  GROUP BY contract_register_id  `
-			parsFms = append(parsFms, contractRegisterId)
-			listInvoiceData, err := fms.GetContractInvoiceList(conditionFms, parsFms, 0, lenArr)
-			if err != nil {
-				br.Msg = "获取数据信息失败"
-				br.ErrMsg = "获取数据信息失败,Err:" + err.Error()
-				return
-			}
-
-			mapInvoiceTime := make(map[int]string)
-			for _, v := range listInvoiceData {
-				mapInvoiceTime[v.ContractRegisterId] = v.InvoiceTime.Format(utils.FormatDate)
-			}
-
 			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 = mapInvoiceTime[v.ContractRegisterId]
+				item.InvoicedAmount = v.Amount
+				item.CreateTime = v.InvoiceTime
 				listResp = append(listResp, item)
 			}
 		}

+ 51 - 9
models/fms/invoice_payment_summary.go

@@ -160,18 +160,29 @@ type InvoiceSummary struct {
 	ContractRegister
 }
 
-// GetContractRegisterListByStartDate  根据起始日期的时间段筛选合同登记信息。
-func GetContractRegisterListByStartDate(startDate, endDate string) (results []*ContractRegisterSummary, err error) {
-	o := orm.NewOrmUsingDB("fms")
-	sql := ` SELECT  * FROM contract_register  WHERE start_date > ?  AND start_date <  ?   AND is_deleted = 0  AND product_ids LIKE '%2%'  `
-	_, err = o.Raw(sql, startDate, endDate).QueryRows(&results)
-	return
+type ContractRegisterRaiData struct {
+	CompanyName   string  `gorm:"column:company_name" json:"company_name" description:"客户名称"`
+	ContractCode  string  `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
+	RaiSellerName string  `gorm:"column:rai_seller_name" json:"rai_seller_name" description:"CRM系统-权益销售名称"`
+	RaiSellerId   int     `gorm:"column:rai_seller_id" json:"rai_seller_id"  description:"CRM系统-权益销售ID"`
+	Amount        float64 `json:"amount" description:"分配金额"`
+	InvoiceTime   string  `json:"invoice_time" description:"开票日期"`
+	InvoiceType   int     `json:"invoice_type" description:"1-开票登记; 2-到款登记"`
+	ContractType  int     `gorm:"column:contract_type" json:"contract_type" description:"合同类型: 1-新签; 2-续约; 3-代付; 4-补充协议"`
 }
 
 // 列表
-func GetContractRegisterList(condition string, pars []interface{}, startSize, pageSize int) (items []*ContractRegisterSummary, err error) {
+func GetContractRegisterList(condition string, pars []interface{}, startSize, pageSize int) (items []*ContractRegisterRaiData, err error) {
 	o := orm.NewOrmUsingDB("fms")
-	sql := `SELECT * FROM contract_register  as a  WHERE 1= 1 `
+	sql := `SELECT 
+    		a.company_name,
+			a.rai_seller_name,
+			a.contract_code,
+			b.amount,
+			b.invoice_time 
+		 FROM contract_register  as a 
+         INNER JOIN contract_invoice as b ON a.contract_register_id = b.contract_register_id  
+         WHERE 1= 1 `
 	if condition != "" {
 		sql += condition
 	}
@@ -216,10 +227,41 @@ func GetContractInvoiceList(condition string, pars []interface{}, startSize, pag
 // 获取数量
 func GetContractInvoiceCount(condition string, pars []interface{}) (count int, err error) {
 	o := orm.NewOrmUsingDB("fms")
-	sqlCount := ` SELECT COUNT(1) AS count  FROM contract_register as a WHERE 1= 1  `
+	sqlCount := ` SELECT COUNT(1) AS count  FROM contract_register as a
+                  INNER JOIN contract_invoice as b ON a.contract_register_id = b.contract_register_id  
+                  WHERE 1= 1  `
 	if condition != "" {
 		sqlCount += condition
 	}
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return
 }
+
+// 获取开票金额与未到账金额的统计
+func GetContractInvoiceAmountCount(condition string, pars []interface{}) (amount float64, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := `SELECT
+			SUM( amount ) AS amount FROM contract_register  as a
+			INNER JOIN contract_invoice as b ON a.contract_register_id = b.contract_register_id  
+			WHERE 1= 1  `
+	if condition != "" {
+		sql += condition
+	}
+	err = o.Raw(sql, pars).QueryRow(&amount)
+	return
+}
+
+// GetContractRegisterListByStartDate  根据起始日期的时间段筛选合同登记信息。
+func GetContractRegisterListByStartDate(startDate, endDate string) (results []*ContractRegisterRaiData, err error) {
+	o := orm.NewOrmUsingDB("fms")
+	sql := `SELECT 
+			a.rai_seller_id,
+			a.contract_type,
+			b.amount,
+			b.invoice_time,
+			b.invoice_type
+		 FROM contract_register  as a 
+         INNER JOIN contract_invoice as b ON a.contract_register_id = b.contract_register_id    AND a.is_deleted = 0  AND  b.invoice_time >= ?  AND  b.invoice_time <= ?    `
+	_, err = o.Raw(sql, startDate, endDate).QueryRows(&results)
+	return
+}

+ 3 - 3
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  AND rai_contract_type  = '续约合同'  AND inherit_company_contract_id = 0  ORDER BY start_date ASC   "
+	condition = "  AND  product_id = 2 AND status != 2  AND rai_contract_type  = '续约合同' AND is_hand = 0  ORDER BY start_date ASC   "
 	companyContractList, e := company.GetCompanyContractList(condition, pars)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		fmt.Println(e)
@@ -650,7 +650,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 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 {
@@ -669,7 +669,7 @@ func UpdateCompanyContractInheritEndDate(companyContractId int) {
 	}
 
 	//上面两个要是都找不到,就把自身的结束时间作为,续约的结束时间
-	e = company.UpdateCompanyContractInheritEndDate(contractInfo.EndDate, contractInfo.CompanyContractId, contractInfo.CompanyContractId)
+	e = company.UpdateCompanyContractInheritEndDate(contractInfo.StartDate, contractInfo.CompanyContractId, contractInfo.CompanyContractId)
 	if e != nil {
 		err = errors.New("UpdateCompanyContractInheritEndDate, Err: " + e.Error())
 		return