zwxi 1 year ago
parent
commit
ef7cb2a3a4
1 changed files with 157 additions and 4 deletions
  1. 157 4
      controller/census/seller.go

+ 157 - 4
controller/census/seller.go

@@ -483,8 +483,8 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		startDate = fmt.Sprint(req.StartDate, " 00:00:00")
 		endDate = fmt.Sprint(req.EndDate, " 23:59:59")
 	}
-	startDateTime, _ := time.Parse(utils.FormatDate, startDate)
-	endDateTime, _ := time.Parse(utils.FormatDate, endDate)
+	startDateTime, _ := time.Parse(utils.FormatDateTime, startDate)
+	endDateTime, _ := time.Parse(utils.FormatDateTime, endDate)
 
 
 	cond := ` 1 = 1 `
@@ -718,6 +718,88 @@ func (this *SellerController) InvoiceListV2(c *gin.Context) {
 		amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
 		accumulate += amountTotal
 		//fmt.Println("partAccumulate:",partAccumulate)
+	} else {
+		if st != "" && ed != "" {
+			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 {
+				resp.FailMsg("查询错误", fmt.Sprintf("获取汇总数据失败, Err: %s", e.Error()), c)
+				return
+			}
+			//dataList = append(dataList, results...)
+			var amountSum float64
+			for _, result := range results {
+				amountSum += result.Amount
+				fmt.Println("result.Amount:", result.Amount)
+				if _, ok := groupInvoiceMap[result.SellerGroupId]; ok {
+					groupInvoiceMap[result.SellerGroupId] += result.Amount
+				} else {
+					groupInvoiceMap[result.SellerGroupId] = result.Amount
+				}
+				if _, ok := sellerInvoiceMap[result.FinalSellerId]; ok {
+					sellerInvoiceMap[result.FinalSellerId] += result.Amount
+				} else {
+					sellerInvoiceMap[result.FinalSellerId] = result.Amount
+				}
+				if _, ok := sellerGroupMap[result.FinalSellerId]; !ok {
+					sellerGroupMap[result.FinalSellerId] = result.SellerGroupId
+				}
+			}
+			amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			accumulate += amountTotal
+
+			if st != "" && ed != "" {
+				historyCond += ` AND (invoice_time BETWEEN ? AND ? )`
+				historyPars = append(historyPars, st, ed)
+			}
+			results, e = fms.GetIncomeHistory(historyCond, historyPars)
+			if e != nil {
+				resp.FailMsg("查询错误", fmt.Sprintf("获取汇总数据失败, Err: %s", e.Error()), c)
+				return
+			}
+			for _, result := range results {
+				amountSum += result.Amount
+				if _, ok := groupInvoiceMap[result.SellerGroupId]; ok {
+					groupInvoiceMap[result.SellerGroupId] += result.Amount
+				} else {
+					groupInvoiceMap[result.SellerGroupId] = result.Amount
+				}
+				if _, ok := sellerInvoiceMap[result.FinalSellerId]; ok {
+					sellerInvoiceMap[result.FinalSellerId] += result.Amount
+				} else {
+					sellerInvoiceMap[result.FinalSellerId] = result.Amount
+				}
+				if _, ok := sellerGroupMap[result.FinalSellerId]; !ok {
+					sellerGroupMap[result.FinalSellerId] = result.SellerGroupId
+				}
+			}
+			amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			accumulate += amountTotal
+		}
 	}
 
 	fmt.Println("totalMoneySlice:", len(totalMoneySlice))
@@ -925,8 +1007,8 @@ func (this *SellerController) GroupInvoiceListV2(c *gin.Context) {
 		startDate = fmt.Sprint(req.StartDate, " 00:00:00")
 		endDate = fmt.Sprint(req.EndDate, " 23:59:59")
 	}
-	startDateTime, _ := time.Parse(utils.FormatDate, startDate)
-	endDateTime, _ := time.Parse(utils.FormatDate, endDate)
+	startDateTime, _ := time.Parse(utils.FormatDate, req.StartDate)
+	endDateTime, _ := time.Parse(utils.FormatDate, req.EndDate)
 
 
 
@@ -1099,6 +1181,77 @@ func (this *SellerController) GroupInvoiceListV2(c *gin.Context) {
 		accumulate += amountTotal
 
 		//fmt.Println("partAccumulate:",partAccumulate)
+	} else {
+		// 有时间,分段查询
+		// 新查询
+		if st != "" && ed != "" {
+			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 {
+				resp.FailMsg("查询错误", fmt.Sprintf("获取汇总数据失败, Err: %s", e.Error()), c)
+				return
+			}
+			//dataList = append(dataList, results...)
+			var amountSum float64
+			for _, result := range results {
+				amountSum += result.Amount
+				fmt.Println("result.Amount:", result.Amount)
+				if _, ok := groupInvoiceMap[result.SellerGroupId]; ok {
+					groupInvoiceMap[result.SellerGroupId] += result.Amount
+				} else {
+					groupInvoiceMap[result.SellerGroupId] = result.Amount
+				}
+			}
+			amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			accumulate += amountTotal
+
+			//var amountTotal float64
+			// 旧查询
+			if st != "" && ed != "" {
+				histortyCond += ` AND (invoice_time BETWEEN ? AND ? )`
+				historyPars = append(historyPars, st, ed)
+			}
+			results, e = fms.GetIncomeHistory(histortyCond, historyPars)
+			if e != nil {
+				resp.FailMsg("查询错误", fmt.Sprintf("获取汇总数据失败, Err: %s", e.Error()), c)
+				return
+			}
+			//dataList = append(dataList, results...)
+			for _, result := range results {
+				amountSum += result.Amount
+				if _, ok := groupInvoiceMap[result.SellerGroupId]; ok {
+					groupInvoiceMap[result.SellerGroupId] += result.Amount
+				} else {
+					groupInvoiceMap[result.SellerGroupId] = result.Amount
+				}
+			}
+			amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
+			accumulate += amountTotal
+		}
 	}
 
 	fmt.Println("totalMoneySlice:", len(totalMoneySlice))