zwxi před 1 rokem
rodič
revize
4fa219a956

+ 514 - 0
controller/census/seller.go

@@ -9,9 +9,11 @@ import (
 	"github.com/tealeg/xlsx"
 	"hongze/fms_api/controller/resp"
 	"hongze/fms_api/global"
+	"hongze/fms_api/models"
 	"hongze/fms_api/models/base"
 	"hongze/fms_api/models/crm"
 	"hongze/fms_api/models/fms"
+	"hongze/fms_api/services/alarm_msg"
 	crmService "hongze/fms_api/services/crm"
 	"hongze/fms_api/utils"
 	"net/http"
@@ -496,3 +498,515 @@ func ExportInvoiceList(c *gin.Context, list []*fms.CensusSellerInvoiceItem, req
 	c.Writer.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
 	http.ServeContent(c.Writer, c.Request, fileName, time.Now(), content)
 }
+
+func (this *SellerController) GroupInvoiceListV2(c *gin.Context) {
+	var req fms.IncomeListReq
+	if e := c.BindQuery(&req); e != nil {
+		err, ok := e.(validator.ValidationErrors)
+		if !ok {
+			resp.FailData("参数解析失败", "Err:"+e.Error(), c)
+			return
+		}
+		resp.FailData("参数解析失败", err.Translate(global.Trans), c)
+		return
+	}
+	//收入统计
+	var incomeList models.CensusIncomeChartResp
+	ch := make(chan models.CensusIncomeChartResp, 1)
+	go getGroupInvoiceList(ch, req)
+
+	for v := range ch {
+		incomeList = v
+		close(ch)
+	}
+	// 是否导出
+	if req.IsExport == 1 {
+		ExportIncomeList(c, incomeList.DataList)
+		return
+	}
+	resp.OkData("获取成功", incomeList, c)
+}
+
+func getGroupInvoiceList(ch chan models.CensusIncomeChartResp, req fms.IncomeListReq) (incomeChart models.CensusIncomeChartResp, err error) {
+	defer func() {
+		if err != nil {
+			global.LOG.Error(err)
+			if err != utils.ErrNoRow {
+				go alarm_msg.SendAlarmMsg("获取业务收入金额统计数据异常,Err:"+err.Error(), 3)
+			}
+		}
+		ch <- incomeChart
+	}()
+
+	//获取最新的开票到款日期
+	cond := ``
+	historyCond := ``
+	pars := make([]interface{}, 0)
+	historyPars := make([]interface{}, 0)
+
+	//if req.SellerIds != "" {
+	//	sellerIds := strings.Split(req.SellerIds, ",")
+	//	cond += ` AND (a.seller_id in ? ) `
+	//	historyCond += ` AND (seller_id in ? ) `
+	//	pars = append(pars, sellerIds)
+	//	historyPars = append(historyPars, sellerIds)
+	//}
+	if req.CompanyType == 1 {
+		cond += ` AND b.contract_type = 1 `
+		historyCond += ` AND new_company = 1 `
+	} else if req.CompanyType == 2 {
+		cond += ` AND b.contract_type IN (2,3,4) `
+		historyCond += ` AND new_company = 0 `
+	}
+
+	var latestTime time.Time
+
+	invoiceItem, err := fms.GetLatestIncome(cond, pars)
+	if err != nil && err != utils.ErrNoRow {
+		err = fmt.Errorf("获取最新的开票或到款日期, Err: %s", err.Error())
+		return
+	}
+	latestTime = invoiceItem.InvoiceDate
+
+	if err == utils.ErrNoRow {
+		historyItem, e := fms.GetLatestHistoryIncome(historyCond, historyPars)
+		if e != nil && e != utils.ErrNoRow {
+			err = fmt.Errorf("获取最新的历史开票或到款日期, Err: %s", e.Error())
+			return
+		}
+		latestTime = historyItem.InvoiceDate
+	}
+
+	if latestTime.IsZero() {
+		latestTime = time.Now()
+	}
+
+	latestTime = latestTime.AddDate(0, 0, -latestTime.Day()+1)
+
+	var dateSlice []string
+	var totalMoneySlice, prevTotalMoneySlice []float64
+	var yoySlice []string
+	var yearNum, monthNum int
+	var reqStartDate, reqEndDate time.Time
+	historyTime, _ := time.Parse(utils.FormatDate, "2023-04-01")
+
+	if req.StartDate != "" && req.EndDate != "" {
+		st := fmt.Sprint(req.StartDate, "-01 00:00:00")
+		ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
+		reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
+		reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
+		if reqEndDate.After(latestTime) {
+			yearNum = latestTime.Year() - reqStartDate.Year()
+			monthNum = int(latestTime.Month() - reqStartDate.Month())
+		} else {
+			yearNum = reqEndDate.Year() - reqStartDate.Year()
+			monthNum = int(reqEndDate.Month() - reqStartDate.Month())
+		}
+	} else {
+		yearNum = latestTime.Year() - 2020
+		monthNum = int(latestTime.Month() - 1)
+	}
+
+	if yearNum < 0 {
+		yearNum = -yearNum
+	}
+	if monthNum < 0 {
+		monthNum = -monthNum
+	}
+	numMonth := yearNum*12 + monthNum //共存在多少个月
+
+	// 累计值
+	var accumulate float64
+	var partAccumulate float64
+	var historyAccumulate float64
+	var partHistoryAccumulate float64
+	//dataList := make([]*fms.IncomeSummaryItem, 0)
+	//historydataList := make([]*fms.IncomeSummaryItem, 0)
+	fmt.Println("numMonth:", numMonth)
+	fmt.Println("InvoiceDate:", latestTime)
+
+	var j int
+	for i := 0; i <= numMonth; i++ {
+		//timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
+
+		var endDateTime time.Time
+		var prevEndDateTime time.Time
+		var prevStartDate, prevEndDate string
+		var startDate, endDate string
+		//开始日期
+		if req.StartDate != "" && req.EndDate != "" {
+			startDate = reqStartDate.AddDate(0, i, 0).Format("2006-01")
+			prevStartDate = reqStartDate.AddDate(-1, i, 0).Format("2006-01")
+		} else {
+			startDate = latestTime.AddDate(0, i-numMonth, 0).Format("2006-01")
+			prevStartDate = latestTime.AddDate(-1, i-numMonth, 0).Format("2006-01")
+		}
+		startDate = fmt.Sprint(startDate, "-01")
+		prevStartDate = fmt.Sprint(prevStartDate, "-01")
+		startDateTime, _ := time.Parse(utils.FormatDate, startDate)
+		prevStartDateTime, _ := time.Parse(utils.FormatDate, prevStartDate)
+
+		//结束日期
+		if req.StartDate != "" && req.EndDate != "" {
+			endDateTime = reqStartDate.AddDate(0, i+1, -1)
+			prevEndDateTime = reqStartDate.AddDate(-1, i+1, -1)
+			if reqEndDate.After(latestTime) {
+				endDateTime = latestTime.AddDate(0, i-numMonth+1, -1)
+				prevEndDateTime = latestTime.AddDate(-1, i-numMonth+1, -1)
+			}
+		} else {
+			endDateTime = latestTime.AddDate(0, i-numMonth+1, -1)
+			prevEndDateTime = latestTime.AddDate(-1, i-numMonth+1, -1)
+		}
+		endDate = endDateTime.Format(utils.FormatDate)
+		prevEndDate = prevEndDateTime.Format(utils.FormatDate)
+
+		cond := `1 = 1`
+		histrtyCond := `1 = 1`
+		pars := make([]interface{}, 0)
+		historyPars := make([]interface{}, 0)
+
+		prevCond := `1 = 1`
+		prevHistoryCond := `1 = 1`
+		prevPars := make([]interface{}, 0)
+		prevHistoryPars := make([]interface{}, 0)
+
+		if req.CompanyType == 1 {
+			cond += ` AND b.contract_type = 1 `
+			prevCond += ` AND b.contract_type = 1 `
+			histrtyCond += ` AND new_company = 1 `
+			prevHistoryCond += ` AND new_company = 1 `
+		} else if req.CompanyType == 2 {
+			cond += ` AND b.contract_type IN (2,3,4) `
+			prevCond += ` AND b.contract_type IN (2,3,4) `
+			histrtyCond += ` AND new_company = 0 `
+			prevHistoryCond += ` AND new_company = 0 `
+		}
+
+		//if req.SellerIds != "" {
+		//	sellerIds := strings.Split(req.SellerIds, ",")
+		//	cond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
+		//	pars = append(pars, sellerIds, sellerIds)
+		//	prevCond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
+		//	prevPars = append(prevPars, sellerIds, sellerIds)
+		//	histrtyCond += ` AND seller_id in ? `
+		//	prevHistoryCond += ` AND seller_id in ? `
+		//	historyPars = append(historyPars, sellerIds)
+		//	prevHistoryPars = append(prevHistoryPars, sellerIds)
+		//}
+
+
+		{
+			//本期
+			st := fmt.Sprint(startDate, " 00:00:00")
+			ed := fmt.Sprint(endDate, " 23:59:59")
+			//校验日期,分段查询
+			if startDateTime.After(historyTime) || startDateTime.Equal(historyTime) {
+				//全部走新查询
+				//fmt.Println("新查询")
+				cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
+				pars = append(pars, st, ed, st, ed)
+				summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
+				if e != nil {
+					return
+				}
+
+				// 开票到款金额合计(换算后)
+				var amountTotal float64
+
+				if len(summaryIds) > 0 {
+					amountCond := `a.id IN ? `
+					amountPars := make([]interface{}, 0)
+					amountPars = append(amountPars, summaryIds)
+					if req.SellerIds != "" {
+						sellerIds := strings.Split(req.SellerIds, ",")
+						amountCond += ` AND (( b.seller_id IN ? AND a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
+						amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) `
+						amountPars = append(amountPars, sellerIds, st, ed, sellerIds, st, ed)
+					} else {
+						amountCond += ` AND ((a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
+						amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))`
+						amountPars = append(amountPars, st, ed, st, ed)
+					}
+					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
+					if e != nil {
+						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+						return
+					}
+					//dataList = append(dataList, results...)
+					var amountSum float64
+					for _, result := range results {
+						incomeChart.DataList = append(incomeChart.DataList, result)
+						amountSum += result.Amount
+						fmt.Println("result.Amount:", result.Amount)
+					}
+					amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+					accumulate += amountTotal
+					partAccumulate += amountTotal
+				}
+				if i == j || i == numMonth {
+					if req.ListParam == "4" {
+						totalMoneySlice = append(totalMoneySlice, accumulate)
+						if startDateTime.Month() == 12 {
+							accumulate = 0
+						}
+					} else if req.ListParam == "0" {
+						totalMoneySlice = append(totalMoneySlice, amountTotal)
+					} else if i > 0 || i == numMonth {
+						totalMoneySlice = append(totalMoneySlice, partAccumulate)
+						fmt.Println("partAccumulate:", partAccumulate)
+						partAccumulate = 0.0
+					}
+				}
+			} else if endDateTime.Before(historyTime) || endDateTime.Equal(historyTime) {
+				//全部走旧查询
+				//fmt.Println("旧查询")
+				//fmt.Println("st:",st)
+				//fmt.Println("ed:",ed)
+				histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
+				historyPars = append(historyPars, st, ed)
+				//fmt.Println("st:",st)
+				//fmt.Println("ed:",ed)
+				// 开票到款金额合计(换算后)
+				var amountTotal float64
+				results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
+				if e != nil {
+					err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+					return
+				}
+				var amountSum float64
+				//dataList = append(dataList, results...)
+				for _, result := range results {
+					incomeChart.DataList = append(incomeChart.DataList, result)
+					amountSum += result.Amount
+				}
+				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+				accumulate += amountTotal
+				partAccumulate += amountTotal
+
+				if i == j || i == numMonth {
+					if req.ListParam == "4" {
+						totalMoneySlice = append(totalMoneySlice, accumulate)
+						if startDateTime.Month() == 12 {
+							accumulate = 0
+						}
+					} else if req.ListParam == "0" {
+						totalMoneySlice = append(totalMoneySlice, amountTotal)
+					} else if i > 0 || i == numMonth {
+						totalMoneySlice = append(totalMoneySlice, partAccumulate)
+						partAccumulate = 0.0
+					}
+				}
+
+				//fmt.Println("partAccumulate:",partAccumulate)
+			}
+
+		}
+
+		{ // 去年同期,用于计算同比值
+			prevSt := fmt.Sprint(prevStartDate, " 00:00:00") // 格式化上一年同一天的开始时间
+			prevEd := fmt.Sprint(prevEndDate, " 23:59:59")   // 格式化上一年同一天的结束时间
+
+			// 校验日期,分段查询
+			if prevStartDateTime.After(historyTime) || prevStartDateTime.Equal(historyTime) {
+				// 全部走新查询
+				prevCond += ` AND ((b.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))` // 查询条件加入新的时间范围
+				prevPars = append(prevPars, prevSt, prevEd, prevSt, prevEd)                               // 添加时间参数到参数列表
+				prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)        // 获取摘要ID列表
+				if e != nil {
+					return
+				}
+
+				// 开票到款金额合计(换算后)
+				var prevAmountTotal float64
+
+				if len(prevSummaryIds) > 0 {
+					amountCond := `a.id IN ? ` // 查询条件为ID在给定的摘要ID列表中
+					amountPars := make([]interface{}, 0)
+					amountPars = append(amountPars, prevSummaryIds) // 将摘要ID列表添加到参数列表
+					if req.SellerIds != "" {
+						sellerIds := strings.Split(req.SellerIds, ",")
+						amountCond += ` AND (( b.seller_id IN ? AND a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
+						amountCond += `OR ( d.seller_id IN ? AND  a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?)) ` // 根据卖家ID和发票/支付状态筛选时间范围
+						amountPars = append(amountPars, sellerIds, prevSt, prevEd, sellerIds, prevSt, prevEd)                                   // 将卖家ID列表添加到参数列表
+					} else {
+						amountCond += ` AND ((a.invoice_id <> 0 AND b.invoice_time BETWEEN ? AND ?)`
+						amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time BETWEEN ? AND ?))` // 根据发票/支付状态筛选时间范围
+						amountPars = append(amountPars, prevSt, prevEd)
+					}
+					results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars) // 获取合同摘要收入金额数据
+					if e != nil {
+						err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+						return
+					}
+					var amountSum float64
+					//historydataList = append(historydataList, results...)
+					for _, result := range results {
+						amountSum += result.Amount // 累计收入金额
+					}
+					prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64) // 将累计金额转换为浮点数
+					historyAccumulate += prevAmountTotal                                        // 累计历史金额
+					partHistoryAccumulate += prevAmountTotal                                    // 累计部分历史金额
+				}
+				if i == j || i == numMonth {
+					if req.ListParam == "4" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate) // 将累计金额添加到总金额切片中
+						if prevStartDateTime.Month() == 12 {
+							historyAccumulate = 0 // 如果是去年的12月份,则将历史金额清零
+						}
+					} else if req.ListParam == "0" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal) // 将部分历史金额添加到总金额切片中
+					} else if i > 0 || i == numMonth {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate) // 将部分历史金额添加到总金额切片中
+						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
+						partHistoryAccumulate = 0.0 // 清零部分历史金额
+					}
+				}
+			} else if prevEndDateTime.Before(historyTime) || prevEndDateTime.Equal(historyTime) {
+				// 全部走旧查询
+				fmt.Println("prevSt:", prevSt)
+				fmt.Println("prevEd:", prevEd)
+				prevHistoryCond += ` AND (invoice_time BETWEEN ? AND ?)`  // 查询条件加入旧的时间范围
+				prevHistoryPars = append(prevHistoryPars, prevSt, prevEd) // 添加时间参数到参数列表
+				// 开票到款金额合计(换算后)
+				var amountTotal float64
+				results, e := fms.GetIncomeHistory(prevHistoryCond, prevHistoryPars) // 获取历史收入数据
+				if e != nil {
+					err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
+					return
+				}
+				//historydataList = append(historydataList, results...)
+				var amountSum float64
+				for _, result := range results {
+					amountSum += result.Amount // 累计收入金额
+				}
+				amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64) // 将累计金额转换为浮点数
+				historyAccumulate += amountTotal                                        // 累计历史金额
+				partHistoryAccumulate += amountTotal                                    // 累计部分历史金额
+
+				if i == j || i == numMonth {
+					if req.ListParam == "4" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, historyAccumulate) // 将累计金额添加到总金额切片中
+						if prevStartDateTime.Month() == 12 {
+							historyAccumulate = 0 // 如果是去年的12月份,则将历史金额清零
+						}
+					} else if req.ListParam == "0" {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, amountTotal) // 将历史金额添加到总金额切片中
+					} else if i > 0 || i == numMonth {
+						prevTotalMoneySlice = append(prevTotalMoneySlice, partHistoryAccumulate) // 将部分历史金额添加到总金额切片中
+						fmt.Println("partHistoryAccumulate:", partHistoryAccumulate)
+						partHistoryAccumulate = 0.0 // 清零部分历史金额
+					}
+				}
+				if req.ListParam == "1" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01")) // 添加下一个月份的开始日期到日期切片中
+						j = j + 2
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
+						j = j + 3
+					}
+				} else if req.ListParam == "2" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01")) // 添加下五个月份的开始日期到日期切片中
+						j = j + 5
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01")) // 添加下半年的开始日期到日期切片中
+						j = j + 6
+					}
+				} else if req.ListParam == "3" && i == j {
+					if i == 0 {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 11, 0).Format("06/01")) // 添加下十一个月份的开始日期到日期切片中
+						j = j + 11
+					} else {
+						dateSlice = append(dateSlice, startDateTime.AddDate(0, 12, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
+						j = j + 12
+					}
+				} else if i == j {
+					dateSlice = append(dateSlice, startDateTime.Format("06/01")) // 添加当月开始日期到日期切片中
+					j++
+				}
+			}
+			if req.ListParam == "1" && i == j {
+				if i == 0 {
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 2, 0).Format("06/01")) // 添加下一个月份的开始日期到日期切片中
+					j = j + 2
+				} else {
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 3, 0).Format("06/01")) // 添加下一季度的开始日期到日期切片中
+					j = j + 3
+				}
+			} else if req.ListParam == "2" && i == j {
+				if i == 0 {
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 5, 0).Format("06/01")) // 添加下五个月份的开始日期到日期切片中
+					j = j + 5
+				} else {
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 6, 0).Format("06/01")) // 添加下半年的开始日期到日期切片中
+					j = j + 6
+				}
+			} else if req.ListParam == "3" && i == j {
+				if i == 0 {
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 11, 0).Format("06/01"))
+					j = j + 11
+				} else {
+					dateSlice = append(dateSlice, startDateTime.AddDate(0, 12, 0).Format("06/01"))
+					j = j + 12
+				}
+			} else if i == j {
+				dateSlice = append(dateSlice, startDateTime.Format("06/01"))
+				j++
+			}
+		}
+	}
+
+	fmt.Println("prevTotalMoneySlice:", len(prevTotalMoneySlice))
+	fmt.Println("totalMoneySlice:", len(totalMoneySlice))
+
+	if req.CompanyType != 3 {
+		//计算同比值
+		for i := range prevTotalMoneySlice {
+			var yoy float64
+			var yoyStr string
+			totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", totalMoneySlice[i]), 64)
+			if prevTotalMoneySlice[i] != 0 && totalMoneySlice[i] != 0 {
+				yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
+				yoyStr = fmt.Sprintf("%.4f", yoy)
+
+				if i == len(prevTotalMoneySlice)-1 && i > 0 && req.ListParam == "3" {
+					fmt.Println("totalMoneySlice[i-1]:", totalMoneySlice[i-1])
+					yoy = (totalMoneySlice[i] - totalMoneySlice[i-1]) / totalMoneySlice[i-1]
+					yoyStr = fmt.Sprintf("%.4f", yoy)
+				}
+			}
+			yoySlice = append(yoySlice, yoyStr)
+		}
+	} else {
+		// 当筛选条件是”月度“时,并且客户是”未续约“客户,展示柱形图和曲线图
+		// 当筛选条件是”季度“、”半年度“、”年度“、”月度统计“时,并且客户是”未续约“时,仅展示柱形图,无曲线图
+		// 未续约收入金额=去年同期总收入金额(新客户+老客户)-当期老客户收入金额
+		// 移动平均值:若是10月份,计算8月,9月,10月,这三个月的收入金额平均值
+		for i := range prevTotalMoneySlice {
+			totalMoneySlice[i], _ = strconv.ParseFloat(fmt.Sprintf("%.2f", prevTotalMoneySlice[i]-totalMoneySlice[i]), 64)
+
+			var yoy float64
+			var yoyStr string
+			if i > 1 && req.ListParam == "0" {
+				// 前俩月没有
+				yoy = (totalMoneySlice[i] + totalMoneySlice[i-1] + totalMoneySlice[i-2]) / 3
+				yoyStr = fmt.Sprintf("%.4f", yoy)
+				yoySlice = append(yoySlice, yoyStr)
+			} else {
+				yoySlice = append(yoySlice, "")
+			}
+		}
+	}
+
+	incomeChart.Title = "开票到款统计图"
+	incomeChart.Date = dateSlice
+	incomeChart.TotalMoney = totalMoneySlice
+	incomeChart.PrevTotalMoney = prevTotalMoneySlice
+	incomeChart.Yoy = yoySlice
+
+
+
+	return
+}

