Ver código fonte

Merge branch '2.8' into debug

# Conflicts:
#	controller/census/invoice_payment.go
#	models/fms/invoice_payment_summary.go
#	routers/census.go
ziwen 1 ano atrás
pai
commit
2c16da3919

+ 553 - 162
controller/census/invoice_payment.go

@@ -10,8 +10,10 @@ import (
 	"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"
 	fmsService "hongze/fms_api/services/fms"
 	"hongze/fms_api/utils"
 	"net/http"
@@ -21,7 +23,6 @@ import (
 	"sync"
 	"time"
 )
-
 // InvoicePaymentController 商品到款统计
 type InvoicePaymentController struct{}
 
@@ -1057,7 +1058,7 @@ func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeL
 	if latestTime.IsZero() {
 		latestTime = time.Now()
 	}
-	
+
 	latestTime = latestTime.AddDate(0, 0, -latestTime.Day()+1)
 
 	var dateSlice []string
@@ -1573,9 +1574,9 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 		}
 	}
 
-	if req.ListParam == 1{
+	if req.ListParam == 1 {
 		cond += ` AND a.service_product_id = 1 `
-	}else if req.ListParam == 2 {
+	} else if req.ListParam == 2 {
 		cond += ` AND a.service_product_id = 2 `
 	}
 
@@ -1604,7 +1605,6 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 	//	pars = append(pars, st, ed, st, ed)
 	//}
 
-
 	//if req.HasInvoice == "1" {
 	//	cond += ` AND a.invoice_id > 0 `
 	//}else if req.HasInvoice == "0" {
@@ -1617,8 +1617,6 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 	//	cond += ` AND a.payment_id = 0 `
 	//}
 
-
-
 	page := new(base.Page)
 	page.SetPageSize(req.PageSize)
 	page.SetCurrent(req.Current)
@@ -1632,24 +1630,23 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 	}
 	if req.SortParam == "" {
 		page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: false})
-	}else if req.SortParam == "start_date" {
+	} else if req.SortParam == "start_date" {
 		if req.SortType == "asc" {
 			page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: true})
-		}else{
+		} else {
 			page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: false})
 		}
-	}else if req.SortParam == "end_date" {
+	} else if req.SortParam == "end_date" {
 		if req.SortType == "asc" {
 			page.AddOrderItem(base.OrderItem{Column: "e.end_date", Asc: true})
-		}else{
+		} else {
 			page.AddOrderItem(base.OrderItem{Column: "e.end_date", Asc: false})
 		}
-	}else{
+	} else {
 		resp.Fail("排序字段不正确", c)
 		return
 	}
 
