|
@@ -1084,7 +1084,7 @@ func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
|
|
|
var incomeList base.BaseData
|
|
|
ch := make(chan base.BaseData, 1)
|
|
|
if req.IncomeType == 0 {
|
|
|
- go getPaymentIncomeList(ch, req)
|
|
|
+ go getCensusIncomeList(ch, req)
|
|
|
} else {
|
|
|
go getPaymentIncomeList(ch, req)
|
|
|
}
|
|
@@ -1252,193 +1252,407 @@ func getPaymentIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseDat
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-//func getCensusIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData base.BaseData, err error) {
|
|
|
-// defer func() {
|
|
|
-// if err != nil {
|
|
|
-// global.LOG.Error(err)
|
|
|
-// if err != utils.ErrNoRow {
|
|
|
-// go alarm_msg.SendAlarmMsg("获取业务收入金额统计数据异常,Err:"+err.Error(), 3)
|
|
|
-// }
|
|
|
-// }
|
|
|
-// ch <- baseData
|
|
|
-// }()
|
|
|
-//
|
|
|
-// var reqStartDate, reqEndDate time.Time
|
|
|
-// historyTime, _ := time.Parse(utils.FormatDate, "2023-04-01")
|
|
|
-//
|
|
|
-// // 套餐筛选
|
|
|
-// if req.ServiceTypes != "" {
|
|
|
-// // 勾选套餐筛选时忽略导入的历史数据
|
|
|
-// if req.StartDate == "" {
|
|
|
-// req.StartDate = "2023-04"
|
|
|
-// req.EndDate = "3023-04"
|
|
|
-// } else {
|
|
|
-// startDateTime, _ := time.Parse(utils.FormatMonth, req.StartDate)
|
|
|
-// if startDateTime.Before(historyTime) {
|
|
|
-// req.StartDate = "2023-04"
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// if req.StartDate != "" && req.EndDate != "" {
|
|
|
-// st := fmt.Sprint(req.StartDate, "-01 00:00:00")
|
|
|
-// ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
|
|
|
-// reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
|
|
|
-// reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
|
|
|
-// }
|
|
|
-//
|
|
|
-// //timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
|
|
|
-//
|
|
|
-// var endDateTime time.Time
|
|
|
-// var startDate, endDate string
|
|
|
-// //开始日期
|
|
|
-// if req.StartDate != "" && req.EndDate != "" {
|
|
|
-// startDate = reqStartDate.Format("2006-01")
|
|
|
-// startDate = fmt.Sprint(startDate, "-01")
|
|
|
-// }
|
|
|
-//
|
|
|
-// startDateTime, _ := time.Parse(utils.FormatDate, startDate)
|
|
|
-//
|
|
|
-// //结束日期
|
|
|
-// if req.StartDate != "" && req.EndDate != "" {
|
|
|
-// endDate = reqEndDate.Format(utils.FormatDate)
|
|
|
-// }
|
|
|
-//
|
|
|
-// cond := `1 = 1`
|
|
|
-// histrtyCond := `1 = 1`
|
|
|
-// pars := make([]interface{}, 0)
|
|
|
-// historyPars := make([]interface{}, 0)
|
|
|
-//
|
|
|
-// if req.CompanyType == 1 {
|
|
|
-// cond += ` AND b.contract_type = 1 `
|
|
|
-// histrtyCond += ` AND new_company = 1 `
|
|
|
-// } else if req.CompanyType == 2 {
|
|
|
-// cond += ` AND b.contract_type IN (2,3,4) `
|
|
|
-// histrtyCond += ` AND new_company = 0 `
|
|
|
-// } else if req.CompanyType == 3 {
|
|
|
-// //未续约收入金额=去年同期总收入金额(新客户+老客户)-当期老客户收入金额
|
|
|
-// cond += ` AND b.contract_type IN (2,3,4) `
|
|
|
-// histrtyCond += ` AND new_company = 0 `
|
|
|
-// }
|
|
|
-//
|
|
|
-// if req.SellerIds != "" {
|
|
|
-// sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
-// cond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
|
|
|
-// pars = append(pars, sellerIds, sellerIds)
|
|
|
-//
|
|
|
-// histrtyCond += ` AND seller_id in ? `
|
|
|
-// historyPars = append(historyPars, sellerIds)
|
|
|
-// }
|
|
|
-//
|
|
|
-// // 套餐筛选
|
|
|
-// if req.ServiceTypes != "" {
|
|
|
-// serviceTypes := strings.Split(req.ServiceTypes, ",")
|
|
|
-// registerIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
|
|
|
-// if e != nil {
|
|
|
-// err = fmt.Errorf("获取合同登记IDs失败, Err: %s", e.Error())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// if len(registerIds) > 0 {
|
|
|
-// cond += ` AND a.register_id IN ?`
|
|
|
-// pars = append(pars, registerIds)
|
|
|
-// } else {
|
|
|
-// cond += ` AND 1 = 2`
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// {
|
|
|
-// st := fmt.Sprint(startDate, " 00:00:00")
|
|
|
-// ed := fmt.Sprint(endDate, " 23:59:59")
|
|
|
-// //校验日期,分段查询
|
|
|
-// if startDateTime.After(historyTime) || startDateTime.Equal(historyTime) {
|
|
|
-// //全部走新查询
|
|
|
-// 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 {
|
|
|
-// err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// //dataList = append(dataList, results...)
|
|
|
-// var amountSum float64
|
|
|
-// for _, result := range results {
|
|
|
-// incomeChart.DataList = append(incomeChart.DataList, result)
|
|
|
-// amountSum += result.Amount
|
|
|
-// fmt.Println("result.Amount:", result.Amount)
|
|
|
-// }
|
|
|
-// amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
|
|
|
-// accumulate += amountTotal
|
|
|
-// partAccumulate += amountTotal
|
|
|
-// }
|
|
|
-// } else if endDateTime.Before(historyTime) || endDateTime.Equal(historyTime) {
|
|
|
-// //全部走旧查询
|
|
|
-// //fmt.Println("旧查询")
|
|
|
-// //fmt.Println("st:",st)
|
|
|
-// //fmt.Println("ed:",ed)
|
|
|
-// histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
|
|
|
-// historyPars = append(historyPars, st, ed)
|
|
|
-// //fmt.Println("st:",st)
|
|
|
-// //fmt.Println("ed:",ed)
|
|
|
-// // 开票到款金额合计(换算后)
|
|
|
-// var amountTotal float64
|
|
|
-// results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
|
|
|
-// if e != nil {
|
|
|
-// err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// var amountSum float64
|
|
|
-// //dataList = append(dataList, results...)
|
|
|
-// for _, result := range results {
|
|
|
-// incomeChart.DataList = append(incomeChart.DataList, result)
|
|
|
-// amountSum += result.Amount
|
|
|
-// }
|
|
|
-// amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
|
|
|
-// accumulate += amountTotal
|
|
|
-// partAccumulate += amountTotal
|
|
|
-//
|
|
|
-// if i == j || i == numMonth {
|
|
|
-// if req.ListParam == "4" {
|
|
|
-// totalMoneySlice = append(totalMoneySlice, accumulate)
|
|
|
-// if startDateTime.Month() == 12 {
|
|
|
-// accumulate = 0
|
|
|
-// }
|
|
|
-// } else if req.ListParam == "0" {
|
|
|
-// totalMoneySlice = append(totalMoneySlice, amountTotal)
|
|
|
-// } else if i > 0 || i == numMonth {
|
|
|
-// totalMoneySlice = append(totalMoneySlice, partAccumulate)
|
|
|
-// partAccumulate = 0.0
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// //fmt.Println("partAccumulate:",partAccumulate)
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-//
|
|
|
-// return
|
|
|
-//}
|
|
|
+func getCensusIncomeList(ch chan base.BaseData, req fms.IncomeListReq) (baseData base.BaseData, err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Error(err)
|
|
|
+ if err != utils.ErrNoRow {
|
|
|
+ go alarm_msg.SendAlarmMsg("获取业务收入金额统计数据异常,Err:"+err.Error(), 3)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ch <- baseData
|
|
|
+ }()
|
|
|
+
|
|
|
+ var reqStartDate, reqEndDate time.Time
|
|
|
+ historyTime, _ := time.Parse(utils.FormatDate, "2023-04-01")
|
|
|
+
|
|
|
+ // 套餐筛选
|
|
|
+ if req.ServiceTypes != "" {
|
|
|
+ // 勾选套餐筛选时忽略导入的历史数据
|
|
|
+ if req.StartDate == "" {
|
|
|
+ req.StartDate = "2023-04"
|
|
|
+ req.EndDate = "3023-04"
|
|
|
+ } else {
|
|
|
+ startDateTime, _ := time.Parse(utils.FormatMonth, req.StartDate)
|
|
|
+ if startDateTime.Before(historyTime) {
|
|
|
+ req.StartDate = "2023-04"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ st := fmt.Sprint(req.StartDate, "-01 00:00:00")
|
|
|
+ ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
|
|
|
+ reqStartDate, _ = time.Parse(utils.FormatDateTime, st)
|
|
|
+ reqEndDate, _ = time.Parse(utils.FormatDateTime, ed)
|
|
|
+ }
|
|
|
+
|
|
|
+ //timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
|
|
|
+
|
|
|
+ var startDate, endDate string
|
|
|
+ //开始日期
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ startDate = reqStartDate.Format("2006-01")
|
|
|
+ startDate = fmt.Sprint(startDate, "-01")
|
|
|
+ }
|
|
|
+
|
|
|
+ startDateTime, _ := time.Parse(utils.FormatDate, startDate)
|
|
|
+
|
|
|
+ //结束日期
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ endDate = reqEndDate.Format(utils.FormatDate)
|
|
|
+ }
|
|
|
+
|
|
|
+ cond := `1 = 1`
|
|
|
+ histrtyCond := `1 = 1`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ historyPars := make([]interface{}, 0)
|
|
|
+
|
|
|
+ if req.CompanyType == 1 {
|
|
|
+ cond += ` AND b.contract_type = 1 `
|
|
|
+ histrtyCond += ` AND new_company = 1 `
|
|
|
+ } else if req.CompanyType == 2 {
|
|
|
+ cond += ` AND b.contract_type IN (2,3,4) `
|
|
|
+ histrtyCond += ` AND new_company = 0 `
|
|
|
+ } else if req.CompanyType == 3 {
|
|
|
+ //未续约收入金额=去年同期总收入金额(新客户+老客户)-当期老客户收入金额
|
|
|
+ cond += ` AND b.contract_type IN (2,3,4) `
|
|
|
+ histrtyCond += ` AND new_company = 0 `
|
|
|
+ }
|
|
|
+
|
|
|
+ if req.SellerIds != "" {
|
|
|
+ sellerIds := strings.Split(req.SellerIds, ",")
|
|
|
+ cond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
|
|
|
+ pars = append(pars, sellerIds, sellerIds)
|
|
|
+
|
|
|
+ histrtyCond += ` AND seller_id in ? `
|
|
|
+ historyPars = append(historyPars, sellerIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 套餐筛选
|
|
|
+ if req.ServiceTypes != "" {
|
|
|
+ serviceTypes := strings.Split(req.ServiceTypes, ",")
|
|
|
+ registerIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取合同登记IDs失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(registerIds) > 0 {
|
|
|
+ cond += ` AND a.register_id IN ?`
|
|
|
+ pars = append(pars, registerIds)
|
|
|
+ } else {
|
|
|
+ cond += ` AND 1 = 2`
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ page := new(base.Page)
|
|
|
+ page.SetPageSize(req.PageSize)
|
|
|
+ page.SetCurrent(req.Current)
|
|
|
+
|
|
|
+ if req.IsExport == 1 {
|
|
|
+ page.SetPageSize(10000)
|
|
|
+ page.SetCurrent(1)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //校验日期,分段查询
|
|
|
+ st := fmt.Sprint(startDate, " 00:00:00")
|
|
|
+ ed := fmt.Sprint(endDate, " 23:59:59")
|
|
|
+
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ if reqEndDate.Before(historyTime) || reqEndDate.Equal(historyTime) {
|
|
|
+ //旧查询
|
|
|
+ histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
|
|
|
+ historyPars = append(historyPars, st, ed)
|
|
|
+
|
|
|
+ if req.SortType == "asc" {
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "invoice_time", Asc: true})
|
|
|
+ } else {
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "invoice_time", Asc: false})
|
|
|
+ }
|
|
|
+
|
|
|
+ results, total, e := fms.GetIncomeHistoryPage(histrtyCond, historyPars, 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,
|
|
|
+ OriginAmount: v.OriginAmount,
|
|
|
+ UnitName: unitMap[v.CurrencyUnit],
|
|
|
+ ServicesName: v.ServicesName,
|
|
|
+ }
|
|
|
+ respItems = append(respItems, respItem)
|
|
|
+ }
|
|
|
+ page.SetTotal(total)
|
|
|
+ baseData.SetPage(page)
|
|
|
+ baseData.SetList(respItems)
|
|
|
+
|
|
|
+ return
|
|
|
+ } else if startDateTime.After(historyTime) || startDateTime.Equal(historyTime) {
|
|
|
+ //全部走新查询
|
|
|
+ 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
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+ 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,
|
|
|
+ OriginAmount: v.OriginAmount,
|
|
|
+ UnitName: unitMap[v.CurrencyUnit],
|
|
|
+ ServicesName: v.ServicesName,
|
|
|
+ }
|
|
|
+ respItems = append(respItems, respItem)
|
|
|
+ }
|
|
|
+ page.SetTotal(total)
|
|
|
+ baseData.SetPage(page)
|
|
|
+ baseData.SetList(respItems[:])
|
|
|
+
|
|
|
+ return
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resultList := make([]*fms.IncomeSummaryItem, 0)
|
|
|
+ //旧查询
|
|
|
+ histrtyCond += ` AND (invoice_time BETWEEN ? AND ? )`
|
|
|
+ historyPars = append(historyPars, st, ed)
|
|
|
+
|
|
|
+ results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultList = append(resultList, results...)
|
|
|
+
|
|
|
+ //新查询
|
|
|
+ cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
+ pars = append(pars, "2023-04-01 00:00:00", ed, "2023-04-01 00:00:00", ed)
|
|
|
+ summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 {
|
|
|
+ err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultList = append(resultList, results...)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 货币列表
|
|
|
+ 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 resultList {
|
|
|
+ respItem := &fms.IncomeSummaryRespItem{
|
|
|
+ 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,
|
|
|
+ }
|
|
|
+ respItems = append(respItems, respItem)
|
|
|
+ }
|
|
|
+ page.SetTotal(int64(len(respItems)))
|
|
|
+ baseData.SetPage(page)
|
|
|
+
|
|
|
+
|
|
|
+ start := (page.GetCurrent() - 1) * page.PageSize
|
|
|
+ end := start + page.PageSize
|
|
|
+ if end > int64(len(respItems)) {
|
|
|
+ end = int64(len(respItems))
|
|
|
+ }
|
|
|
+ baseData.SetList(respItems[start:end])
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ resultList := make([]*fms.IncomeSummaryItem, 0)
|
|
|
+ //旧查询
|
|
|
+
|
|
|
+ results, e := fms.GetIncomeHistory(histrtyCond, historyPars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultList = append(resultList, results...)
|
|
|
+
|
|
|
+ //新查询
|
|
|
+ st = "2023-04-01 00:00:00"
|
|
|
+ cond += ` AND ((c.invoice_time > ?) or (d.invoice_time > ?))`
|
|
|
+ pars = append(pars, st, st)
|
|
|
+ summaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ 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 > ?)`
|
|
|
+ amountCond += `OR ( d.seller_id IN ? AND a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time > ? )) `
|
|
|
+ amountPars = append(amountPars, sellerIds, st, sellerIds, st)
|
|
|
+ } else {
|
|
|
+ amountCond += ` AND ((a.invoice_id <> 0 AND b.invoice_time > ?)`
|
|
|
+ amountCond += `OR (a.payment_id <> 0 AND a.invoice_id = 0 AND d.invoice_time > ?))`
|
|
|
+ amountPars = append(amountPars, st, st)
|
|
|
+ }
|
|
|
+ results, e := fms.GetContractSummaryIncomeAmount(amountCond, amountPars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取汇总数据失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resultList = append(resultList, results...)
|
|
|
+ }
|
|
|
+
|
|
|
+ // 货币列表
|
|
|
+ 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 resultList {
|
|
|
+ respItem := &fms.IncomeSummaryRespItem{
|
|
|
+ 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,
|
|
|
+ }
|
|
|
+ respItems = append(respItems, respItem)
|
|
|
+ }
|
|
|
+ page.SetTotal(int64(len(respItems)))
|
|
|
+ baseData.SetPage(page)
|
|
|
+
|
|
|
+
|
|
|
+ start := (page.GetCurrent() - 1) * page.PageSize
|
|
|
+ end := start + page.PageSize
|
|
|
+ if end > int64(len(respItems)) {
|
|
|
+ end = int64(len(respItems))
|
|
|
+ }
|
|
|
+ baseData.SetList(respItems[start:end])
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return
|
|
|
+}
|
|
|
|
|
|
// ExportIncomeList 导出业务收入统计列表
|
|
|
func ExportIncomeList(c *gin.Context, results interface{}, incomeType int) {
|