Browse Source

Merge branch 'fms_3.1' into debug

xiziwen 4 tháng trước cách đây
mục cha
commit
e4491b8079

+ 51 - 16
controller/census/income_list.go

@@ -9,6 +9,7 @@ import (
 	"hongze/fms_api/controller/resp"
 	"hongze/fms_api/global"
 	"hongze/fms_api/models"
+	"hongze/fms_api/models/base"
 	"hongze/fms_api/models/fms"
 	"hongze/fms_api/services/alarm_msg"
 	"hongze/fms_api/utils"
@@ -1142,8 +1143,8 @@ func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
 		return
 	}
 	//收入统计
-	incomeList := make([]*fms.IncomeSummaryRespItem, 0)
-	ch := make(chan []*fms.IncomeSummaryRespItem, 1)
+	var incomeList base.BaseData
+	ch := make(chan base.BaseData, 1)
 	if req.IncomeType == 0 {
 		go getPaymentIncomeList(ch, req)
 	} else {
@@ -1151,7 +1152,7 @@ func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
 	}
 
 	for v := range ch {
-		incomeList = append(incomeList, v...)
+		incomeList = v
 		close(ch)
 	}
 	// 是否导出
@@ -1475,7 +1476,7 @@ func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
 //	return
 //}
 
-func getPaymentIncomeList(ch chan []*fms.IncomeSummaryRespItem, req fms.IncomeListReq) (resp []*fms.IncomeSummaryRespItem, err error) {
+func getPaymentIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData base.BaseData, err error) {
 	defer func() {
 		if err != nil {
 			global.LOG.Error(err)
@@ -1483,10 +1484,9 @@ func getPaymentIncomeList(ch chan []*fms.IncomeSummaryRespItem, req fms.IncomeLi
 				go alarm_msg.SendAlarmMsg("获取业务收入金额统计数据异常,Err:"+err.Error(), 3)
 			}
 		}
-		ch <- resp
+		ch <- baseData
 	}()
 
-
 	var reqStartDate, reqEndDate time.Time
 
 	st := fmt.Sprint(req.StartDate, "-01 00:00:00")
@@ -1500,13 +1500,11 @@ func getPaymentIncomeList(ch chan []*fms.IncomeSummaryRespItem, req fms.IncomeLi
 		startDate = reqStartDate.Format(utils.FormatDate)
 	}
 
-
 	//结束日期
 	if req.StartDate != "" && req.EndDate != "" {
 		endDate = reqEndDate.Format(utils.FormatDate)
 	}
 
-
 	cond := `1 = 1`
 	pars := make([]interface{}, 0)
 
@@ -1549,6 +1547,11 @@ func getPaymentIncomeList(ch chan []*fms.IncomeSummaryRespItem, req fms.IncomeLi
 			pars = append(pars, st, ed, st, ed)
 		}
 
+		if req.Keyword != "" {
+			cond += ` AND b.company_name LIKE ?`
+			pars = append(pars, "%"+req.Keyword+"%")
+		}
+
 		summaryIds, e := fms.GetPaymentCensusSummaryDataIds(cond, pars)
 		if e != nil {
 			return
@@ -1565,22 +1568,54 @@ func getPaymentIncomeList(ch chan []*fms.IncomeSummaryRespItem, req fms.IncomeLi
 			} else {
 				amountCond += `AND (a.payment_id <> 0)`
 			}
-			results, e := fms.GetContractSummaryPaymentIncomeAmountPage(amountCond, amountPars)
+			page := new(base.Page)
+			page.SetPageSize(req.PageSize)
+			page.SetCurrent(req.Current)
+
+			if req.SortType == "asc" {
+				page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: true})
+			} else {
+				page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: false})
+			}
+
+			results, total, e := fms.GetContractSummaryPaymentIncomeAmountPage(amountCond, amountPars, page)
 			if e != nil {
 				err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
 				return
 			}
+
+			// 货币列表
+			currencyOB := new(fms.CurrencyUnit)
+			currencyCond := `enable = 1`
+			currencyPars := make([]interface{}, 0)
+			currencyList, e := currencyOB.List(currencyCond, currencyPars)
+			if e != nil {
+				err = fmt.Errorf("获取货币列表失败, Err: %s", e.Error())
+				return
+			}
+			unitMap := make(map[string]string)
+			for i := range currencyList {
+				unitMap[currencyList[i].Code] = currencyList[i].UnitName
+			}
+
+			respItems := make([]*fms.IncomeSummaryRespItem, 0)
 			for _, v := range results {
 				respItem := &fms.IncomeSummaryRespItem{
-					CompanyName:     v.CompanyName,
-					ContractType:    v.ContractType,
-					InvoiceDate:     v.InvoiceDate.Format(utils.FormatDate),
-					Amount:          v.Amount,
-					SellerName:      v.SellerName,
-					FinalSellerId:   v.FinalSellerId,
+					CompanyName:   v.CompanyName,
+					ContractType:  v.ContractType,
+					InvoiceDate:   v.InvoiceDate.Format(utils.FormatDate),
+					Amount:        v.Amount,
+					SellerName:    v.SellerName,
+					FinalSellerId: v.FinalSellerId,
+					OriginAmount:  v.OriginAmount,
+					UnitName:      unitMap[v.CurrencyUnit],
+					ServicesName: v.ServicesName,
 				}
-				resp = append(resp, respItem)
+				respItems = append(respItems, respItem)
 			}
+			page.SetTotal(total)
+			baseData.SetPage(page)
+			baseData.SetList(respItems)
 		}
 	}
 