-
 	if req.IsExport == 1 {
 		page.SetPageSize(10000)
 		page.SetCurrent(1)
@@ -1671,6 +1668,14 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 		// 获取汇总数据IDs, 用于查询合计数据
 		summaryIdsCond := cond
 		summaryIdsPars := pars
+		if req.SellerIds != "" {
+			sellerIds := strings.Split(req.SellerIds, ",")
+			summaryIdsCond += ` AND c.seller_id in ? AND a.payment_id <> 0 AND a.invoice_id = 0  AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
+			summaryIdsPars = append(summaryIdsPars, sellerIds)
+		} else {
+			summaryIdsCond += ` AND a.payment_id <> 0 AND a.invoice_id = 0  AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
+			summaryIdsPars = append(summaryIdsPars)
+		}
 		summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(summaryIdsCond, summaryIdsPars)
 		if e != nil {
 			resp.FailMsg("获取失败", "获取商品到款汇总IDs失败, Err: "+e.Error(), c)
@@ -1682,7 +1687,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 		wg := sync.WaitGroup{}
 
 		// 响应列表
-		respList := make([]*fms.InvoicePaymentCensusItem, 0)
+		respList := make([]*fms.NotPaymentCensusItem, 0)
 		summaryList := make([]*fms.InvoicePaymentSummaryItem, 0)
 		wg.Add(1)
 		go func() {
@@ -1693,6 +1698,15 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 			summaryCond += ` AND a.register_id IN ?`
 			summaryPars := pars
 			summaryPars = append(summaryPars, queryRegisterIds)
+			if req.SellerIds != "" {
+				sellerIds := strings.Split(req.SellerIds, ",")
+				summaryCond += ` AND d.seller_id in ? AND a.payment_id <> 0 AND a.invoice_id = 0 `
+				summaryPars = append(summaryPars, sellerIds, sellerIds)
+			} else {
+				summaryCond += ` AND a.payment_id <> 0 AND a.invoice_id = 0 `
+				summaryPars = append(summaryPars)
+			}
+
 			summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
 			if e != nil {
 				resp.FailMsg("获取失败", "获取商品到款汇总列表失败, Err: "+e.Error(), c)
@@ -1707,7 +1721,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 					paymentIds = append(paymentIds, summaryList[i].PaymentId)
 				}
 			}
-
+			fmt.Println("paymentIds:", paymentIds)
 			// 合同套餐
 			/*contractServiceCond := `contract_register_id IN ?`
 			contractServicePars := make([]interface{}, 0)
@@ -1754,10 +1768,10 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 			}
 
 			// 重组汇总数据
-			summaryMap := make(map[int][]*fms.InvoicePaymentCensusInfo)
+			summaryMap := make(map[int][]*fms.NotPaymentCensusInfo)
 			amountMap := make(map[string]*fms.ContractPaymentServiceAmount)
 			for i := range summaryList {
-				v := new(fms.InvoicePaymentCensusInfo)
+				v := new(fms.NotPaymentCensusInfo)
 				v.InvoiceId = summaryList[i].InvoiceId
 				v.InvoiceDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].InvoiceDate)
 				v.InvoiceAmount = summaryList[i].InvoiceAmount
@@ -1818,7 +1832,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 
 			// 响应列表
 			for i := range registerList {
-				v := new(fms.InvoicePaymentCensusItem)
+				v := new(fms.NotPaymentCensusItem)
 				v.SummaryId = registerList[i].SummaryId
 				v.ContractRegisterId = registerList[i].ContractRegisterId
 				v.CompanyName = registerList[i].CompanyName
@@ -1945,10 +1959,10 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				return
 			}
 			for _, v := range contractRegisters {
-				if v.RMBRate == 0.0{
+				if v.RMBRate == 0.0 {
 					v.RMBRate = 1
 				}
-				amount,_ := strconv.ParseFloat(fmt.Sprintf("%.2f",v.ContractAmount / v.RMBRate), 64)
+				amount, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.ContractAmount/v.RMBRate), 64)
 				contractAmount += amount
 				contractSumMap[v.CurrencyUnit] = v.ContractAmount
 			}
@@ -1975,7 +1989,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 		results.DataList = respList
 		results.InvoiceTotal = invoiceTotal
 		results.PaymentTotal = paymentTotal
-		results.NotInvoiceTotal = contractAmount-invoiceTotal
+		results.NotInvoiceTotal = contractAmount - invoiceTotal
 		results.InvoiceCurrencyTotal = invoiceCurrencyTotals
 		results.PaymentCurrencyTotal = paymentCurrencyTotals
 		results.NotInvoiceCurrencyTotal = contractAmountCurrencyTotals
@@ -1993,6 +2007,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 	resp.OkData("获取成功", baseData, c)
 }
 
+
 // List
 // @Title 开票未到款统计列表
 // @Description 开票未到款统计列表
@@ -2051,9 +2066,9 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 		}
 	}
 
-	if req.ListParam == 1{
+	if req.ListParam == 1 {
 		cond += ` AND a.service_product_id = 1 `
-	}else if req.ListParam == 2 {
+	} else if req.ListParam == 2 {
 		cond += ` AND a.service_product_id = 2 `
 	}
 
@@ -2082,7 +2097,6 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 	//	pars = append(pars, st, ed, st, ed)
 	//}
 
-
 	//if req.HasInvoice == "1" {
 	//	cond += ` AND a.invoice_id > 0 `
 	//}else if req.HasInvoice == "0" {
@@ -2095,14 +2109,12 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 	//	cond += ` AND a.payment_id = 0 `
 	//}
 
-
-
 	page := new(base.Page)
 	page.SetPageSize(req.PageSize)
 	page.SetCurrent(req.Current)
 	//排序
 	if req.SortType == "" {
-		req.SortType = "desc"
+		req.SortType = "asc"
 	}
 	if req.SortType != "desc" && req.SortType != "asc" {
 		resp.Fail("排序类型不正确", c)
@@ -2110,11 +2122,10 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 	}
 	if req.SortType == "asc" {
 		page.AddOrderItem(base.OrderItem{Column: "e.invoice_time", Asc: true})
-	}else{
+	} else {
 		page.AddOrderItem(base.OrderItem{Column: "e.invoice_time", Asc: false})
 	}
 
-
 	if req.IsExport == 1 {
 		page.SetPageSize(10000)
 		page.SetCurrent(1)
@@ -2136,6 +2147,14 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 		// 获取汇总数据IDs, 用于查询合计数据
 		summaryIdsCond := cond
 		summaryIdsPars := pars
+		if req.SellerIds != "" {
+			sellerIds := strings.Split(req.SellerIds, ",")
+			summaryIdsCond += ` AND c.seller_id in ? AND a.invoice_id <> 0  AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
+			summaryIdsPars = append(summaryIdsPars, sellerIds)
+		} else {
+			summaryIdsCond += ` AND a.invoice_id <> 0  AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
+			summaryIdsPars = append(summaryIdsPars)
+		}
 		summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(summaryIdsCond, summaryIdsPars)
 		if e != nil {
 			resp.FailMsg("获取失败", "获取商品到款汇总IDs失败, Err: "+e.Error(), c)
@@ -2147,7 +2166,7 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 		wg := sync.WaitGroup{}
 
 		// 响应列表
-		respList := make([]*fms.InvoicePaymentCensusItem, 0)
+		respList := make([]*fms.NotPaymentCensusItem, 0)
 		summaryList := make([]*fms.InvoicePaymentSummaryItem, 0)
 		wg.Add(1)
 		go func() {
@@ -2158,6 +2177,14 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 			summaryCond += ` AND a.register_id IN ?`
 			summaryPars := pars
 			summaryPars = append(summaryPars, queryRegisterIds)
+			if req.SellerIds != "" {
+				sellerIds := strings.Split(req.SellerIds, ",")
+				summaryCond += ` AND c.seller_id in ? AND a.invoice_id <> 0  AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
+				summaryPars = append(summaryPars, sellerIds)
+			} else {
+				summaryCond += ` AND a.invoice_id <> 0  AND (c.origin_amount > d.origin_amount OR d.origin_amount IS NULL) `
+				summaryPars = append(summaryPars)
+			}
 			summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
 			if e != nil {
 				resp.FailMsg("获取失败", "获取商品到款汇总列表失败, Err: "+e.Error(), c)
@@ -2165,64 +2192,29 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 			}
 			summaryList = summaryData
 			//summaryIds := make([]int, 0)
-			paymentIds := make([]int, 0)
-			for i := range summaryList {
-				//summaryIds = append(summaryIds, summaryList[i].SummaryId)
-				if summaryList[i].PaymentId > 0 {
-					paymentIds = append(paymentIds, summaryList[i].PaymentId)
-				}
-			}
-
-			// 合同套餐
-			/*contractServiceCond := `contract_register_id IN ?`
-			contractServicePars := make([]interface{}, 0)
-			contractServicePars = append(contractServicePars, queryRegisterIds)
-			contractServiceOB := new(fms.ContractService)
-			contractServiceList, e := contractServiceOB.List(contractServiceCond, contractServicePars)
-			if e != nil {
-				listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
-				return
-			}
-			contractServiceMap := make(map[int][]*fms.ContractService, 0)
-			servicesNameMap := make(map[int][]string, 0)
-			for i := range contractServiceList {
-				if contractServiceMap[contractServiceList[i].ContractRegisterId] == nil {
-					contractServiceMap[contractServiceList[i].ContractRegisterId] = make([]*fms.ContractService, 0)
-				}
-				contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
-				servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
-			}
-			*/
-			servicesNameMap, serviceFormatMap, e := fmsService.GetContractServiceNameFormat(queryRegisterIds)
-			if e != nil {
-				listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
-				return
-			}
-			// 到款套餐分配
-			serviceAmountMap := make(map[int][]*fms.ContractPaymentServiceAmount, 0)
-			if len(paymentIds) > 0 {
-				serviceAmountCond := `contract_payment_id IN ?`
-				serviceAmountPars := make([]interface{}, 0)
-				serviceAmountPars = append(serviceAmountPars, paymentIds)
-				serviceAmountOB := new(fms.ContractPaymentServiceAmount)
-				serviceAmountList, e := serviceAmountOB.List(serviceAmountCond, serviceAmountPars)
-				if e != nil {
-					listErr = fmt.Errorf("获取到款套餐分配列表失败, Err: %s", e.Error())
-					return
-				}
-				for i := range serviceAmountList {
-					if serviceAmountMap[serviceAmountList[i].ContractPaymentId] == nil {
-						serviceAmountMap[serviceAmountList[i].ContractPaymentId] = make([]*fms.ContractPaymentServiceAmount, 0)
-					}
-					serviceAmountMap[serviceAmountList[i].ContractPaymentId] = append(serviceAmountMap[serviceAmountList[i].ContractPaymentId], serviceAmountList[i])
-				}
-			}
+			//for i := range summaryList {
+			//	//summaryIds = append(summaryIds, summaryList[i].SummaryId)
+			//
+			//}
+
+			//// 获取合同的套餐金额信息
+			//serviceAmountList, e := fms.GetContractServiceAmountByContractRegisterIds(queryRegisterIds)
+			//if e != nil {
+			//	resp.FailData("获取合同的套餐金额信息失败", "Err:"+e.Error(), c)
+			//	return
+			//}
+			//serviceAmountMap := make(map[int]map[int]*fms.ContractServiceAmount, 0)
+			//for _, v := range serviceAmountList {
+			//	if _, ok := serviceAmountMap[v.ContractRegisterId]; !ok {
+			//		serviceAmountMap[v.ContractRegisterId] = make(map[int]*fms.ContractServiceAmount)
+			//	}
+			//	serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
+			//}
 
 			// 重组汇总数据
-			summaryMap := make(map[int][]*fms.InvoicePaymentCensusInfo)
-			amountMap := make(map[string]*fms.ContractPaymentServiceAmount)
+			summaryMap := make(map[int][]*fms.NotPaymentCensusInfo)
 			for i := range summaryList {
-				v := new(fms.InvoicePaymentCensusInfo)
+				v := new(fms.NotPaymentCensusInfo)
 				v.InvoiceId = summaryList[i].InvoiceId
 				v.InvoiceDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].InvoiceDate)
 				v.InvoiceAmount = summaryList[i].InvoiceAmount
@@ -2235,35 +2227,7 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 				v.PaymentDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].PaymentDate)
 				v.PaymentAmount = summaryList[i].PaymentAmount
 				v.PayType = summaryList[i].PayType
-
-				// 套餐到款分配
-				svaList := make([]*fms.ContractPaymentServiceAmountItem, 0)
-				amountList := serviceAmountMap[summaryList[i].PaymentId]
-				if amountList != nil {
-					for i := range amountList {
-						k := fmt.Sprintf("%d-%d", amountList[i].ContractPaymentId, amountList[i].ServiceTemplateId)
-						amountMap[k] = amountList[i]
-					}
-				}
-				// 合同对应的所有套餐
-				svList := serviceFormatMap[summaryList[i].RegisterId]
-				if svList != nil {
-					for ii := range svList {
-						vv := new(fms.ContractPaymentServiceAmountItem)
-						vv.ServiceTemplateId = svList[ii].ServiceTemplateId
-						vv.ServiceTemplateName = svList[ii].FormatTitle
-						vv.ServiceTemplatePid = svList[ii].ServiceTemplatePid
-						k2 := fmt.Sprintf("%d-%d", summaryList[i].PaymentId, svList[ii].ServiceTemplateId)
-						a := amountMap[k2]
-						if a != nil {
-							vv.ContractPaymentServiceAmountId = a.ContractPaymentServiceAmountId
-							vv.ContractPaymentId = a.ContractPaymentId
-							vv.Amount = a.Amount
-						}
-						svaList = append(svaList, vv)
-					}
-				}
-				v.ServiceAmountList = svaList
+				v.NotPaymentAmount = summaryList[i].InvoiceAmount - summaryList[i].PaymentAmount
 
 				summaryMap[summaryList[i].SummaryId] = append(summaryMap[summaryList[i].SummaryId], v)
 			}
