Browse Source

Merge branch 'pool_760' into debug

ziwen 1 year ago
parent
commit
d6db2b695e

+ 1 - 0
controller/census/invoice_payment.go

@@ -2022,6 +2022,7 @@ func (ct *InvoicePaymentController) NotInvoiceList(c *gin.Context) {
 
 			for _, v := range contractAmountCurrencyTotals {
 				v.Amount = contractSumMap[v.Code] - invoiceSumMap[v.Code]
+				v.Amount, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", v.Amount), 64)
 			}
 
 		}()

+ 92 - 1
controller/crm/company_seller.go

@@ -104,7 +104,8 @@ func (rg *CompanySellerController) TeamList(c *gin.Context) {
 	resp.OkData("获取成功", list, c)
 }
 
-func FIX() (err error) {
+// 修复历史数据表中导入的销售seller_id
+func FIXIncomeHistorySellerId() (err error) {
 	adminCond := ``
 	adminPars := make([]interface{}, 0)
 	adminOB := new(crm.Admin)
@@ -132,4 +133,94 @@ func FIX() (err error) {
 		}
 	}
 	return
+}
+
+// 修复
+func FixContractInvoiceSellerInfoV2() (err error) {
+	sellerList, e := crmService.GetSellerDepartmentListWithEnable()
+	if e != nil {
+		fmt.Println("获取销售列表失败, Err: " + e.Error())
+		return
+	}
+	sellerMap := make(map[int]*crm.SellerAdminWithGroupTeam)
+	for i := range sellerList {
+		sellerMap[sellerList[i].SellerId] = sellerList[i]
+	}
+
+	list,err := fms.GetInvoiceListByFix()
+	if err != nil {
+		return
+	}
+	queryRegisterIds := make([]int, 0)
+	for i := range list {
+		queryRegisterIds = append(queryRegisterIds, list[i].ContractRegisterId)
+	}
+
+	cond := `1 = 1`
+	pars := make([]interface{}, 0)
+
+	summaryCond := cond
+	summaryCond += ` AND a.register_id IN ?`
+	summaryPars := pars
+	summaryPars = append(summaryPars, queryRegisterIds)
+	summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
+	if e != nil {
+		fmt.Println("err1:",e)
+		return
+	}
+
+	contractRegisters, err := fms.GetContractInfoByRegisterIds(queryRegisterIds)
+	if err != nil {
+		fmt.Println("err3:",e)
+		return
+	}
+	registerMap := make(map[int]fms.ContractRegister, 0)
+	for _, v := range contractRegisters {
+		registerMap[v.ContractRegisterId] = v
+	}
+
+	summaryMap := make(map[int]*fms.InvoicePaymentSummaryItem, 0)
+	for _, v := range summaryData {
+		summaryMap[v.InvoiceId] = v
+		summaryMap[v.PaymentId] = v
+	}
+
+	for _, v := range list {
+		paymentItem := fms.ContractInvoice{}
+		paymentItem.ContractInvoiceId = v.ContractInvoiceId
+		fmt.Println("paymentItem.ContractInvoiceId:", paymentItem.ContractInvoiceId)
+		var seller  *crm.SellerAdminWithGroupTeam
+		//if v.InvoiceType == 2 || v.InvoiceType == 4 {
+		//	seller = sellerMap[v.SellerId]
+		//} else {
+		//	seller = sellerMap[v.ContractInvoiceId]
+		//}
+		if item, ok := summaryMap[v.ContractInvoiceId]; ok{
+			seller = sellerMap[item.SellerId]
+		}
+		if seller == nil {
+			register := registerMap[v.ContractRegisterId]
+			seller = sellerMap[register.SellerId]
+			if seller == nil {
+				seller = sellerMap[register.RaiSellerId]
+			}
+		}
+
+		if seller != nil {
+			fmt.Println("SellerName:", seller.SellerName)
+			paymentItem.SellerId = seller.SellerId
+			paymentItem.SellerName = seller.SellerName
+			paymentItem.SellerGroupId = seller.GroupId
+			paymentItem.SellerGroupName = seller.GroupName
+			paymentItem.SellerTeamId = seller.TeamId
+			paymentItem.SellerTeamName = seller.TeamName
+			e = paymentItem.Update([]string{"SellerId", "SellerName", "SellerGroupId", "SellerGroupName", "SellerTeamId", "SellerTeamName"})
+			if e != nil {
+				fmt.Println("err2:",e)
+				return
+			}
+		}
+	}
+	fmt.Println(len(summaryData))
+	return
 }

+ 1 - 0
init_serve/task.go

@@ -10,5 +10,6 @@ func InitTask() {
 	//fmsService.FixContractInvoiceSellerInfo()
 	//fmsService.FixContractInvoicePaymentType()
 	//fmsService.FixContractSummaryData()
+	//crm.FixContractInvoiceSellerInfoV2()
 	fmt.Println("task end")
 }

+ 7 - 0
models/fms/contract_invoice.go

@@ -783,4 +783,11 @@ func GetCensusSellerInvoicePageListV2(page base.IPage, adminStr, inCond, conditi
 	sql = fmt.Sprintf(sql, inCond, amountSum, condition, page.GetOrderItemsString(), page.Offset(), page.GetPageSize())
 	err = global.DEFAULT_MYSQL.Raw(sql, pars...).Scan(&results).Error
 	return
+}
+
+// GetInvoiceListByFix
+func GetInvoiceListByFix() (results []*ContractInvoice, err error) {
+	sql := `SELECT * FROM contract_invoice WHERE invoice_type = 2 AND seller_id = 0 `
+	err = global.DEFAULT_MYSQL.Raw(sql).Find(&results).Error
+	return
 }

+ 2 - 2
models/fms/invoice_payment_summary.go

@@ -351,14 +351,14 @@ func GetNoInvoicePaymentCensusData(condition string, pars []interface{}) (result
 // GetInvoiceCensusList 获取未开票统计列表
 func GetInvoiceCensusList(condition string, pars []interface{}) (results []*InvoiceSummary, err error) {
 	query := global.DEFAULT_MYSQL.Table("contract_register AS b").
-		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,a.service_product_id,c.origin_amount AS invoice_origin,d.origin_amount AS payment_origin ").
+		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.origin_amount ),0) AS invoiced_amount_count,COALESCE(SUM( d.origin_amount ),0) AS payment_amount_count,a.service_product_id,c.origin_amount AS invoice_origin,d.origin_amount AS payment_origin ").
 		Joins("left JOIN invoice_payment_summary AS a 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("contract_register_id")
 
 	nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
-		Select("*").Where(" e.invoiced_amount_count <>  e.contract_amount ")
+		Select("*").Where(" (e.invoiced_amount_count <> e.contract_amount AND e.contract_amount <> 0) OR (e.contract_amount = 0 AND e.invoiced_amount_count <> e.payment_amount_count) ")
 
 	err = nq.Find(&results).Error
 	if err != nil {