+ 4 - 1
models/fms/contract_invoice.go

@@ -838,4 +838,7 @@ type IncomeListReq struct {
 	CompanyType  int    `json:"company_type" form:"company_type" description:"客户类型 0全部 1新客户 2老客户 3未续约"`
 	ServiceTypes string `json:"service_types" form:"service_types" description:"套餐类型"`
 	IncomeType   int    `json:"income_type" form:"income_type" description:"收入类型 0开票收入 1到款收入"`
-}
+	SortType     string `json:"sort_type" form:"sort_type" description:"如何排序,是正序还是倒序,枚举值:asc 正序,desc 倒叙"`
+	Keyword      string `json:"keyword" form:"keyword" description:"搜索关键字"`
+	base.PageReq
+}

+ 25 - 16
models/fms/invoice_payment_summary.go

@@ -197,11 +197,14 @@ type IncomeSummaryItem struct {
 	CompanyName     string    `json:"company_name" description:"客户名称"`
 	ContractType    int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
 	InvoiceDate     time.Time `json:"invoice_time" description:"开票日期"`
+	OriginAmount    float64   `json:"origin_amount" description:"原始金额"`
 	Amount          float64   `json:"amount" description:"金额"`
 	SellerName      string    `json:"seller_name" description:"销售名称"`
 	FinalSellerId   int       `json:"final_seller_id" description:"最终销售ID"`
 	SellerGroupId   int       `json:"seller_group_id" description:"销售分组ID"`
 	SellerGroupName int       `json:"seller_group_name" description:"销售分组名称"`
+	CurrencyUnit    string    `json:"currency_unit" description:"货币单位"`
+	ServicesName       string `json:"services" description:"套餐名称"`
 }
 
 // GetContractSummaryIncomeAmount 获取汇总金额合计信息
@@ -386,12 +389,11 @@ func UpdateInvoicePaymentSummaryByRegisterId(newId int, registerIds []int) (err
 	return
 }
 
-
 // GetContractSummaryPaymentIncomeAmount 获取汇总金额合计信息-到款收入统计
 func GetContractSummaryPaymentIncomeAmount(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
 		Select("d.amount AS amount,d.invoice_time AS invoice_date,"+
-			" c.contract_type,c.company_name,d.seller_name," +
+			" c.contract_type,c.company_name,d.seller_name,"+
 			" d.seller_id AS final_seller_id, d.seller_group_id AS seller_group_id").
 		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").
@@ -404,27 +406,34 @@ func GetContractSummaryPaymentIncomeAmount(condition string, pars []interface{})
 }
 
 type IncomeSummaryRespItem struct {
-	CompanyName     string    `json:"company_name" description:"客户名称"`
-	ContractType    int       `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
-	InvoiceDate     string `json:"invoice_time" description:"开票日期"`
-	Amount          float64   `json:"amount" description:"金额"`
-	SellerName      string    `json:"seller_name" description:"销售名称"`
-	FinalSellerId   int       `json:"final_seller_id" description:"最终销售ID"`
+	CompanyName   string  `json:"company_name" description:"客户名称"`
+	ContractType  int     `json:"contract_type" description:"是否为新客户: 2-否; 1-是"`
+	InvoiceDate   string  `json:"invoice_time" description:"开票日期"`
+	OriginAmount  float64 `json:"origin_amount" description:"原始金额"`
+	Amount        float64 `json:"amount" description:"金额"`
+	SellerName    string  `json:"seller_name" description:"销售名称"`
+	FinalSellerId int     `json:"final_seller_id" description:"最终销售ID"`
+	UnitName      string  `json:"unit_name" description:"货币单位名称"`
+	ServicesName       string `json:"services_name" description:"套餐名称"`
 }
 
 // GetContractSummaryPaymentIncomeAmountPage 获取汇总金额合计信息-到款收入统计
-func GetContractSummaryPaymentIncomeAmountPage(condition string, pars []interface{}) (results []*IncomeSummaryItem, err error) {
+func GetContractSummaryPaymentIncomeAmountPage(condition string, pars []interface{}, page *base.Page) (results []*IncomeSummaryItem, count int64, err error) {
 	query := global.DEFAULT_MYSQL.Table("invoice_payment_summary AS a").
-		Select("d.amount AS amount,d.invoice_time AS invoice_date,"+
-			" c.contract_type,c.company_name,d.seller_name," +
-			" d.seller_id AS final_seller_id").
+		Select("d.origin_amount, d.amount AS amount,d.currency_unit, d.invoice_time AS invoice_date,"+
+			" c.contract_type,c.company_name,d.seller_name,"+
+			" d.seller_id AS final_seller_id, GROUP_CONCAT(s.title) AS services_name ").
 		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 ")
+		Joins("LEFT JOIN contract_service AS s ON s.contract_register_id = c.contract_register_id").
+		Where(condition, pars...).Group("id")
 	//nq := global.DEFAULT_MYSQL.Table("(?) AS e", query).
 	//	Select(" IFNULL( SUM( e.amount ), 0 ) ")
-
-	err = query.Find(&results).Error
+	query.Count(&count)
+	if len(page.GetOrderItemsString()) > 0 {
+		query = query.Order(page.GetOrderItemsString())
+	}
+	err = query.Limit(int(page.GetPageSize())).Offset(int(page.Offset())).Find(&results).Error
 	return
 }
 
@@ -437,4 +446,4 @@ func GetPaymentCensusSummaryDataIds(condition string, pars []interface{}) (summa
 		Where(condition, pars...)
 	query.Find(&summaryIds)
 	return
-}
+}