@@ -2284,27 +2248,26 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 
 			// 响应列表
 			for i := range registerList {
-				v := new(fms.InvoicePaymentCensusItem)
+				v := new(fms.NotPaymentCensusItem)
 				v.SummaryId = registerList[i].SummaryId
 				v.ContractRegisterId = registerList[i].ContractRegisterId
 				v.CompanyName = registerList[i].CompanyName
 				v.NewCompany = registerList[i].NewCompany
 				v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
 				v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
-				v.ServicesName = servicesNameMap[registerList[i].ContractRegisterId]
 				v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
 				v.ContractType = registerList[i].ContractType
 				v.ContractCode = registerList[i].ContractCode
 				v.ContractAmount = registerList[i].ContractAmount
 				v.UnitName = unitMap[registerList[i].CurrencyUnit]
 				v.ProductIds = registerList[i].ProductIds
+				v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].InvoicedAmount
 				respList = append(respList, v)
 			}
 		}()
 
 		// 开票到款金额合计(换算后)
-		// 开票到款金额合计(换算后)
-		var invoiceTotal, paymentTotal, contractAmount float64
+		var invoiceTotal, paymentTotal float64
 		wg.Add(1)
 		go func() {
 			defer wg.Done()
@@ -2332,7 +2295,8 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 		// 分币种金额统计
 		invoiceCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
 		paymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
-		contractAmountCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
+		notpaymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
+		//contractAmountCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
 		wg.Add(1)
 		go func() {
 			defer wg.Done()
@@ -2360,12 +2324,18 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 					Code:     currencyList[i].Code,
 					FlagImg:  currencyList[i].FlagImg,
 				})
-				contractAmountCurrencyTotals = append(contractAmountCurrencyTotals, &fms.InvoiceListCurrencyTotal{
+				notpaymentCurrencyTotals = append(notpaymentCurrencyTotals, &fms.InvoiceListCurrencyTotal{
 					Name:     currencyList[i].Name,
 					UnitName: currencyList[i].UnitName,
 					Code:     currencyList[i].Code,
 					FlagImg:  currencyList[i].FlagImg,
 				})
+				//contractAmountCurrencyTotals = append(contractAmountCurrencyTotals, &fms.InvoiceListCurrencyTotal{
+				//	Name:     currencyList[i].Name,
+				//	UnitName: currencyList[i].UnitName,
+				//	Code:     currencyList[i].Code,
+				//	FlagImg:  currencyList[i].FlagImg,
+				//})
 			}
 
 			if len(summaryIds) == 0 {
@@ -2386,7 +2356,7 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 			}
 			invoiceSumMap := make(map[string]float64)
 			paymentSumMap := make(map[string]float64)
-			contractSumMap := make(map[string]float64)
+			//contractSumMap := make(map[string]float64)
 
 			for i := range invoiceSumGroup {
 				invoiceSumMap[invoiceSumGroup[i].CurrencyUnit] = invoiceSumGroup[i].OriginAmountTotal
@@ -2404,23 +2374,27 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 				a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSumMap[paymentCurrencyTotals[i].Code]), 64)
 				paymentCurrencyTotals[i].Amount = a
 			}
-
-			contractRegisters, err := fms.GetContractInfoByRegisterIds(queryRegisterIds)
-			if err != nil {
-				resp.FailMsg("查询合同信息失败", "查询合同信息失败, Err: "+err.Error(), c)
-				return
-			}
-			for _, v := range contractRegisters {
-				if v.RMBRate == 0.0 {
-					v.RMBRate = 1
-				}
-				amount, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.ContractAmount/v.RMBRate), 64)
-				contractAmount += amount
-				contractSumMap[v.CurrencyUnit] = v.ContractAmount
-			}
-			for _, v := range contractAmountCurrencyTotals {
-				v.Amount = contractSumMap[v.Code] - invoiceSumMap[v.Code]
-			}
+			for i := range notpaymentCurrencyTotals {
+				a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSumMap[invoiceCurrencyTotals[i].Code] - paymentSumMap[paymentCurrencyTotals[i].Code]), 64)
+				notpaymentCurrencyTotals[i].Amount = a
+			}
+
+			//contractRegisters, err := fms.GetContractInfoByRegisterIds(queryRegisterIds)
+			//if err != nil {
+			//	resp.FailMsg("查询合同信息失败", "查询合同信息失败, Err: "+err.Error(), c)
+			//	return
+			//}
+			//for _, v := range contractRegisters {
+			//	if v.RMBRate == 0.0 {
+			//		v.RMBRate = 1
+			//	}
+			//	amount, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.ContractAmount/v.RMBRate), 64)
+			//	contractAmount += amount
+			//	contractSumMap[v.CurrencyUnit] = v.ContractAmount
+			//}
+			//for _, v := range contractAmountCurrencyTotals {
+			//	v.Amount = contractSumMap[v.Code] - invoiceSumMap[v.Code]
+			//}
 
 		}()
 
@@ -2441,10 +2415,8 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 		results.DataList = respList
 		results.InvoiceTotal = invoiceTotal
 		results.PaymentTotal = paymentTotal
-		results.NotInvoiceTotal = contractAmount - invoiceTotal
-		results.InvoiceCurrencyTotal = invoiceCurrencyTotals
-		results.PaymentCurrencyTotal = paymentCurrencyTotals
-		results.NotInvoiceCurrencyTotal = contractAmountCurrencyTotals
+		results.NotPaymentTotal = invoiceTotal - paymentTotal
+		results.NotPaymentCurrencyTotal = notpaymentCurrencyTotals
 	}
 	// 是否导出
 	if req.IsExport == 1 {
@@ -2457,7 +2429,6 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 	baseData.SetList(results)
 	resp.OkData("获取成功", baseData, c)
 }
-
 // ExportNotInvoiceCensusList 导出未开票统计列表
 func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCensusResp) {
 	list := results.DataList
@@ -2509,7 +2480,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 		return
 	}
 	serviceTempListMap := make(map[int]*fms.ContractServiceTemplate)
-	var serviceTempShow [] *fms.ContractServiceTemplate
+	var serviceTempShow []*fms.ContractServiceTemplate
 	for i := range serviceTempList {
 		serviceTempListMap[serviceTempList[i].ServiceTemplateId] = serviceTempList[i]
 	}
