Bläddra i källkod

Merge branch 'new_2.6' into debug

ziwen 1 år sedan
förälder
incheckning
6f0f92d39b
1 ändrade filer med 91 tillägg och 140 borttagningar
  1. 91 140
      controller/census/invoice_payment.go

+ 91 - 140
controller/census/invoice_payment.go

@@ -781,7 +781,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
 				v.SellerName = summaryList[i].SellerName
 				v.SellerGroupId = summaryList[i].SellerGroupId
 				v.SellerGroupName = summaryList[i].SellerGroupName
-				if seller, ok := sellerMap[summaryList[i].SellerId]; ok{
+				if seller, ok := sellerMap[summaryList[i].SellerId]; ok {
 					v.SellerType = sellerTypeMap[seller.DepartmentId]
 				}
 				v.PaymentId = summaryList[i].PaymentId
@@ -1637,7 +1637,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 		page.SetCurrent(1)
 	}
 
-	cond += `  AND b.contract_amount <> b.invoiced_amount AND b.is_deleted = 0 AND b.contract_amount <> b.payment_amount `
+	cond += `  AND b.contract_amount <> b.invoiced_amount AND b.is_deleted = 0 AND b.contract_amount <> b.payment_amount AND b.contract_status <> 4 `
 	registerList, total, e := fms.GetInvoiceCensusPageList(page, cond, pars)
 	if e != nil {
 		resp.FailMsg("获取失败", "获取商品到款统计列表总数失败, Err: "+e.Error(), c)
@@ -1662,27 +1662,8 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				serviceAmountMap[v.ContractRegisterId] = make(map[int]*fms.ContractServiceAmount)
 			}
 			serviceAmountMap[v.ContractRegisterId][v.ProductId] = v
-			fmt.Println("ServiceAmount,ProductId", v.ServiceAmount, v.ProductId, v.ContractRegisterId)
 		}
 
-		// 获取汇总数据IDs, 用于查询合计数据
-		//summaryIdsCond := cond
-		//summaryIdsPars := pars
-		//if req.SellerIds != "" {
-		//	sellerIds := strings.Split(req.SellerIds, ",")
-		//	summaryIdsCond += ` AND c.seller_id in ?  AND (d.origin_amount > c.origin_amount OR c.origin_amount IS NULL) `
-		//	summaryIdsPars = append(summaryIdsPars, sellerIds)
-		//} else {
-		//	summaryIdsCond += `  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{}
 
@@ -1698,14 +1679,6 @@ 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 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 {
@@ -1717,7 +1690,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				notQueryRegisterIds = append(notQueryRegisterIds, v.ContractRegisterId)
 			}
 
-			noSummaryCond += ` AND b.is_deleted = 0`
+			noSummaryCond += ` AND b.is_deleted = 0 AND b.contract_status <> 4 `
 			noSummaryCond += ` AND b.contract_register_id IN ? AND b.contract_register_id NOT IN ?`
 			noSummaryPars = append(noSummaryPars, queryRegisterIds, notQueryRegisterIds)
 			noSummaryData, e := fms.GetNoInvoicePaymentCensusData(noSummaryCond, noSummaryPars)
@@ -1736,12 +1709,6 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 
 			summaryList = append(summaryList, noSummaryData...)
 
-			//summaryIds := make([]int, 0)
-			//paymentIds := make([]int, 0)
-			//for i := range summaryList {
-			//	//summaryIds = append(summaryIds, summaryList[i].SummaryId)
-			//}
-
 			//fmt.Println("len(NotInvoiceSummaryMap):", len(NotInvoiceSummaryMap))
 
 			for _, v := range summaryList {
@@ -1752,73 +1719,84 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				//fmt.Println("len(NotInvoiceSummaryMap[v.RegisterId]):", len(NotInvoiceSummaryMap[v.ContractRegisterId]))
 				if (v.ProductIds == "1,2" || v.ProductIds == "2,1") && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 1 {
 					if v.ServiceProductId == 1 {
-						item := fms.NotInvoicePaymentSummaryItem{
-							NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][2].ServiceAmount,
-							ServiceProductId:       2,
+						if serviceAmount, ok := serviceAmountMap[v.ContractRegisterId]; ok {
+							item := fms.NotInvoicePaymentSummaryItem{
+								NotInvoicedAmountTotal: serviceAmount[2].ServiceAmount,
+								ServiceProductId:       2,
+							}
+							item.SellerId = v.SellerId
+							item.SellerName = v.SellerName
+							item.RaiSellerId = v.RaiSellerId
+							item.RaiSellerName = v.RaiSellerName
+
+							NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item)
 						}
-						item.SellerId = v.SellerId
-						item.SellerName = v.SellerName
-						item.RaiSellerId = v.RaiSellerId
-						item.RaiSellerName = v.RaiSellerName
 
-						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item)
 					} else {
+						if serviceAmount, ok := serviceAmountMap[v.ContractRegisterId]; ok {
+							item := fms.NotInvoicePaymentSummaryItem{
+								NotInvoicedAmountTotal: serviceAmount[1].ServiceAmount,
+								ServiceProductId:       1,
+							}
+							item.SellerId = v.SellerId
+							item.SellerName = v.SellerName
+							item.RaiSellerId = v.RaiSellerId
+							item.RaiSellerName = v.RaiSellerName
 
-						item := fms.NotInvoicePaymentSummaryItem{
-							NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][1].ServiceAmount,
-							ServiceProductId:       1,
+							NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item)
 						}