+ 1 - 1
controller/contract/register.go

@@ -984,7 +984,7 @@ func (rg *RegisterController) Edit(c *gin.Context) {
 	originHasInvoice := item.HasInvoice
 
 	updateCols := []string{
-		"ProductIds", "ContractCode", "RelateContractCode", "CrmContractId", "ContractSource", "CompanyName",
+		"ProductIds", "ContractCode", "RelateContractCode","RelateContractMainCode", "CrmContractId", "ContractSource", "CompanyName",
 		"SellerId", "SellerName", "ContractType", "ContractAmount", "StartDate", "EndDate", "SignDate", "AgreedPayTime", "RaiSellerId", "RaiSellerName",
 		"ContractStatus", "RegisterStatus", "Remark", "ServiceRemark", "HasPayment", "ModifyTime", "HasInvoice", "ActualPayCompanies",
 	}

+ 36 - 36
models/fms/contract_register.go

@@ -41,7 +41,7 @@ type ContractRegister struct {
 	HasPayment             int       `gorm:"column:has_payment" json:"has_payment" description:"是否有代付: 0-无; 1-有"`
 	HasInvoice             int       `gorm:"column:has_invoice" json:"has_invoice" description:"是否需要开票到款: 0-无; 1-有"`
 	NewCompany             int       `gorm:"column:new_company" json:"new_company" description:"是否为新客户: 0-否; 1-是"`
-	ActualPayCompanies string    `gorm:"column:actual_pay_companies" json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
+	ActualPayCompanies     string    `gorm:"column:actual_pay_companies" json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 	IsDeleted              int       `gorm:"column:is_deleted" json:"is_deleted" description:"是否已删除: 0-正常; 1-已删除"`
 	base.TimeBase
 }
@@ -115,38 +115,39 @@ type ContractRegisterListReq struct {
 
 // ContractRegisterItem 合同登记
 type ContractRegisterItem struct {
-	ContractRegisterId int     `json:"contract_register_id" description:"登记ID"`
-	ContractCode       string  `json:"contract_code" description:"合同编号"`
-	RelateContractCode string  `json:"relate_contract_code" description:"关联合同编号"`
-	CrmContractId      int     `json:"crm_contract_id" description:"CRM系统-合同ID"`
-	ContractSource     int     `json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
-	CompanyName        string  `json:"company_name" description:"客户名称"`
-	ActualCompanyName  string  `json:"actual_company_name" description:"实际使用方"`
-	ProductIds         string  `json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
-	SellerId           int     `json:"seller_id" description:"CRM系统-销售ID"`
-	SellerName         string  `json:"seller_name" description:"CRM系统-销售名称"`
-	RaiSellerId        int     `json:"rai_seller_id"  description:"CRM系统-权益销售ID"`
-	RaiSellerName      string  `json:"rai_seller_name" description:"CRM系统-权益销售名称"`
-	ContractType       int     `json:"contract_type" description:"合同类型: 1-新签; 2-续约"`
-	ContractAmount     float64 `json:"contract_amount" description:"合同金额"`
-	InvoicedAmount     float64 `json:"invoiced_amount" description:"开票金额"`
-	PaymentAmount      float64 `json:"payment_amount" description:"到款金额"`
-	CurrencyUnit       string  `json:"currency_unit" description:"货币国际代码"`
-	RMBRate            float64 `json:"rmb_rate" description:"人民币汇率(create_time当日)"`
-	StartDate          string  `json:"start_date" description:"合同开始日期"`
-	EndDate            string  `json:"end_date" description:"合同结束日期"`
-	SignDate           string  `json:"sign_date" description:"合同签订日期"`
-	AgreedPayTime      string  `json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
-	ContractStatus     int     `json:"contract_status" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回"`
-	RegisterStatus     int     `json:"register_status" description:"登记状态: 1-进行中; 2-已完成;"`
-	Remark             string  `json:"remark" description:"备注信息"`
-	ServiceRemark      string  `json:"service_remark" description:"套餐备注信息"`
-	HasPayment         int     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
-	HasInvoice         int     `json:"has_invoice" description:"是否需要开票到款: 0-无; 1-有"`
-	NewCompany         int     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
-	ActualPayCompanies string  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
-	CreateTime         string  `json:"create_time" description:"登记时间"`
-	SellerIds          string  `json:"seller_ids"`
+	ContractRegisterId     int     `json:"contract_register_id" description:"登记ID"`
+	ContractCode           string  `json:"contract_code" description:"合同编号"`
+	RelateContractCode     string  `json:"relate_contract_code" description:"关联合同编号"`
+	RelateContractMainCode string  `json:"relate_contract_main_code" description:"关联合同主编号"`
+	CrmContractId          int     `json:"crm_contract_id" description:"CRM系统-合同ID"`
+	ContractSource         int     `json:"contract_source" description:"合同来源: 0-非系统合同导入; 1-CRM合同导入"`
+	CompanyName            string  `json:"company_name" description:"客户名称"`
+	ActualCompanyName      string  `json:"actual_company_name" description:"实际使用方"`
+	ProductIds             string  `json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
+	SellerId               int     `json:"seller_id" description:"CRM系统-销售ID"`
+	SellerName             string  `json:"seller_name" description:"CRM系统-销售名称"`
+	RaiSellerId            int     `json:"rai_seller_id"  description:"CRM系统-权益销售ID"`
+	RaiSellerName          string  `json:"rai_seller_name" description:"CRM系统-权益销售名称"`
+	ContractType           int     `json:"contract_type" description:"合同类型: 1-新签; 2-续约"`
+	ContractAmount         float64 `json:"contract_amount" description:"合同金额"`
+	InvoicedAmount         float64 `json:"invoiced_amount" description:"开票金额"`
+	PaymentAmount          float64 `json:"payment_amount" description:"到款金额"`
+	CurrencyUnit           string  `json:"currency_unit" description:"货币国际代码"`
+	RMBRate                float64 `json:"rmb_rate" description:"人民币汇率(create_time当日)"`
+	StartDate              string  `json:"start_date" description:"合同开始日期"`
+	EndDate                string  `json:"end_date" description:"合同结束日期"`
+	SignDate               string  `json:"sign_date" description:"合同签订日期"`
+	AgreedPayTime          string  `json:"agreed_pay_time" description:"约定付款时间(如:生效日起10日内)"`
+	ContractStatus         int     `json:"contract_status" description:"合同状态: 1-已审批; 2-单章寄出; 3-已签回"`
+	RegisterStatus         int     `json:"register_status" description:"登记状态: 1-进行中; 2-已完成;"`
+	Remark                 string  `json:"remark" description:"备注信息"`
+	ServiceRemark          string  `json:"service_remark" description:"套餐备注信息"`
+	HasPayment             int     `json:"has_payment" description:"是否有代付: 0-无; 1-有"`
+	HasInvoice             int     `json:"has_invoice" description:"是否需要开票到款: 0-无; 1-有"`
+	NewCompany             int     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	ActualPayCompanies     string  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
+	CreateTime             string  `json:"create_time" description:"登记时间"`
+	SellerIds              string  `json:"seller_ids"`
 }
 
 // ContractRegisterList 合同登记列表
@@ -195,7 +196,7 @@ type ContractRegisterAddReq struct {
 	ContractRegisterId     int                           `json:"contract_register_id" description:"登记ID"`
 	Services               []ContractServiceAddReq       `json:"services" description:"服务套餐内容"`
 	ServiceAmount          []ContractServiceAmountAddReq `json:"service_amount" description:"服务套餐金额"`
-	ActualPayCompanies string                  `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
+	ActualPayCompanies     string                        `json:"actual_pay_companies" description:"合同关联的所有代付方名称, 英文逗号拼接"`
 }
 
 // ContractRegisterEditReq 编辑合同登记请求体
@@ -707,7 +708,6 @@ func UpdateContractPreRegister(item *ContractRegister, updateCols []string, serv
 	return
 }
 
-
 // UpdateContractRegister 预登记保存和更新
 func UpdateContractRegisterPre(item *ContractRegister, updateCols []string, serviceDetail []*ContractServiceAndDetail,
 	invoiceList []*ContractInvoice, invoiceUpdateCols []string, invoiceHandleType int, ppList []*ContractPreRegister) (err error) {
@@ -932,7 +932,7 @@ type CheckContractDuplicateResp struct {
 	Type  int `json:"type" description:"重复的合同类型:0预登记,1合规登记"`
 }
 type ContractServiceDuplicateItem struct {
-	Ids string
+	Ids                string
 	ContractRegisterId int
 }