@@ -2517,17 +2488,17 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 		if serviceTempList[i].ProductId == 1 {
 			rowTitle = append(rowTitle, serviceTempList[i].Title)
 			serviceTempShow = append(serviceTempShow, serviceTempList[i])
-		}else if serviceTempList[i].ProductId == 2{
-			if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "权益大套餐" || (serviceTempList[i].Title == "策略" && serviceTempListMap[serviceTempList[i].Pid].Pid==0){
-			}else if serviceTempList[i].Title == "医药" || serviceTempList[i].Title == "消费" || serviceTempList[i].Title == "科技" || serviceTempList[i].Title == "智造" {
-			}else {
+		} else if serviceTempList[i].ProductId == 2 {
+			if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "权益大套餐" || (serviceTempList[i].Title == "策略" && serviceTempListMap[serviceTempList[i].Pid].Pid == 0) {
+			} else if serviceTempList[i].Title == "医药" || serviceTempList[i].Title == "消费" || serviceTempList[i].Title == "科技" || serviceTempList[i].Title == "智造" {
+			} else {
 				serviceTempShow = append(serviceTempShow, serviceTempList[i])
 			}
-			if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "45万" ||  serviceTempList[i].Title == "70万" {
+			if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "45万" || serviceTempList[i].Title == "70万" {
 				continue
 			}
 
-			if serviceTempList[i].Pid > 0 &&  serviceTempListMap[serviceTempList[i].Pid].Pid > 0 {
+			if serviceTempList[i].Pid > 0 && serviceTempListMap[serviceTempList[i].Pid].Pid > 0 {
 				continue
 			}
 
@@ -2544,8 +2515,8 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 		v.SetStyle(style)
 		if rowTitle[i] != "权益大套餐" && rowTitle[i] != "医药" && rowTitle[i] != "消费" && rowTitle[i] != "科技" && rowTitle[i] != "智造" {
 			v.VMerge = 1
-			hi ++
-		}else{
+			hi++
+		} else {
 			if insertHi == 0 {
 				insertHi = hi
 			}
@@ -2556,7 +2527,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 
 	// 新增一行放主观和客观
 	specialRow := sheet.AddRow()
-	for i:=0; i< hi; i++ {
+	for i := 0; i < hi; i++ {
 		if i == insertHi {
 			v1 := specialRow.AddCell()
 			v1.SetString("45万")
@@ -2564,25 +2535,25 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 			v1 = specialRow.AddCell()
 			v1.SetString("70万")
 			v1.SetStyle(style)
-			for j:=0; j<8;j++ {
-				if j%2 ==0 {
+			for j := 0; j < 8; j++ {
+				if j%2 == 0 {
 					v1 = specialRow.AddCell()
 					v1.SetString("主观")
 					v1.SetStyle(style)
-				}else{
+				} else {
 					v1 = specialRow.AddCell()
 					v1.SetString("客观")
 					v1.SetStyle(style)
 				}
 			}
-		}else{
+		} else {
 			v := specialRow.AddCell()
 			v.SetString("")
 		}
 	}
 
 	newCompanyMap := map[int]string{0: "否", 1: "是"}
-	sellerTypeMap := map[int]string{1:"FICC销售", 2:"权益销售"}
+	sellerTypeMap := map[int]string{1: "FICC销售", 2: "权益销售"}
 	for k, v := range list {
 		dataRow := sheet.AddRow()
 		// 前四个单元格根据每行开票到款条数向下合并
@@ -2625,15 +2596,15 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 					if item.ServiceTemplateId == serviceTempShow[i].ServiceTemplateId {
 						serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount)
 						break
-					}else if serviceTempShow[i].Pid == item.ServiceTemplateId {
-						serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount/2)
+					} else if serviceTempShow[i].Pid == item.ServiceTemplateId {
+						serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount / 2)
 						break
 					}
 				}
 			}
 			for i := range serviceTempShow {
 				sa := ""
-				if am, ok :=  serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId]; ok {
+				if am, ok := serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId]; ok {
 					sa = am
 				}
 				rowData = append(rowData, sa)
@@ -2668,7 +2639,6 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 	http.ServeContent(c.Writer, c.Request, fileName, time.Now(), content)
 }
 
-
 // ExportNotPaymentCensusList 导出开票未到款统计列表
 func ExportNotPaymentCensusList(c *gin.Context, results *fms.NotInvoicePaymentCensusResp) {
 	list := results.DataList
@@ -2684,6 +2654,7 @@ func ExportNotPaymentCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 		Horizontal: "center",
 		Vertical:   "center",
 		WrapText:   true,
+>>>>>>> 2.8
 	}
 	style.Alignment = alignment
 	style.ApplyAlignment = true
@@ -2877,4 +2848,424 @@ func ExportNotPaymentCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 	c.Writer.Header().Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, fileName))
 	c.Writer.Header().Add("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
 	http.ServeContent(c.Writer, c.Request, fileName, time.Now(), content)
+}
+
+func (ct *InvoicePaymentController) NotInvoiceList2(c *gin.Context) {
+	var req fms.InvoicePaymentCensusListReq
+	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
+	}
+
+	cond := `1 = 1`
+	pars := make([]interface{}, 0)
+	// 客户姓名/合同编号
+	if req.Keyword != "" {
+		kw := "%" + req.Keyword + "%"
+		cond += ` AND (b.company_name LIKE ? OR b.contract_code LIKE ?)`
+		pars = append(pars, kw, kw)
+	}
+	if req.SellerIds != "" {
+		sellerIds := strings.Split(req.SellerIds, ",")
+		cond += ` AND (c.seller_id in ?)`
+		pars = append(pars, sellerIds)
+	}
+	// 套餐筛选
+	if req.ServiceTypes != "" {
+		serviceTypes := strings.Split(req.ServiceTypes, ",")
+		tempRegisterIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
+		if e != nil {
+			resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
+			return
+		}
+		if len(tempRegisterIds) > 0 {
+			cond += ` AND a.register_id IN ?`
+			pars = append(pars, tempRegisterIds)
+		} else {
+			cond += ` AND 1 = 2`
+		}
+	}
+
+	if req.ListParam == 1 {
+		cond += ` AND a.service_product_id = 1 `
+	} else if req.ListParam == 2 {
+		cond += ` AND a.service_product_id = 2 `
+	}
+
+	// 开票到款日期
+	//if req.TimeType != 0 {
+	//	if req.TimeType == 1 &&  req.StartDate != "" && req.EndDate != "" {
+	//		st := fmt.Sprint(req.StartDate, " 00:00:00")
+	//		ed := fmt.Sprint(req.EndDate, " 23:59:59")
+	//		cond += ` AND (c.invoice_time BETWEEN ? AND ?) `
+	//		pars = append(pars, st, ed)
+	//	}else if req.TimeType == 2 &&  req.StartDate != "" && req.EndDate != "" {
+	//		st := fmt.Sprint(req.StartDate, " 00:00:00")
+	//		ed := fmt.Sprint(req.EndDate, " 23:59:59")
+	//		cond += ` AND (d.invoice_time BETWEEN ? AND ?) `
+	//		pars = append(pars, st, ed)
+	//	}else if req.TimeType == 3 &&  req.StartDate != "" && req.EndDate != "" {
+	//		st := fmt.Sprint(req.StartDate, " 00:00:00")
+	//		ed := fmt.Sprint(req.EndDate, " 23:59:59")
+	//		cond += ` AND (c.invoice_time BETWEEN ? AND ?) AND (d.invoice_time BETWEEN ? AND ?) `
+	//		pars = append(pars, st, ed, st, ed)
+	//	}
+	//} else if req.StartDate != "" && req.EndDate != "" {
+	//	st := fmt.Sprint(req.StartDate, " 00:00:00")
+	//	ed := fmt.Sprint(req.EndDate, " 23:59:59")
+	//	cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
+	//	pars = append(pars, st, ed, st, ed)
+	//}
+
+	//if req.HasInvoice == "1" {
+	//	cond += ` AND a.invoice_id > 0 `
+	//}else if req.HasInvoice == "0" {
+	//	cond += ` AND a.invoice_id = 0 `
+	//}
+	//
+	//if req.HasPayment == "1" {
+	//	cond += ` AND a.payment_id > 0 `
+	//}else if req.HasPayment == "0" {
+	//	cond += ` AND a.payment_id = 0 `
+	//}
+
+	page := new(base.Page)
+	page.SetPageSize(req.PageSize)
+	page.SetCurrent(req.Current)
+	//排序
+	if req.SortType == "" {
+		req.SortType = "asc"
+	}
+	if req.SortType != "desc" && req.SortType != "asc" {
+		resp.Fail("排序类型不正确", c)
+		return
+	}
+	if req.SortParam == "" {
+		page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: true})
+	} else if req.SortParam == "start_date" {
+		if req.SortType == "asc" {
+			page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: true})
+		} else {
+			page.AddOrderItem(base.OrderItem{Column: "e.start_date", Asc: false})
+		}
+	} else if req.SortParam == "end_date" {
+		if req.SortType == "asc" {
+			page.AddOrderItem(base.OrderItem{Column: "e.end_date", Asc: true})
+		} else {
+			page.AddOrderItem(base.OrderItem{Column: "e.end_date", Asc: false})
+		}
+	} else {
+		resp.Fail("排序字段不正确", c)
+		return
+	}
+
+	if req.IsExport == 1 {
+		page.SetPageSize(10000)
+		page.SetCurrent(1)
+	}
+
+	cond += ` AND b.payment_amount > b.invoiced_amount AND b.contract_amount <> b.invoiced_amount `
+	registerList, total, e := fms.GetInvoiceCensusPageList(page, cond, pars)
+	if e != nil {
+		resp.FailMsg("获取失败", "获取商品到款统计列表总数失败, Err: "+e.Error(), c)
+		return
+	}
+	queryRegisterIds := make([]int, 0)
+	for _, v := range registerList {
+		queryRegisterIds = append(queryRegisterIds, v.ContractRegisterId)
+	}
+	//fmt.Println("queryRegisterIds:",queryRegisterIds)
+	results := new(fms.NotInvoicePaymentCensusResp)
+	if len(queryRegisterIds) > 0 {
+		// 获取合同的套餐金额信息
+		serviceAmountList, e := fms.GetContractServiceAmountByContractRegisterIds(queryRegisterIds)
+		if e != nil {
+			resp.FailData("获取合同的套餐金额信息失败", "Err:"+e.Error(), c)
+			return
+		}
+		serviceAmountMap := make(map[int]map[int]*fms.ContractServiceAmount, 0)
+		for _, v := range serviceAmountList {
+			if _, ok := serviceAmountMap[v.ContractRegisterId]; !ok {
+				serviceAmountMap[v.ContractRegisterId] = make(map[int]*fms.ContractServiceAmount)
+			}
+			serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
+		}
+
+		// 获取汇总数据IDs, 用于查询合计数据
+		summaryIdsCond := cond
+		summaryIdsPars := pars
+		if req.SellerIds != "" {
+			sellerIds := strings.Split(req.SellerIds, ",")
+			summaryIdsCond += ` AND c.seller_id in ? AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
+			summaryIdsPars = append(summaryIdsPars, sellerIds)
+		} else {
+			summaryIdsCond += ` AND a.payment_id <> 0  AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
+			summaryIdsPars = append(summaryIdsPars)
+		}
+		summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(summaryIdsCond, summaryIdsPars)
+		if e != nil {
+			resp.FailMsg("获取失败", "获取商品到款汇总IDs失败, Err: "+e.Error(), c)
+			return
+		}
+
+		//fmt.Println("summaryIds:",summaryIds)
+		var listErr, totalErr, totalGroupErr error
+		wg := sync.WaitGroup{}
+
+		// 响应列表
+		respList := make([]*fms.NotPaymentCensusItem, 0)
+		summaryList := make([]*fms.NotInvoicePaymentSummaryItem, 0)
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+
+			// 获取汇总数据
+			summaryCond := cond
+			summaryCond += ` AND a.register_id IN ?`
+			summaryPars := pars
+			summaryPars = append(summaryPars, queryRegisterIds)
+			//if req.SellerIds != "" {
+			//	sellerIds := strings.Split(req.SellerIds, ",")
+			//	summaryCond += ` AND c.seller_id in ? AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
+			//	summaryPars = append(summaryPars, sellerIds, sellerIds)
+			//} else {
+			//	summaryCond += ` AND a.payment_id <> 0 AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
+			//	summaryPars = append(summaryPars)
+			//}
+
+			summaryData, e := fms.GetNotInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
+			if e != nil {
+				resp.FailMsg("获取失败", "获取商品到款汇总列表失败, Err: "+e.Error(), c)
+				return
+			}
+			summaryList = summaryData
+			//summaryIds := make([]int, 0)
+			//paymentIds := make([]int, 0)
+			//for i := range summaryList {
+			//	//summaryIds = append(summaryIds, summaryList[i].SummaryId)
+			//}
+			NotInvoiceSummaryMap := make(map[int][]*fms.NotInvoicePaymentSummaryItem, 0)
+			for _, v := range summaryList {
+				NotInvoiceSummaryMap[v.RegisterId] = append(NotInvoiceSummaryMap[v.RegisterId], v)
+			}
+
+			// 重组汇总数据
+			summaryMap := make(map[int][]*fms.NotPaymentCensusInfo)
+			sellerList, e := crmService.GetSellerDepartmentListWithGroupAndTeam()
+			if e != nil {
+				resp.FailData("获取销售失败", "Err:"+e.Error(), c)
+				return
+			}
+			sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
+			for i := range sellerList {
+				sellerMap[sellerList[i].SellerId] = sellerList[i]
+			}
+
+			// 货币列表
+			currencyOB := new(fms.CurrencyUnit)
+			currencyCond := `enable = 1`
+			currencyPars := make([]interface{}, 0)
+			currencyList, e := currencyOB.List(currencyCond, currencyPars)
+			if e != nil {
+				resp.FailMsg("获取失败", "获取货币列表失败, Err: "+e.Error(), c)
+				return
+			}
+			unitMap := make(map[string]string)
+			for i := range currencyList {
+				unitMap[currencyList[i].Code] = currencyList[i].UnitName
+			}
+
+			for registerId, list := range NotInvoiceSummaryMap {
+				for _, v := range list {
+					v.NotInvoicedAmountTotal = serviceAmountMap[registerId][v.ServiceProductId].ServiceAmount - v.InvoiceAmountTotal
+					if v.ServiceProductId == 1 {
+						v.SellerGroupId = sellerMap[v.SellerId].GroupId
+						v.SellerGroupName = sellerMap[v.SellerId].GroupName
+					} else {
+						v.RaiSellerGroupId = sellerMap[v.RaiSellerId].GroupId
+						v.RaiSellerGroupName = sellerMap[v.RaiSellerId].GroupName
+					}
+				}
+			}
+
+			// 响应列表
+			for i := range registerList {
+				v := new(fms.NotPaymentCensusItem)
+				v.SummaryId = registerList[i].SummaryId
+				v.ContractRegisterId = registerList[i].ContractRegisterId
+				v.CompanyName = registerList[i].CompanyName
+				v.NewCompany = registerList[i].NewCompany
+				v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
+				v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
+				v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
+				v.ContractType = registerList[i].ContractType
+				v.ContractCode = registerList[i].ContractCode
+				v.ContractAmount = registerList[i].ContractAmount
+				v.UnitName = unitMap[registerList[i].CurrencyUnit]
+				v.ProductIds = registerList[i].ProductIds
+				v.NotInvoiceTotal = registerList[i].ContractAmount - registerList[i].InvoicedAmount
+				v.NotInvoiceList = NotInvoiceSummaryMap[summaryList[i].RegisterId]
+				respList = append(respList, v)
+			}
+		}()
+
+		// 开票到款金额合计(换算后)
+		var invoiceTotal, paymentTotal, contractAmount float64
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+
+			if len(summaryIds) == 0 {
+				return
+			}
+			amountTotalCond := `a.id IN ?`
+			amountTotalPars := make([]interface{}, 0)
+			amountTotalPars = append(amountTotalPars, summaryIds)
+			invoiceSum, e := fms.GetContractSummaryInvoicePaymentAmountTotal(amountTotalCond, amountTotalPars, 1)
+			if e != nil {
+				totalErr = fmt.Errorf("获取汇总开票金额合计失败, Err: %s", e.Error())
+				return
+			}
+			invoiceTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSum), 64)
+			paymentSum, e := fms.GetContractSummaryInvoicePaymentAmountTotal(amountTotalCond, amountTotalPars, 2)
+			if e != nil {
+				totalErr = fmt.Errorf("获取汇总到款金额合计失败, Err: %s", e.Error())
+				return
+			}
+			paymentTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSum), 64)
+		}()
+
+		// 分币种金额统计
+		invoiceCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
+		paymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
+		contractAmountCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
+		wg.Add(1)
+		go func() {
+			defer wg.Done()
+
+			currencyOB := new(fms.CurrencyUnit)
+			currencyCond := `enable = 1`
+			currencyPars := make([]interface{}, 0)
+			currencyList, e := currencyOB.List(currencyCond, currencyPars)
+			if e != nil {
+				totalGroupErr = fmt.Errorf("获取货币列表失败, Err: %s", e.Error())
+				return
+			}
+			unitMap := make(map[string]string)
+			for i := range currencyList {
+				unitMap[currencyList[i].Code] = currencyList[i].UnitName
+				invoiceCurrencyTotals = append(invoiceCurrencyTotals, &fms.InvoiceListCurrencyTotal{
+					Name:     currencyList[i].Name,
+					UnitName: currencyList[i].UnitName,
+					Code:     currencyList[i].Code,
+					FlagImg:  currencyList[i].FlagImg,
+				})
+				paymentCurrencyTotals = append(paymentCurrencyTotals, &fms.InvoiceListCurrencyTotal{
+					Name:     currencyList[i].Name,
+					UnitName: currencyList[i].UnitName,
+					Code:     currencyList[i].Code,
+					FlagImg:  currencyList[i].FlagImg,
+				})
+				contractAmountCurrencyTotals = append(contractAmountCurrencyTotals, &fms.InvoiceListCurrencyTotal{
+					Name:     currencyList[i].Name,
+					UnitName: currencyList[i].UnitName,
+					Code:     currencyList[i].Code,
+					FlagImg:  currencyList[i].FlagImg,
+				})
+			}
+
+			if len(summaryIds) == 0 {
+				return
+			}
+			totalGroupCond := `a.id IN ?`
+			totalGroupPars := make([]interface{}, 0)
+			totalGroupPars = append(totalGroupPars, summaryIds)
+			invoiceSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 1)
+			if e != nil {
+				totalGroupErr = fmt.Errorf("获取汇总货币合计开票金额失败, Err: %s", e.Error())
+				return
+			}
+			paymentSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 2)
+			if e != nil {
+				totalGroupErr = fmt.Errorf("获取汇总货币合计到款金额失败, Err: %s", e.Error())
+				return
+			}
+			invoiceSumMap := make(map[string]float64)
+			paymentSumMap := make(map[string]float64)
+			contractSumMap := make(map[string]float64)
+
+			for i := range invoiceSumGroup {
+				invoiceSumMap[invoiceSumGroup[i].CurrencyUnit] = invoiceSumGroup[i].OriginAmountTotal
+				continue
+			}
+			for i := range paymentSumGroup {
+				paymentSumMap[paymentSumGroup[i].CurrencyUnit] = paymentSumGroup[i].OriginAmountTotal
+				continue
+			}
+			for i := range invoiceCurrencyTotals {
+				a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSumMap[invoiceCurrencyTotals[i].Code]), 64)
+				invoiceCurrencyTotals[i].Amount = a
+			}
+			for i := range paymentCurrencyTotals {
+				a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSumMap[paymentCurrencyTotals[i].Code]), 64)
+				paymentCurrencyTotals[i].Amount = a
+			}
+
+			contractRegisters, err := fms.GetContractInfoByRegisterIds(queryRegisterIds)
+			if err != nil {
+				resp.FailMsg("查询合同信息失败", "查询合同信息失败, Err: "+err.Error(), c)
+				return
+			}
+			for _, v := range contractRegisters {
+				if v.RMBRate == 0.0 {
+					v.RMBRate = 1
+				}
+				amount, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", v.ContractAmount/v.RMBRate), 64)
+				contractAmount += amount
+				contractSumMap[v.CurrencyUnit] = v.ContractAmount
+			}
+			for _, v := range contractAmountCurrencyTotals {
+				v.Amount = contractSumMap[v.Code] - invoiceSumMap[v.Code]
+			}
+
+		}()
+
+		wg.Wait()
+
+		if listErr != nil {
+			resp.FailMsg("获取失败", listErr.Error(), c)
+			return
+		}
+		if totalErr != nil {
+			resp.FailMsg("获取失败", totalErr.Error(), c)
+			return
+		}
+		if totalGroupErr != nil {
+			resp.FailMsg("获取失败", totalGroupErr.Error(), c)
+			return
+		}
+		results.DataList = respList
+		results.InvoiceTotal = invoiceTotal
+		results.PaymentTotal = paymentTotal
+		results.NotInvoiceTotal = contractAmount - invoiceTotal
+		results.InvoiceCurrencyTotal = invoiceCurrencyTotals
+		results.PaymentCurrencyTotal = paymentCurrencyTotals
+		results.NotInvoiceCurrencyTotal = contractAmountCurrencyTotals
+	}
+
+	// 是否导出
+	if req.IsExport == 1 {
+		ExportNotInvoiceCensusList(c, results)
+		return
+	}
+	page.SetTotal(total)
+	baseData := new(base.BaseData)
+	baseData.SetPage(page)
+	baseData.SetList(results)
+	resp.OkData("获取成功", baseData, c)
 }