-						item.SellerId = v.SellerId
-						item.SellerName = v.SellerName
-						item.RaiSellerId = v.RaiSellerId
-						item.RaiSellerName = v.RaiSellerName
 
-						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item)
 					}
 				} else if (v.ProductIds == "1,2" || v.ProductIds == "2,1") && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
-					item1 := fms.NotInvoicePaymentSummaryItem{
-						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][2].ServiceAmount,
-						ServiceProductId:       2,
-					}
-					item1.SellerId = v.SellerId
-					item1.SellerName = v.SellerName
-					item1.RaiSellerId = v.RaiSellerId
-					item1.RaiSellerName = v.RaiSellerName
-					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item1)
-
-					item2 := fms.NotInvoicePaymentSummaryItem{
-						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][1].ServiceAmount,
-						ServiceProductId:       1,
-					}
-					item2.SellerId = v.SellerId
-					item2.SellerName = v.SellerName
-					item2.RaiSellerId = v.RaiSellerId
-					item2.RaiSellerName = v.RaiSellerName
+					if serviceAmount, ok := serviceAmountMap[v.ContractRegisterId]; ok {
+						item1 := fms.NotInvoicePaymentSummaryItem{
+							NotInvoicedAmountTotal: serviceAmount[2].ServiceAmount,
+							ServiceProductId:       2,
+						}
+						item1.SellerId = v.SellerId
+						item1.SellerName = v.SellerName
+						item1.RaiSellerId = v.RaiSellerId
+						item1.RaiSellerName = v.RaiSellerName
+						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item1)
+
+						item2 := fms.NotInvoicePaymentSummaryItem{
+							NotInvoicedAmountTotal: serviceAmount[1].ServiceAmount,
+							ServiceProductId:       1,
+						}
+						item2.SellerId = v.SellerId
+						item2.SellerName = v.SellerName
+						item2.RaiSellerId = v.RaiSellerId
+						item2.RaiSellerName = v.RaiSellerName
 
-					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item2)
-				} else if v.ProductIds == "1" && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
-					item1 := fms.NotInvoicePaymentSummaryItem{
-						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][1].ServiceAmount,
-						ServiceProductId:       1,
+						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item2)
 					}
-					item1.SellerId = v.SellerId
-					item1.SellerName = v.SellerName
-					item1.RaiSellerId = v.RaiSellerId
-					item1.RaiSellerName = v.RaiSellerName
 
-					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item1)
+				} else if v.ProductIds == "1" && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
+					if serviceAmount, ok := serviceAmountMap[v.ContractRegisterId]; ok {
+						item1 := fms.NotInvoicePaymentSummaryItem{
+							NotInvoicedAmountTotal: serviceAmount[1].ServiceAmount,
+							ServiceProductId:       1,
+						}
+						item1.SellerId = v.SellerId
+						item1.SellerName = v.SellerName
+						item1.RaiSellerId = v.RaiSellerId
+						item1.RaiSellerName = v.RaiSellerName
 
-				} else if v.ProductIds == "2" && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
-					item2 := fms.NotInvoicePaymentSummaryItem{
-						NotInvoicedAmountTotal: serviceAmountMap[v.ContractRegisterId][2].ServiceAmount,
-						ServiceProductId:       2,
+						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item1)
 					}
-					item2.SellerId = v.SellerId
-					item2.SellerName = v.SellerName
-					item2.RaiSellerId = v.RaiSellerId
-					item2.RaiSellerName = v.RaiSellerName
+				} else if v.ProductIds == "2" && len(NotInvoiceSummaryMap[v.ContractRegisterId]) == 0 {
+					if serviceAmount, ok := serviceAmountMap[v.ContractRegisterId]; ok {
+						item2 := fms.NotInvoicePaymentSummaryItem{
+							NotInvoicedAmountTotal: serviceAmount[2].ServiceAmount,
+							ServiceProductId:       2,
+						}
+						item2.SellerId = v.SellerId
+						item2.SellerName = v.SellerName
+						item2.RaiSellerId = v.RaiSellerId
+						item2.RaiSellerName = v.RaiSellerName
 
-					NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item2)
+						NotInvoiceSummaryMap[v.ContractRegisterId] = append(NotInvoiceSummaryMap[v.ContractRegisterId], &item2)
+					}
 				}
 			}
 