+ 50 - 10
models/fms/contract_invoice.go

@@ -610,7 +610,7 @@ func GetDuplicateContractInvoiceDetailItemListWithType(companyName, startDate, e
 	err = global.DEFAULT_MYSQL.Table("contract_invoice as a ").
 		Select(" a.* ").
 		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
-		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) AND a.invoice_type = %v ",companyName, startDate, endDate, invoiceType)).
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) AND a.invoice_type = %v ", companyName, startDate, endDate, invoiceType)).
 		Order("a.contract_invoice_id ASC").
 		Find(&list).Error
 	if err != nil {
@@ -636,7 +636,7 @@ func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate s
 		Select(" a.*,GROUP_CONCAT(c.service_template_id ORDER BY c.service_template_id ) AS template_ids ").
 		Joins(" JOIN contract_register as b ON a.contract_register_id = b.contract_register_id ").
 		Joins("JOIN contract_service AS c ON a.contract_register_id = c.contract_register_id").
-		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) ",companyName, startDate, endDate)).
+		Where(fmt.Sprintf("a.is_deleted = 0 AND b.company_name = '%s' AND b.start_date= '%s' AND b.end_date= '%s' AND b.is_deleted=0 AND (a.invoice_type=3 OR a.invoice_type=4) ", companyName, startDate, endDate)).
 		Group("a.contract_register_id").
 		Order("a.contract_invoice_id ASC").
 		Find(&list).Error
@@ -647,15 +647,15 @@ func GetDuplicateContractInvoiceDetailItemList(companyName, startDate, endDate s
 }
 
 type IncomeListReq struct {
-	SellerIds    string `json:"seller_ids" form:"seller_ids" description:"销售ID,多个ID之间用逗号拼接"`
-	StartDate    string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01" description:"开始日期"`
-	EndDate      string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01" description:"结束日期"`
-	IsExport     int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
-	ListParam    string    `json:"list_param" form:"list_param" description:"套餐类型: 0-月度; 1-季度; 2-半年度;3-年度;4-月度累计"`
-	CompanyType     int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户"`
+	SellerIds   string `json:"seller_ids" form:"seller_ids" description:"销售ID,多个ID之间用逗号拼接"`
+	StartDate   string `json:"start_date" form:"start_date" binding:"omitempty,datetime=2006-01" description:"开始日期"`
+	EndDate     string `json:"end_date" form:"end_date" binding:"omitempty,datetime=2006-01" description:"结束日期"`
+	IsExport    int    `json:"is_export" form:"is_export" description:"是否导出: 0-否; 1-是"`
+	ListParam   string `json:"list_param" form:"list_param" description:"套餐类型: 0-月度; 1-季度; 2-半年度;3-年度;4-月度累计"`
+	CompanyType int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户"`
 }
 