@@ -1861,29 +1839,29 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 					}
 					if v.SellerId > 0 && v.RaiSellerId > 0 {
 						if v.ServiceProductId == 1 {
-							v.SellerGroupId = sellerMap[v.SellerId].GroupId
-							v.SellerGroupName = sellerMap[v.SellerId].GroupName
-							if seller, ok := sellerMap[v.SellerId]; ok{
+							if seller, ok := sellerMap[v.SellerId]; ok {
 								v.SellerType = sellerTypeMap[seller.DepartmentId]
+								v.SellerGroupId = seller.GroupId
+								v.SellerGroupName = seller.GroupName
 							}
 						} else {
-							v.RaiSellerGroupId = sellerMap[v.RaiSellerId].GroupId
-							v.RaiSellerGroupName = sellerMap[v.RaiSellerId].GroupName
-							if seller, ok := sellerMap[v.RaiSellerId]; ok{
+							if seller, ok := sellerMap[v.RaiSellerId]; ok {
 								v.SellerType = sellerTypeMap[seller.DepartmentId]
+								v.RaiSellerGroupId = seller.GroupId
+								v.RaiSellerGroupName = seller.GroupName
 							}
 						}
 					} else if v.SellerId > 0 && v.RaiSellerId == 0 {
-						v.SellerGroupId = sellerMap[v.SellerId].GroupId
-						v.SellerGroupName = sellerMap[v.SellerId].GroupName
-						if seller, ok := sellerMap[v.SellerId]; ok{
+						if seller, ok := sellerMap[v.SellerId]; ok {
 							v.SellerType = sellerTypeMap[seller.DepartmentId]
+							v.SellerGroupId = seller.GroupId
+							v.SellerGroupName = seller.GroupName
 						}
 					} else if v.SellerId == 0 && v.RaiSellerId > 0 {
-						v.RaiSellerGroupId = sellerMap[v.RaiSellerId].GroupId
-						v.RaiSellerGroupName = sellerMap[v.RaiSellerId].GroupName
-						if seller, ok := sellerMap[v.RaiSellerId]; ok{
+						if seller, ok := sellerMap[v.RaiSellerId]; ok {
 							v.SellerType = sellerTypeMap[seller.DepartmentId]
+							v.RaiSellerGroupId = seller.GroupId
+							v.RaiSellerGroupName = seller.GroupName
 						}
 					}
 				}
@@ -1914,32 +1892,6 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 			}
 		}()
 
-		// 开票到款金额合计(换算后)
-		//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)
-		//}()
-
 		// 开票到款金额合计(换算后)V2
 		var invoiceTotal, contractAmount float64
 		wg.Add(1)
@@ -1963,7 +1915,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				if rate == 0.0 {
 					rate = 1.0
 				}
-				if _,ok := contractIdSumMap[v.ContractRegisterId]; !ok{
+				if _, ok := contractIdSumMap[v.ContractRegisterId]; !ok {
 					contractIdSumMap[v.ContractRegisterId] = 1
 					contractAmount += v.ContractAmount / v.RMBRate
 				}
@@ -2026,7 +1978,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 				} else {
 					invoiceSumMap[v.CurrencyUnit] += v.PaymentAmount
 				}
-				if _,ok := contractIdSumMap[v.ContractRegisterId]; !ok{
+				if _, ok := contractIdSumMap[v.ContractRegisterId]; !ok {
 					contractIdSumMap[v.ContractRegisterId] = 1
 					contractSumMap[v.CurrencyUnit] += v.ContractAmount
 				}
@@ -2273,7 +2225,7 @@ func (ct *InvoicePaymentController) NotPaymentList(c *gin.Context) {
 				v.SellerName = summaryList[i].SellerName
 				v.SellerGroupId = summaryList[i].SellerGroupId
 				v.SellerGroupName = summaryList[i].SellerGroupName
-				if seller, ok := sellerMap[summaryList[i].SellerId]; ok{
+				if seller, ok := sellerMap[summaryList[i].SellerId]; ok {
 					v.SellerType = sellerTypeMap[seller.DepartmentId]
 				}
 
@@ -2568,7 +2520,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 				if item.SellerId > 0 && item.RaiSellerId > 0 {
 					if item.ServiceProductId == 1 {
 						item.SellerGroupName = sellerMap[item.SellerId].GroupName
-						if seller, ok := sellerMap[item.SellerId]; ok{
+						if seller, ok := sellerMap[item.SellerId]; ok {
 							item.SellerType = sellerTypeMap[seller.DepartmentId]
 						}
 						dataRow2.AddCell().SetString(item.SellerName)      // 销售
@@ -2576,7 +2528,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 						dataRow2.AddCell().SetString(item.SellerType)      // 销售类型
 					} else {
 						item.RaiSellerGroupName = sellerMap[item.RaiSellerId].GroupName
-						if seller, ok := sellerMap[item.RaiSellerId]; ok{
+						if seller, ok := sellerMap[item.RaiSellerId]; ok {
 							item.SellerType = sellerTypeMap[seller.DepartmentId]
 						}
 						dataRow2.AddCell().SetString(item.RaiSellerName)      // 销售
@@ -2585,7 +2537,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 					}
 				} else if item.SellerId > 0 && item.RaiSellerId == 0 {
 					item.SellerGroupName = sellerMap[item.SellerId].GroupName
-					if seller, ok := sellerMap[item.SellerId]; ok{
+					if seller, ok := sellerMap[item.SellerId]; ok {
 						item.SellerType = sellerTypeMap[seller.DepartmentId]
 					}
 					dataRow2.AddCell().SetString(item.SellerName)      // 销售
@@ -2593,7 +2545,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 					dataRow2.AddCell().SetString(item.SellerType)      // 销售类型
 				} else if item.SellerId == 0 && item.RaiSellerId > 0 {
 					item.RaiSellerGroupName = sellerMap[item.RaiSellerId].GroupName
-					if seller, ok := sellerMap[item.RaiSellerId]; ok{
+					if seller, ok := sellerMap[item.RaiSellerId]; ok {
 						item.SellerType = sellerTypeMap[seller.DepartmentId]
 					}
 					dataRow2.AddCell().SetString(item.RaiSellerName)      // 销售
@@ -2605,13 +2557,12 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 
 				dataRow.AddCell().SetString(fmt.Sprintf("%.2f", item.NotInvoicedAmountTotal)) // 未开票金额
 
-				dataRow.AddCell().SetString(serviceProductIdMap[item.ServiceProductId])       // 套餐类型
-
+				dataRow.AddCell().SetString(serviceProductIdMap[item.ServiceProductId]) // 套餐类型
 
 				if item.SellerId > 0 && item.RaiSellerId > 0 {
 					if item.ServiceProductId == 1 {
 						item.SellerGroupName = sellerMap[item.SellerId].GroupName
-						if seller, ok := sellerMap[item.SellerId]; ok{
+						if seller, ok := sellerMap[item.SellerId]; ok {
 							item.SellerType = sellerTypeMap[seller.DepartmentId]
 						}
 						dataRow.AddCell().SetString(item.SellerName)      // 销售
@@ -2619,7 +2570,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 						dataRow.AddCell().SetString(item.SellerType)      // 销售类型
 					} else {
 						item.RaiSellerGroupName = sellerMap[item.RaiSellerId].GroupName
-						if seller, ok := sellerMap[item.RaiSellerId]; ok{
+						if seller, ok := sellerMap[item.RaiSellerId]; ok {
 							item.SellerType = sellerTypeMap[seller.DepartmentId]
 						}
 						dataRow.AddCell().SetString(item.RaiSellerName)      // 销售
@@ -2628,7 +2579,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 					}
 				} else if item.SellerId > 0 && item.RaiSellerId == 0 {
 					item.SellerGroupName = sellerMap[item.SellerId].GroupName
-					if seller, ok := sellerMap[item.SellerId]; ok{
+					if seller, ok := sellerMap[item.SellerId]; ok {
 						item.SellerType = sellerTypeMap[seller.DepartmentId]
 					}
 					dataRow.AddCell().SetString(item.SellerName)      // 销售
@@ -2636,7 +2587,7 @@ func ExportNotInvoiceCensusList(c *gin.Context, results *fms.NotInvoicePaymentCe
 					dataRow.AddCell().SetString(item.SellerType)      // 销售类型
 				} else if item.SellerId == 0 && item.RaiSellerId > 0 {
 					item.RaiSellerGroupName = sellerMap[item.RaiSellerId].GroupName
-					if seller, ok := sellerMap[item.RaiSellerId]; ok{
+					if seller, ok := sellerMap[item.RaiSellerId]; ok {
 						item.SellerType = sellerTypeMap[seller.DepartmentId]
 					}
 					dataRow.AddCell().SetString(item.RaiSellerName)      // 销售