-//获取最新的开票或到款日期
+// 获取最新的开票或到款日期
 func GetLatestIncome(condition string, pars []interface{}) (result *ContractInvoice, err error) {
 	sql := `SELECT
 	a.* 
@@ -668,4 +668,44 @@ WHERE
 	sql += `ORDER BY a.invoice_time DESC  `
 	err = global.DEFAULT_MYSQL.Raw(sql, pars...).First(&result).Error
 	return
-}
+}
+
+// NotPaymentCensusItem 商品到款统计信息
+type NotPaymentCensusItem struct {
+	SummaryId          int                     `json:"summary_id" description:"汇总ID"`
+	ContractRegisterId int                     `json:"contract_register_id" description:"登记ID"`
+	CompanyName        string                  `json:"company_name" description:"客户名称"`
+	NewCompany         int                     `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	StartDate          string                  `json:"start_date" description:"合同开始日期"`
+	EndDate            string                  `json:"end_date" description:"合同结束日期"`
+	ServicesName       string                  `json:"services_name" description:"套餐信息字符串拼接"`
+	ContractType       int                     `json:"contract_type" description:"合同类型: 0-无 1-新签; 2-续约"`
+	ActualPayCompanies string                  `json:"actual_pay_companies" description:"该合同关联的所有代付方, 英文逗号拼接"`
+	InvoicePaymentList []*NotPaymentCensusInfo `json:"invoice_payment_list" description:"开票到款列表"`
+	ContractCode       string                  `gorm:"column:contract_code" json:"contract_code" description:"合同编号"`
+	ContractAmount     float64                 `gorm:"column:contract_amount" json:"contract_amount" description:"合同金额"`
+	UnitName           string                  `gorm:"unit_name" json:"unit_name" description:"单位名称"`
+	ProductIds         string                  `gorm:"column:product_ids" json:"product_ids" description:"产品ID:1-FICC; 2-权益, 如果两者都有,则用英文逗号拼接"`
+	NotInvoiceTotal    float64                 `json:"not_invoice_total" description:"未开票总金额(换算后)"`
+	NotInvoiceList    []*NotInvoicePaymentSummaryItem     `json:"not_invoice_list" description:"未开票invoice列表"`
+}
+
+// NotPaymentCensusInfo 开票到款统计信息
+type NotPaymentCensusInfo struct {
+	InvoiceId         int                                 `json:"invoice_id" description:"开票ID"`
+	InvoiceDate       string                              `json:"invoice_time" description:"开票日期"`
+	InvoiceAmount     float64                             `json:"invoice_amount" description:"开票金额"`
+	SellerId          int                                 `json:"seller_id" description:"销售ID"`
+	SellerName        string                              `json:"seller_name" description:"销售名称"`
+	SellerGroupId     int                                 `json:"seller_group_id" description:"销售组别ID"`
+	SellerGroupName   string                              `json:"seller_group_name" description:"销售组别名称"`
+	PaymentId         int                                 `json:"payment_id" description:"到款ID"`
+	PaymentDate       string                              `json:"payment_date" description:"到款日期"`
+	PaymentAmount     float64                             `json:"payment_amount" description:"到款金额"`
+	PayType           int                                 `json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
+	ServiceAmountList []*ContractPaymentServiceAmountItem `json:"service_amount_list" description:"到款套餐金额分配信息"`
+	SellerType        int                                 `json:"seller_type" description:"销售类型:1ficc销售,2权益销售"`
+	NotPaymentAmount  float64                             `json:"not_payment_amount" description:"开票未到款金额"`
+}
+
+

+ 82 - 39
models/fms/invoice_payment_summary.go

@@ -183,9 +183,39 @@ func GetContractSummaryInvoicePaymentAmount(condition string, pars []interface{}
 	return
 }
 
+// GetInvoicePaymentSummaryByRegisterIdAndInvoiceId 根据合同登记ID和开票ID获取汇总数据
+func GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(registerId, invocieId int) (results []*ContractRegisterSummary, err error) {
+	sql := `SELECT * FROM invoice_payment_summary WHERE register_id = ? AND invoice_id= ? `
+	err = global.DEFAULT_MYSQL.Exec(sql, registerId, invocieId).Find(&results).Error
+	return
+}
+
+type IncomeSummaryItem struct {
+	CompanyName string    `json:"company_name" description:"客户名称"`
+	ContractType  int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
+	InvoiceDate time.Time `json:"invoice_time" description:"开票日期"`
+	Amount      float64   `json:"amount" description:"金额"`
+	SellerName  string    `json:"seller_name" description:"销售名称"`
+}
+
+// GetContractSummaryIncomeAmount 获取汇总金额合计信息
+func GetContractSummaryIncomeAmount(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
+	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
+		Select("IF(a.invoice_id=0,d.amount, b.amount) AS amount,IF(a.invoice_id=0,d.invoice_time, b.invoice_time) AS invoice_date, c.contract_type,c.company_name,IF(a.invoice_id=0,d.seller_name, b.seller_name) AS seller_name,IF(a.invoice_id=0,d.seller_id, b.seller_id) AS final_seller_id").
+		Joins("LEFT JOIN contract_invoice AS b ON a.invoice_id = b.contract_invoice_id AND b.is_deleted = 0 ").
+		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
+		Joins("JOIN contract_register AS c ON a.register_id = c.contract_register_id AND c.is_deleted = 0").
+		Where(condition, pars...).Group("id").Order("invoice_date ")
+	//nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
+	//	Select(" IFNULL( SUM( e.amount ), 0 ) ")
+
+	err = query.Find(&results).Error
+	return
+}
+
 type InvoiceSummary struct {
 	SummaryId           int     `json:"summary_id" description:"汇总ID"`
-	ContractAmountCount float64 `gorm:"column:contract_amount_count" json:"contract_amount_count" description:"合同金额"`
+	PaymentAmountCount  float64 `gorm:"column:payment_amount_count" json:"payment_amount_count" description:"到款金额"`
 	InvoicedAmountCount float64 `gorm:"column:invoiced_amount_count" json:"invoiced_amount_count" description:"开票金额"`
 	ContractRegister
 }
@@ -193,11 +223,11 @@ type InvoiceSummary struct {
 // GetInvoiceCensusPageList 获取未开票统计列表-总数
 func GetInvoiceCensusPageList(page base.IPage, condition string, pars []interface{}) (results []*InvoiceSummary, count int64, err error) {
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
-		Select("b.*, a.id as summary_id, IF(a.invoice_id >0, 1,0) as sort_invoice_id, IF(a.payment_id >0, 1,0) as sort_payment_id, SUM( c.amount ) AS invoiced_amount_count,SUM( d.amount ) AS payment_amount_count ").
+		Select("b.*, a.id as summary_id, IF(a.invoice_id >0, 1,0) as sort_invoice_id, IF(a.payment_id >0, 1,0) as sort_payment_id, COALESCE(SUM( c.amount ),0) AS invoiced_amount_count,COALESCE(SUM( d.amount ),0) AS payment_amount_count ").
 		Joins("JOIN contract_register AS b ON a.register_id = b.contract_register_id AND b.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS c ON a.invoice_id = c.contract_invoice_id AND c.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
-		Where(condition, pars...).Group("b.contract_register_id")
+		Where(condition, pars...).Group("contract_register_id")
 
 	nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
 		Select("*").Where(" e.invoiced_amount_count <>  e.contract_amount ")
@@ -215,16 +245,15 @@ func GetInvoiceCensusPageList(page base.IPage, condition string, pars []interfac
 // GetNoPaymentCensusPageList 获取开票未到款统计计列表-总数
 func GetNoPaymentCensusPageList(page base.IPage, condition string, pars []interface{}) (results []*InvoiceSummary, count int64, err error) {
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
-		Select("b.*, a.id as summary_id, IF(a.invoice_id >0, 1,0) as sort_invoice_id, IF(a.payment_id >0, 1,0) as sort_payment_id, SUM( c.amount ) AS invoiced_amount_count,SUM( d.amount ) AS payment_amount_count " +
+		Select("b.*, a.id as summary_id, IF(a.invoice_id >0, 1,0) as sort_invoice_id, IF(a.payment_id >0, 1,0) as sort_payment_id, COALESCE(SUM( c.amount ),0) AS invoiced_amount_count,COALESCE(SUM( d.amount ),0) AS payment_amount_count "+
 			" ,c.invoice_time ").
 		Joins("JOIN contract_register AS b ON a.register_id = b.contract_register_id AND b.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS c ON a.invoice_id = c.contract_invoice_id AND c.is_deleted = 0").
 		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
-		Where(condition, pars...).Group("b.contract_register_id")
-
+		Where(condition, pars...).Group("contract_register_id")
 
 	nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
-		Select("*").Where(" e.invoiced_amount_count <>  e.contract_amount AND e.payment_amount = 0 ")
+		Select("*")
 	nq.Count(&count)
 	if len(page.GetOrderItemsString()) > 0 {
 		nq = nq.Order(page.GetOrderItemsString())
@@ -238,43 +267,15 @@ func GetNoPaymentCensusPageList(page base.IPage, condition string, pars []interf
 
 // NotInvoicePaymentCensusResp 未开票到款到款统计响应体
 type NotInvoicePaymentCensusResp struct {
-	DataList                []*InvoicePaymentCensusItem `json:"data_list"`
+	DataList                []*NotPaymentCensusItem     `json:"data_list"`
 	InvoiceTotal            float64                     `json:"invoice_total" description:"开票总金额(换算后)"`
 	PaymentTotal            float64                     `json:"payment_total" description:"到款总金额(换算后)"`
 	InvoiceCurrencyTotal    []*InvoiceListCurrencyTotal `json:"invoice_currency_total" description:"开票-分币种总金额"`
 	PaymentCurrencyTotal    []*InvoiceListCurrencyTotal `json:"payment_currency_total" description:"到款-分币种总金额"`
 	NotInvoiceTotal         float64                     `json:"not_invoice_total" description:"未开票总金额(换算后)"`
 	NotInvoiceCurrencyTotal []*InvoiceListCurrencyTotal `json:"not_invoice_currency_total" description:"未开票-分币种总金额"`
-}
-
-// GetInvoicePaymentSummaryByRegisterIdAndInvoiceId 根据合同登记ID和开票ID获取汇总数据
-func GetInvoicePaymentSummaryByRegisterIdAndInvoiceId(registerId, invocieId int) (results []*ContractRegisterSummary, err error) {
-	sql := `SELECT * FROM invoice_payment_summary WHERE register_id = ? AND invoice_id= ? `
-	err = global.DEFAULT_MYSQL.Exec(sql, registerId, invocieId).Find(&results).Error
-	return
-}
-
-type IncomeSummaryItem struct {
-	CompanyName string    `json:"company_name" description:"客户名称"`
-	ContractType  int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
-	InvoiceDate time.Time `json:"invoice_time" description:"开票日期"`
-	Amount      float64   `json:"amount" description:"金额"`
-	SellerName  string    `json:"seller_name" description:"销售名称"`
-}
-
-// GetContractSummaryIncomeAmount 获取汇总金额合计信息
-func GetContractSummaryIncomeAmount(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
-	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
-		Select("IF(a.invoice_id=0,d.amount, b.amount) AS amount,IF(a.invoice_id=0,d.invoice_time, b.invoice_time) AS invoice_date, c.contract_type,c.company_name,IF(a.invoice_id=0,d.seller_name, b.seller_name) AS seller_name,IF(a.invoice_id=0,d.seller_id, b.seller_id) AS final_seller_id").
-		Joins("LEFT JOIN contract_invoice AS b ON a.invoice_id = b.contract_invoice_id AND b.is_deleted = 0 ").
-		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
-		Joins("JOIN contract_register AS c ON a.register_id = c.contract_register_id AND c.is_deleted = 0").
-		Where(condition, pars...).Group("id").Order("invoice_date ")
-	//nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
-	//	Select(" IFNULL( SUM( e.amount ), 0 ) ")
-
-	err = query.Find(&results).Error
-	return
+	NotPaymentTotal         float64                     `json:"not_payment_total" description:"未开票总金额(换算后)"`
+	NotPaymentCurrencyTotal []*InvoiceListCurrencyTotal `json:"not_payment_currency_total" description:"未开票-分币种总金额"`
 }
 
 type IncomeSummaryItemList []*IncomeSummaryItem
@@ -289,4 +290,46 @@ func (c IncomeSummaryItemList) Less(i, j int) bool {
 
 func (c IncomeSummaryItemList) Swap(i, j int) {
 	c[i], c[j] = c[j], c[i]
-}
+}
+
+type NotInvoicePaymentSummaryItem struct {
+	SummaryId              int       `json:"summary_id" description:"汇总ID"`
+	RegisterId             int       `json:"register_id" description:"登记ID"`
+	NewCompany             int       `json:"new_company" description:"是否为新客户: 0-否; 1-是"`
+	InvoiceId              int       `json:"invoice_id" description:"开票ID"`
+	InvoiceDate            time.Time `json:"invoice_time" description:"开票日期"`
+	InvoiceAmount          float64   `json:"invoice_amount" description:"开票金额"`
+	SellerGroupId          int       `json:"seller_group_id" description:"销售组别ID"`
+	SellerGroupName        string    `json:"seller_group_name" description:"销售组别名称"`
+	RaiSellerGroupId       int       `json:"rai_seller_group_id" description:"销售组别ID"`
+	RaiSellerGroupName     string    `json:"rai_seller_group_name" description:"销售组别名称"`
+	PaymentId              int       `json:"payment_id" description:"到款ID"`
+	PaymentDate            time.Time `json:"payment_date" description:"到款日期"`
+	PaymentAmount          float64   `json:"payment_amount" description:"到款金额"`
+	PayType                int       `json:"pay_type" description:"付款方式:0-无;1-年付;2-半年付;3-季付;4-次付;5-异常"`
+	ServiceProductId       int       `json:"service_product_id" description:"套餐类型:1ficc套餐,2权益套餐"`
+	ContractAmount         float64   `gorm:"column:contract_amount" json:"contract_amount" description:"合同金额"`
+	InvoicedAmount         float64   `gorm:"column:invoiced_amount" json:"invoiced_amount" description:"开票金额"`
+	CurrencyUnit           string    `gorm:"column:currency_unit" json:"currency_unit" description:"货币国际代码"`
+	RMBRate                float64   `gorm:"column:rmb_rate" json:"rmb_rate" description:"人民币汇率(create_time当日)"`
+	PaymentAmountTotal     float64   `gorm:"column:payment_amount_total" json:"payment_amount_total" description:"合同金额"`
+	InvoiceAmountTotal     float64   `gorm:"column:invoice_amount_total" json:"invoice_amount_total" description:"开票金额"`
+	NotInvoicedAmountTotal float64   ` json:"not_invoiced_amount_total" description:"未开票金额"`
+	ContractRegister
+}
+
+// GetNotInvoicePaymentCensusSummaryData 获取商品到款统计列表-汇总数据
+func GetNotInvoicePaymentCensusSummaryData(condition string, pars []interface{}) (results []*NotInvoicePaymentSummaryItem, err error) {
+	fields := []string{"a.id AS summary_id", "a.register_id", "a.invoice_id", "a.payment_id", "a.service_product_id", "b.*",
+		"c.origin_amount AS invoice_amount", "c.invoice_time AS invoice_date", "d.origin_amount AS payment_amount", "d.invoice_time AS payment_date",
+		"d.pay_type", "COALESCE(SUM( c.origin_amount ),0) AS invoice_amount_total", "COALESCE(SUM( d.origin_amount ),0) AS payment_amount_total",
+	}
+	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
+		Select(strings.Join(fields, ",")).
+		Joins("JOIN contract_register AS b ON a.register_id = b.contract_register_id AND b.is_deleted = 0").
+		Joins("LEFT JOIN contract_invoice AS c ON a.invoice_id = c.contract_invoice_id AND c.is_deleted = 0").
+		Joins("LEFT JOIN contract_invoice AS d ON a.payment_id = d.contract_invoice_id AND d.is_deleted = 0").
+		Where(condition, pars...).Group("a.register_id,service_product_id")
+	query.Find(&results)
+	return
+}

+ 1 - 1
routers/census.go

@@ -11,7 +11,7 @@ func InitCensus(rg *gin.RouterGroup) {
 	inv := new(census.InvoicePaymentController)
 	invGroup := rg.Group("invoice_payment/").Use(middleware.Token())
 	invGroup.GET("list", inv.List)
-	invGroup.GET("not_invoice/list", inv.NotInvoiceList)
+	invGroup.GET("not_invoice/list", inv.NotInvoiceList2)
 	invGroup.GET("not_payment/list", inv.NotPaymentList)
 	invGroup.GET("income/list", inv.IncomeList)