|
@@ -8,8 +8,10 @@ import (
|
|
|
"github.com/tealeg/xlsx"
|
|
|
"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"
|
|
|
fmsService "hongze/fms_api/services/fms"
|
|
|
"hongze/fms_api/utils"
|
|
|
"net/http"
|
|
@@ -337,7 +339,7 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
|
|
|
return
|
|
|
}
|
|
|
serviceTempListMap := make(map[int]*fms.ContractServiceTemplate)
|
|
|
- var serviceTempShow [] *fms.ContractServiceTemplate
|
|
|
+ var serviceTempShow []*fms.ContractServiceTemplate
|
|
|
for i := range serviceTempList {
|
|
|
serviceTempListMap[serviceTempList[i].ServiceTemplateId] = serviceTempList[i]
|
|
|
}
|
|
@@ -345,17 +347,17 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
|
|
|
if serviceTempList[i].ProductId == 1 {
|
|
|
rowTitle = append(rowTitle, serviceTempList[i].Title)
|
|
|
serviceTempShow = append(serviceTempShow, serviceTempList[i])
|
|
|
- }else if serviceTempList[i].ProductId == 2{
|
|
|
- if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "权益大套餐" || (serviceTempList[i].Title == "策略" && serviceTempListMap[serviceTempList[i].Pid].Pid==0){
|
|
|
- }else if serviceTempList[i].Title == "医药" || serviceTempList[i].Title == "消费" || serviceTempList[i].Title == "科技" || serviceTempList[i].Title == "智造" {
|
|
|
- }else {
|
|
|
+ } else if serviceTempList[i].ProductId == 2 {
|
|
|
+ if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "权益大套餐" || (serviceTempList[i].Title == "策略" && serviceTempListMap[serviceTempList[i].Pid].Pid == 0) {
|
|
|
+ } else if serviceTempList[i].Title == "医药" || serviceTempList[i].Title == "消费" || serviceTempList[i].Title == "科技" || serviceTempList[i].Title == "智造" {
|
|
|
+ } else {
|
|
|
serviceTempShow = append(serviceTempShow, serviceTempList[i])
|
|
|
}
|
|
|
- if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "45万" || serviceTempList[i].Title == "70万" {
|
|
|
+ if serviceTempList[i].Title == "行业套餐" || serviceTempList[i].Title == "45万" || serviceTempList[i].Title == "70万" {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- if serviceTempList[i].Pid > 0 && serviceTempListMap[serviceTempList[i].Pid].Pid > 0 {
|
|
|
+ if serviceTempList[i].Pid > 0 && serviceTempListMap[serviceTempList[i].Pid].Pid > 0 {
|
|
|
continue
|
|
|
}
|
|
|
|
|
@@ -372,8 +374,8 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
|
|
|
v.SetStyle(style)
|
|
|
if rowTitle[i] != "权益大套餐" && rowTitle[i] != "医药" && rowTitle[i] != "消费" && rowTitle[i] != "科技" && rowTitle[i] != "智造" {
|
|
|
v.VMerge = 1
|
|
|
- hi ++
|
|
|
- }else{
|
|
|
+ hi++
|
|
|
+ } else {
|
|
|
if insertHi == 0 {
|
|
|
insertHi = hi
|
|
|
}
|
|
@@ -384,7 +386,7 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
|
|
|
|
|
|
// 新增一行放主观和客观
|
|
|
specialRow := sheet.AddRow()
|
|
|
- for i:=0; i< hi; i++ {
|
|
|
+ for i := 0; i < hi; i++ {
|
|
|
if i == insertHi {
|
|
|
v1 := specialRow.AddCell()
|
|
|
v1.SetString("45万")
|
|
@@ -392,25 +394,25 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
|
|
|
v1 = specialRow.AddCell()
|
|
|
v1.SetString("70万")
|
|
|
v1.SetStyle(style)
|
|
|
- for j:=0; j<8;j++ {
|
|
|
- if j%2 ==0 {
|
|
|
+ for j := 0; j < 8; j++ {
|
|
|
+ if j%2 == 0 {
|
|
|
v1 = specialRow.AddCell()
|
|
|
v1.SetString("主观")
|
|
|
v1.SetStyle(style)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
v1 = specialRow.AddCell()
|
|
|
v1.SetString("客观")
|
|
|
v1.SetStyle(style)
|
|
|
}
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
v := specialRow.AddCell()
|
|
|
v.SetString("")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
newCompanyMap := map[int]string{0: "否", 1: "是"}
|
|
|
- sellerTypeMap := map[int]string{1:"FICC销售", 2:"权益销售"}
|
|
|
+ sellerTypeMap := map[int]string{1: "FICC销售", 2: "权益销售"}
|
|
|
for k, v := range list {
|
|
|
dataRow := sheet.AddRow()
|
|
|
// 前四个单元格根据每行开票到款条数向下合并
|
|
@@ -453,15 +455,15 @@ func ExportInvoicePaymentCensusList(c *gin.Context, results *fms.InvoicePaymentC
|
|
|
if item.ServiceTemplateId == serviceTempShow[i].ServiceTemplateId {
|
|
|
serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount)
|
|
|
break
|
|
|
- }else if serviceTempShow[i].Pid == item.ServiceTemplateId {
|
|
|
- serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount/2)
|
|
|
+ } else if serviceTempShow[i].Pid == item.ServiceTemplateId {
|
|
|
+ serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId] = fmt.Sprint(item.Amount / 2)
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
for i := range serviceTempShow {
|
|
|
sa := ""
|
|
|
- if am, ok := serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId]; ok {
|
|
|
+ if am, ok := serviceTempShowAmount[serviceTempShow[i].ServiceTemplateId]; ok {
|
|
|
sa = am
|
|
|
}
|
|
|
rowData = append(rowData, sa)
|
|
@@ -554,25 +556,25 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if req.ListParam == 1{
|
|
|
+ if req.ListParam == 1 {
|
|
|
cond += ` AND a.service_product_id = 1 `
|
|
|
- }else if req.ListParam == 2 {
|
|
|
+ } else if req.ListParam == 2 {
|
|
|
cond += ` AND a.service_product_id = 2 `
|
|
|
}
|
|
|
|
|
|
// 开票到款日期
|
|
|
if req.TimeType != 0 {
|
|
|
- if req.TimeType == 1 && req.StartDate != "" && req.EndDate != "" {
|
|
|
+ if req.TimeType == 1 && req.StartDate != "" && req.EndDate != "" {
|
|
|
st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
cond += ` AND (c.invoice_time BETWEEN ? AND ?) `
|
|
|
pars = append(pars, st, ed)
|
|
|
- }else if req.TimeType == 2 && req.StartDate != "" && req.EndDate != "" {
|
|
|
+ } else if req.TimeType == 2 && req.StartDate != "" && req.EndDate != "" {
|
|
|
st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
cond += ` AND (d.invoice_time BETWEEN ? AND ?) `
|
|
|
pars = append(pars, st, ed)
|
|
|
- }else if req.TimeType == 3 && req.StartDate != "" && req.EndDate != "" {
|
|
|
+ } else if req.TimeType == 3 && req.StartDate != "" && req.EndDate != "" {
|
|
|
st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
cond += ` AND (c.invoice_time BETWEEN ? AND ?) AND (d.invoice_time BETWEEN ? AND ?) `
|
|
@@ -585,21 +587,18 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
|
|
|
pars = append(pars, st, ed, st, ed)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if req.HasInvoice == "1" {
|
|
|
cond += ` AND a.invoice_id > 0 `
|
|
|
- }else if req.HasInvoice == "0" {
|
|
|
+ } else if req.HasInvoice == "0" {
|
|
|
cond += ` AND a.invoice_id = 0 `
|
|
|
}
|
|
|
|
|
|
if req.HasPayment == "1" {
|
|
|
cond += ` AND a.payment_id > 0 `
|
|
|
- }else if req.HasPayment == "0" {
|
|
|
+ } else if req.HasPayment == "0" {
|
|
|
cond += ` AND a.payment_id = 0 `
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
page := new(base.Page)
|
|
|
page.SetPageSize(req.PageSize)
|
|
|
page.SetCurrent(req.Current)
|
|
@@ -612,41 +611,40 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
if req.SortParam == "" {
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "sort_invoice_id", Asc: true})
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "sort_payment_id", Asc: false})
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "c.invoice_time", Asc: false})
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "c.amount", Asc: false})
|
|
|
- page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
- }else if req.SortParam == "invoice_time" {
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "sort_invoice_id", Asc: true})
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "sort_payment_id", Asc: false})
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "c.invoice_time", Asc: false})
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "c.amount", Asc: false})
|
|
|
+ page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
+ } else if req.SortParam == "invoice_time" {
|
|
|
if req.SortType == "asc" {
|
|
|
page.AddOrderItem(base.OrderItem{Column: "sort_invoice_id", Asc: false})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "c.invoice_time", Asc: true})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "c.amount", Asc: true})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: true})
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
page.AddOrderItem(base.OrderItem{Column: "sort_invoice_id", Asc: true})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "c.invoice_time", Asc: false})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "c.amount", Asc: false})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
}
|
|
|
- }else if req.SortParam == "payment_date" {
|
|
|
+ } else if req.SortParam == "payment_date" {
|
|
|
if req.SortType == "asc" {
|
|
|
page.AddOrderItem(base.OrderItem{Column: "sort_payment_id", Asc: false})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: true})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "d.amount", Asc: true})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: true})
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
page.AddOrderItem(base.OrderItem{Column: "sort_payment_id", Asc: true})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: false})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "d.amount", Asc: false})
|
|
|
page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
resp.Fail("排序字段不正确", c)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-
|
|
|
if req.IsExport == 1 {
|
|
|
page.SetPageSize(10000)
|
|
|
page.SetCurrent(1)
|
|
@@ -724,7 +722,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
|
|
|
contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
|
|
|
servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
|
|
|
}
|
|
|
-*/
|
|
|
+ */
|
|
|
servicesNameMap, serviceFormatMap, e := fmsService.GetContractServiceNameFormat(queryRegisterIds)
|
|
|
if e != nil {
|
|
|
listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
|
|
@@ -817,7 +815,7 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
|
|
|
}()
|
|
|
|
|
|
// 开票到款金额合计(换算后)
|
|
|
- var invoiceTotal, paymentTotal,amountTotal float64
|
|
|
+ var invoiceTotal, paymentTotal, amountTotal float64
|
|
|
wg.Add(1)
|
|
|
go func() {
|
|
|
defer wg.Done()
|
|
@@ -955,4 +953,658 @@ func (ct *InvoicePaymentController) List(c *gin.Context) {
|
|
|
resp.OkData("获取成功", baseData, c)
|
|
|
}
|
|
|
|
|
|
+// List
|
|
|
+// @Title 商品到款统计列表
|
|
|
+// @Description 商品到款统计列表
|
|
|
+// @Param SellerIds query string false "销售IDs"
|
|
|
+// @Param StartDate query string false "合同开始日期"
|
|
|
+// @Param EndDate query string false "合同结束日期"
|
|
|
+// @Param TimeType query int false "时间类型: 1-开票时间; 2-到款时间"
|
|
|
+// @Param IsExport query int false "是否导出: 0-否; 1-是"
|
|
|
+// @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'invoice_time':开票日 、 'payment_date':到款日"
|
|
|
+// @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
|
|
|
+// @Success 200 {object} fms.ContractRegisterItem
|
|
|
+// @router /census/income/list [get]
|
|
|
+//func (ct *InvoicePaymentController) IncomeList(c *gin.Context) {
|
|
|
+// var req fms.InvoicePaymentCensusListReq
|
|
|
+// if e := c.BindQuery(&req); e != nil {
|
|
|
+// err, ok := e.(validator.ValidationErrors)
|
|
|
+// if !ok {
|
|
|
+// resp.FailData("参数解析失败", "Err:"+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// resp.FailData("参数解析失败", err.Translate(global.Trans), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// cond := `1 = 1`
|
|
|
+// pars := make([]interface{}, 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)
|
|
|
+// }
|
|
|
+// // 套餐筛选
|
|
|
+// if req.ServiceTypes != "" {
|
|
|
+// serviceTypes := strings.Split(req.ServiceTypes, ",")
|
|
|
+// tempRegisterIds, e := fms.GetContractRegisterIdsByTempId(serviceTypes)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取合同登记IDs失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if len(tempRegisterIds) > 0 {
|
|
|
+// cond += ` AND a.register_id IN ?`
|
|
|
+// pars = append(pars, tempRegisterIds)
|
|
|
+// } else {
|
|
|
+// cond += ` AND 1 = 2`
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// if req.ListParam == 1 {
|
|
|
+// cond += ` AND a.service_product_id = 1 `
|
|
|
+// } else if req.ListParam == 2 {
|
|
|
+// cond += ` AND a.service_product_id = 2 `
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 开票到款日期
|
|
|
+// if req.TimeType != 0 {
|
|
|
+// if req.TimeType == 1 && req.StartDate != "" && req.EndDate != "" {
|
|
|
+// st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
+// ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
+// cond += ` AND (c.invoice_time BETWEEN ? AND ?) `
|
|
|
+// pars = append(pars, st, ed)
|
|
|
+// } else if req.TimeType == 2 && req.StartDate != "" && req.EndDate != "" {
|
|
|
+// st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
+// ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
+// cond += ` AND (d.invoice_time BETWEEN ? AND ?) `
|
|
|
+// pars = append(pars, st, ed)
|
|
|
+// } else if req.TimeType == 3 && req.StartDate != "" && req.EndDate != "" {
|
|
|
+// st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
+// ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
+// cond += ` AND (c.invoice_time BETWEEN ? AND ?) AND (d.invoice_time BETWEEN ? AND ?) `
|
|
|
+// pars = append(pars, st, ed, st, ed)
|
|
|
+// }
|
|
|
+// } else if req.StartDate != "" && req.EndDate != "" {
|
|
|
+// st := fmt.Sprint(req.StartDate, " 00:00:00")
|
|
|
+// ed := fmt.Sprint(req.EndDate, " 23:59:59")
|
|
|
+// cond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
+// pars = append(pars, st, ed, st, ed)
|
|
|
+// }
|
|
|
+//
|
|
|
+// if req.HasInvoice == "1" {
|
|
|
+// cond += ` AND a.invoice_id > 0 `
|
|
|
+// } else if req.HasInvoice == "0" {
|
|
|
+// cond += ` AND a.invoice_id = 0 `
|
|
|
+// }
|
|
|
+//
|
|
|
+// if req.HasPayment == "1" {
|
|
|
+// cond += ` AND a.payment_id > 0 `
|
|
|
+// } else if req.HasPayment == "0" {
|
|
|
+// cond += ` AND a.payment_id = 0 `
|
|
|
+// }
|
|
|
+//
|
|
|
+// page := new(base.Page)
|
|
|
+// page.SetPageSize(req.PageSize)
|
|
|
+// page.SetCurrent(req.Current)
|
|
|
+// //排序
|
|
|
+// if req.SortType == "" {
|
|
|
+// req.SortType = "desc"
|
|
|
+// }
|
|
|
+// if req.SortType != "desc" && req.SortType != "asc" {
|
|
|
+// resp.Fail("排序类型不正确", c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if req.SortParam == "" {
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "sort_invoice_id", Asc: true})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "sort_payment_id", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "c.invoice_time", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "c.amount", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
+// } else if req.SortParam == "invoice_time" {
|
|
|
+// if req.SortType == "asc" {
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "sort_invoice_id", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "c.invoice_time", Asc: true})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "c.amount", Asc: true})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: true})
|
|
|
+// } else {
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "sort_invoice_id", Asc: true})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "c.invoice_time", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "c.amount", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
+// }
|
|
|
+// } else if req.SortParam == "payment_date" {
|
|
|
+// if req.SortType == "asc" {
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "sort_payment_id", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: true})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "d.amount", Asc: true})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: true})
|
|
|
+// } else {
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "sort_payment_id", Asc: true})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "d.invoice_time", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "d.amount", Asc: false})
|
|
|
+// page.AddOrderItem(base.OrderItem{Column: "a.create_time", Asc: false})
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// resp.Fail("排序字段不正确", c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// if req.IsExport == 1 {
|
|
|
+// page.SetPageSize(10000)
|
|
|
+// page.SetCurrent(1)
|
|
|
+// }
|
|
|
+//
|
|
|
+// registerList, total, e := fms.GetInvoicePaymentCensusPageList(page, cond, pars)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取商品到款统计列表总数失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// queryRegisterIds := make([]int, 0)
|
|
|
+// for i := range registerList {
|
|
|
+// queryRegisterIds = append(queryRegisterIds, registerList[i].ContractRegisterId)
|
|
|
+// }
|
|
|
+//
|
|
|
+// //fmt.Println("queryRegisterIds:",queryRegisterIds)
|
|
|
+// results := new(fms.InvoicePaymentCensusResp)
|
|
|
+// if len(queryRegisterIds) > 0 {
|
|
|
+// // 获取汇总数据IDs, 用于查询合计数据
|
|
|
+// summaryIdsCond := cond
|
|
|
+// summaryIdsPars := pars
|
|
|
+// 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{}
|
|
|
+//
|
|
|
+// // 响应列表
|
|
|
+// respList := make([]*fms.InvoicePaymentCensusItem, 0)
|
|
|
+// summaryList := make([]*fms.InvoicePaymentSummaryItem, 0)
|
|
|
+// wg.Add(1)
|
|
|
+// go func() {
|
|
|
+// defer wg.Done()
|
|
|
+//
|
|
|
+// // 获取汇总数据
|
|
|
+// summaryCond := cond
|
|
|
+// summaryCond += ` AND a.register_id IN ?`
|
|
|
+// summaryPars := pars
|
|
|
+// summaryPars = append(summaryPars, queryRegisterIds)
|
|
|
+// summaryData, e := fms.GetInvoicePaymentCensusSummaryData(summaryCond, summaryPars)
|
|
|
+// if e != nil {
|
|
|
+// resp.FailMsg("获取失败", "获取商品到款汇总列表失败, Err: "+e.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// summaryList = summaryData
|
|
|
+// //summaryIds := make([]int, 0)
|
|
|
+// paymentIds := make([]int, 0)
|
|
|
+// for i := range summaryList {
|
|
|
+// //summaryIds = append(summaryIds, summaryList[i].SummaryId)
|
|
|
+// if summaryList[i].PaymentId > 0 {
|
|
|
+// paymentIds = append(paymentIds, summaryList[i].PaymentId)
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 合同套餐
|
|
|
+// /*contractServiceCond := `contract_register_id IN ?`
|
|
|
+// contractServicePars := make([]interface{}, 0)
|
|
|
+// contractServicePars = append(contractServicePars, queryRegisterIds)
|
|
|
+// contractServiceOB := new(fms.ContractService)
|
|
|
+// contractServiceList, e := contractServiceOB.List(contractServiceCond, contractServicePars)
|
|
|
+// if e != nil {
|
|
|
+// listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// contractServiceMap := make(map[int][]*fms.ContractService, 0)
|
|
|
+// servicesNameMap := make(map[int][]string, 0)
|
|
|
+// for i := range contractServiceList {
|
|
|
+// if contractServiceMap[contractServiceList[i].ContractRegisterId] == nil {
|
|
|
+// contractServiceMap[contractServiceList[i].ContractRegisterId] = make([]*fms.ContractService, 0)
|
|
|
+// }
|
|
|
+// contractServiceMap[contractServiceList[i].ContractRegisterId] = append(contractServiceMap[contractServiceList[i].ContractRegisterId], contractServiceList[i])
|
|
|
+// servicesNameMap[contractServiceList[i].ContractRegisterId] = append(servicesNameMap[contractServiceList[i].ContractRegisterId], contractServiceList[i].Title)
|
|
|
+// }
|
|
|
+// */
|
|
|
+// servicesNameMap, serviceFormatMap, e := fmsService.GetContractServiceNameFormat(queryRegisterIds)
|
|
|
+// if e != nil {
|
|
|
+// listErr = fmt.Errorf("获取合同套餐列表失败, Err: %s", e.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// // 到款套餐分配
|
|
|
+// serviceAmountMap := make(map[int][]*fms.ContractPaymentServiceAmount, 0)
|
|
|
+// if len(paymentIds) > 0 {
|
|
|
+// serviceAmountCond := `contract_payment_id IN ?`
|
|
|
+// serviceAmountPars := make([]interface{}, 0)
|
|
|
+// serviceAmountPars = append(serviceAmountPars, paymentIds)
|
|
|
+// serviceAmountOB := new(fms.ContractPaymentServiceAmount)
|
|
|
+// serviceAmountList, e := serviceAmountOB.List(serviceAmountCond, serviceAmountPars)
|
|
|
+// if e != nil {
|
|
|
+// listErr = fmt.Errorf("获取到款套餐分配列表失败, Err: %s", e.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// for i := range serviceAmountList {
|
|
|
+// if serviceAmountMap[serviceAmountList[i].ContractPaymentId] == nil {
|
|
|
+// serviceAmountMap[serviceAmountList[i].ContractPaymentId] = make([]*fms.ContractPaymentServiceAmount, 0)
|
|
|
+// }
|
|
|
+// serviceAmountMap[serviceAmountList[i].ContractPaymentId] = append(serviceAmountMap[serviceAmountList[i].ContractPaymentId], serviceAmountList[i])
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 重组汇总数据
|
|
|
+// summaryMap := make(map[int][]*fms.InvoicePaymentCensusInfo)
|
|
|
+// amountMap := make(map[string]*fms.ContractPaymentServiceAmount)
|
|
|
+// for i := range summaryList {
|
|
|
+// v := new(fms.InvoicePaymentCensusInfo)
|
|
|
+// v.InvoiceId = summaryList[i].InvoiceId
|
|
|
+// v.InvoiceDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].InvoiceDate)
|
|
|
+// v.InvoiceAmount = summaryList[i].InvoiceAmount
|
|
|
+// v.SellerId = summaryList[i].SellerId
|
|
|
+// v.SellerName = summaryList[i].SellerName
|
|
|
+// v.SellerGroupId = summaryList[i].SellerGroupId
|
|
|
+// v.SellerGroupName = summaryList[i].SellerGroupName
|
|
|
+// v.SellerType = summaryList[i].ServiceProductId
|
|
|
+// v.PaymentId = summaryList[i].PaymentId
|
|
|
+// v.PaymentDate = utils.TimeTransferString(utils.FormatDate, summaryList[i].PaymentDate)
|
|
|
+// v.PaymentAmount = summaryList[i].PaymentAmount
|
|
|
+// v.PayType = summaryList[i].PayType
|
|
|
+// // 套餐到款分配
|
|
|
+// svaList := make([]*fms.ContractPaymentServiceAmountItem, 0)
|
|
|
+// amountList := serviceAmountMap[summaryList[i].PaymentId]
|
|
|
+// if amountList != nil {
|
|
|
+// for i := range amountList {
|
|
|
+// k := fmt.Sprintf("%d-%d", amountList[i].ContractPaymentId, amountList[i].ServiceTemplateId)
|
|
|
+// amountMap[k] = amountList[i]
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 合同对应的所有套餐
|
|
|
+// svList := serviceFormatMap[summaryList[i].RegisterId]
|
|
|
+// if svList != nil {
|
|
|
+// for ii := range svList {
|
|
|
+// vv := new(fms.ContractPaymentServiceAmountItem)
|
|
|
+// vv.ServiceTemplateId = svList[ii].ServiceTemplateId
|
|
|
+// vv.ServiceTemplateName = svList[ii].FormatTitle
|
|
|
+// vv.ServiceTemplatePid = svList[ii].ServiceTemplatePid
|
|
|
+// vv.ServiceProductId = svList[ii].ServiceProductId
|
|
|
+// k2 := fmt.Sprintf("%d-%d", summaryList[i].PaymentId, svList[ii].ServiceTemplateId)
|
|
|
+// a := amountMap[k2]
|
|
|
+// if a != nil {
|
|
|
+// vv.ContractPaymentServiceAmountId = a.ContractPaymentServiceAmountId
|
|
|
+// vv.ContractPaymentId = a.ContractPaymentId
|
|
|
+// vv.Amount = a.Amount
|
|
|
+// }
|
|
|
+// svaList = append(svaList, vv)
|
|
|
+// }
|
|
|
+// }
|
|
|
+// v.ServiceAmountList = svaList
|
|
|
+//
|
|
|
+// summaryMap[summaryList[i].SummaryId] = append(summaryMap[summaryList[i].SummaryId], v)
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 响应列表
|
|
|
+// for i := range registerList {
|
|
|
+// v := new(fms.InvoicePaymentCensusItem)
|
|
|
+// v.SummaryId = registerList[i].SummaryId
|
|
|
+// v.ContractRegisterId = registerList[i].ContractRegisterId
|
|
|
+// v.CompanyName = registerList[i].CompanyName
|
|
|
+// v.NewCompany = registerList[i].NewCompany
|
|
|
+// v.StartDate = utils.TimeTransferString(utils.FormatDate, registerList[i].StartDate)
|
|
|
+// v.EndDate = utils.TimeTransferString(utils.FormatDate, registerList[i].EndDate)
|
|
|
+// v.ServicesName = servicesNameMap[registerList[i].ContractRegisterId]
|
|
|
+// v.InvoicePaymentList = summaryMap[registerList[i].SummaryId]
|
|
|
+// v.ContractType = registerList[i].ContractType
|
|
|
+// respList = append(respList, v)
|
|
|
+// }
|
|
|
+// }()
|
|
|
+//
|
|
|
+// // 开票到款金额合计(换算后)
|
|
|
+// var invoiceTotal, paymentTotal, amountTotal 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)
|
|
|
+//
|
|
|
+// amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
|
|
|
+// amountPars := make([]interface{}, 0)
|
|
|
+// amountPars = append(amountTotalPars, summaryIds)
|
|
|
+// amountSum, e := fms.GetContractSummaryInvoicePaymentAmount(amountCond, amountPars)
|
|
|
+// if e != nil {
|
|
|
+// totalErr = fmt.Errorf("获取汇总金额合计失败, Err: %s", e.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
|
|
|
+// }()
|
|
|
+//
|
|
|
+// // 分币种金额统计
|
|
|
+// invoiceCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
+// paymentCurrencyTotals := make([]*fms.InvoiceListCurrencyTotal, 0)
|
|
|
+// wg.Add(1)
|
|
|
+// go func() {
|
|
|
+// defer wg.Done()
|
|
|
+//
|
|
|
+// currencyOB := new(fms.CurrencyUnit)
|
|
|
+// currencyCond := `enable = 1`
|
|
|
+// currencyPars := make([]interface{}, 0)
|
|
|
+// currencyList, e := currencyOB.List(currencyCond, currencyPars)
|
|
|
+// if e != nil {
|
|
|
+// totalGroupErr = fmt.Errorf("获取货币列表失败, Err: %s", e.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// unitMap := make(map[string]string)
|
|
|
+// for i := range currencyList {
|
|
|
+// unitMap[currencyList[i].Code] = currencyList[i].UnitName
|
|
|
+// invoiceCurrencyTotals = append(invoiceCurrencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
+// Name: currencyList[i].Name,
|
|
|
+// UnitName: currencyList[i].UnitName,
|
|
|
+// Code: currencyList[i].Code,
|
|
|
+// FlagImg: currencyList[i].FlagImg,
|
|
|
+// })
|
|
|
+// paymentCurrencyTotals = append(paymentCurrencyTotals, &fms.InvoiceListCurrencyTotal{
|
|
|
+// Name: currencyList[i].Name,
|
|
|
+// UnitName: currencyList[i].UnitName,
|
|
|
+// Code: currencyList[i].Code,
|
|
|
+// FlagImg: currencyList[i].FlagImg,
|
|
|
+// })
|
|
|
+// }
|
|
|
+//
|
|
|
+// if len(summaryIds) == 0 {
|
|
|
+// return
|
|
|
+// }
|
|
|
+// totalGroupCond := `a.id IN ?`
|
|
|
+// totalGroupPars := make([]interface{}, 0)
|
|
|
+// totalGroupPars = append(totalGroupPars, summaryIds)
|
|
|
+// invoiceSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 1)
|
|
|
+// if e != nil {
|
|
|
+// totalGroupErr = fmt.Errorf("获取汇总货币合计开票金额失败, Err: %s", e.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// paymentSumGroup, e := fms.GetSummaryListCurrencySum(totalGroupCond, totalGroupPars, 2)
|
|
|
+// if e != nil {
|
|
|
+// totalGroupErr = fmt.Errorf("获取汇总货币合计到款金额失败, Err: %s", e.Error())
|
|
|
+// return
|
|
|
+// }
|
|
|
+// invoiceSumMap := make(map[string]float64)
|
|
|
+// paymentSumMap := make(map[string]float64)
|
|
|
+// for i := range invoiceSumGroup {
|
|
|
+// invoiceSumMap[invoiceSumGroup[i].CurrencyUnit] = invoiceSumGroup[i].OriginAmountTotal
|
|
|
+// continue
|
|
|
+// }
|
|
|
+// for i := range paymentSumGroup {
|
|
|
+// paymentSumMap[paymentSumGroup[i].CurrencyUnit] = paymentSumGroup[i].OriginAmountTotal
|
|
|
+// continue
|
|
|
+// }
|
|
|
+// for i := range invoiceCurrencyTotals {
|
|
|
+// a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", invoiceSumMap[invoiceCurrencyTotals[i].Code]), 64)
|
|
|
+// invoiceCurrencyTotals[i].Amount = a
|
|
|
+// }
|
|
|
+// for i := range paymentCurrencyTotals {
|
|
|
+// a, _ := strconv.ParseFloat(fmt.Sprintf("%.2f", paymentSumMap[paymentCurrencyTotals[i].Code]), 64)
|
|
|
+// paymentCurrencyTotals[i].Amount = a
|
|
|
+// }
|
|
|
+// }()
|
|
|
+//
|
|
|
+// wg.Wait()
|
|
|
+//
|
|
|
+// if listErr != nil {
|
|
|
+// resp.FailMsg("获取失败", listErr.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if totalErr != nil {
|
|
|
+// resp.FailMsg("获取失败", totalErr.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// if totalGroupErr != nil {
|
|
|
+// resp.FailMsg("获取失败", totalGroupErr.Error(), c)
|
|
|
+// return
|
|
|
+// }
|
|
|
+//
|
|
|
+// results.DataList = respList
|
|
|
+// results.InvoiceTotal = invoiceTotal
|
|
|
+// results.PaymentTotal = paymentTotal
|
|
|
+// results.AmountTotal = amountTotal
|
|
|
+// results.InvoiceCurrencyTotal = invoiceCurrencyTotals
|
|
|
+// results.PaymentCurrencyTotal = paymentCurrencyTotals
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 是否导出
|
|
|
+// if req.IsExport == 1 {
|
|
|
+// ExportInvoicePaymentCensusList(c, results)
|
|
|
+// return
|
|
|
+// }
|
|
|
+// page.SetTotal(total)
|
|
|
+// baseData := new(base.BaseData)
|
|
|
+// baseData.SetPage(page)
|
|
|
+// baseData.SetList(results)
|
|
|
+// resp.OkData("获取成功", baseData, c)
|
|
|
+//}
|
|
|
+
|
|
|
+// IncomeList
|
|
|
+// @Title 业务收入统计表
|
|
|
+// @Description 获取业务收入统计表接口
|
|
|
+// @Param ListParam query int false "套餐类型: 0-月度; 1-季度; 2-半年度;3-年度;4-月度累计"
|
|
|
+// @Success 200 {object} fms.CensusIncomeChartResp
|
|
|
+// @router /census/income/list [get]
|
|
|
+func (this *InvoicePaymentController) IncomeList(c *gin.Context) {
|
|
|
+ var req fms.IncomeListReq
|
|
|
+ if e := c.BindQuery(&req); e != nil {
|
|
|
+ err, ok := e.(validator.ValidationErrors)
|
|
|
+ if !ok {
|
|
|
+ resp.FailData("参数解析失败", "Err:"+e.Error(), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ resp.FailData("参数解析失败", err.Translate(global.Trans), c)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //收入统计
|
|
|
+ var incomeList models.CensusIncomeChartResp
|
|
|
+ ch := make(chan models.CensusIncomeChartResp, 1)
|
|
|
+ go getCensusIncomeListV2(ch, req)
|
|
|
+
|
|
|
+ for v := range ch {
|
|
|
+ incomeList = v
|
|
|
+ close(ch)
|
|
|
+ }
|
|
|
+
|
|
|
+ resp.OkData("获取成功", incomeList, c)
|
|
|
+}
|
|
|
+
|
|
|
+func getCensusIncomeListV2(ch chan models.CensusIncomeChartResp, req fms.IncomeListReq) (incomeChart models.CensusIncomeChartResp, err error) {
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ global.LOG.Error(err)
|
|
|
+ go alarm_msg.SendAlarmMsg("获取近两年的收入统计数据异常,Err:"+err.Error(), 3)
|
|
|
+ //go utils.SendEmail(utils.APPNAME+"获取近12个月的收入统计数据异常:"+time.Now().Format("2006-01-02 15:04:05"), err.Error(), utils.EmailSendToUsers)
|
|
|
+ }
|
|
|
+ ch <- incomeChart
|
|
|
+ }()
|
|
|
+ //todayStr := utils.GetToday("20060102")
|
|
|
+ //key := "admin:home:fmsIncomeList:" + todayStr
|
|
|
+ //
|
|
|
+ //redisJsonData, redisErr := global.Redis.Get(context.TODO(), key).Result()
|
|
|
+ //if redisErr != nil {
|
|
|
+ var dateSlice []string
|
|
|
+ var totalMoneySlice, prevTotalMoneySlice, yoySlice []float64
|
|
|
+ var yearNum, monthNum int
|
|
|
+ if req.StartDate != "" && req.EndDate != "" {
|
|
|
+ st := fmt.Sprint(req.StartDate, "-01 00:00:00")
|
|
|
+ ed := fmt.Sprint(req.EndDate, "-01 23:59:59")
|
|
|
+ startDate,_ := time.Parse(st, utils.FormatDateTime)
|
|
|
+ endDate,_ := time.Parse(ed, utils.FormatDateTime)
|
|
|
+ yearNum = startDate.Year() - endDate.Year()
|
|
|
+ monthNum = int(startDate.Month() - endDate.Month())
|
|
|
+ } else {
|
|
|
+ yearNum = time.Now().Year() - 2020
|
|
|
+ monthNum = int(time.Now().Month() - 1)
|
|
|
+ }
|
|
|
+
|
|
|
+ numMonth := yearNum*12 + monthNum //共存在多少个月
|
|
|
+ if req.ListParam == "1" {
|
|
|
+ numMonth = numMonth/3
|
|
|
+ } else if req.ListParam == "2" {
|
|
|
+ numMonth = numMonth/6
|
|
|
+ } else if req.ListParam == "3" {
|
|
|
+ numMonth = numMonth/12
|
|
|
+ }
|
|
|
+ // 累计值
|
|
|
+ var accumulate float64
|
|
|
+ for i := numMonth; i >= 0; i-- {
|
|
|
+ if req.ListParam == "1" {
|
|
|
+ i = i-2
|
|
|
+ } else if req.ListParam == "2" {
|
|
|
+ i = i-5
|
|
|
+ } else if req.ListParam == "3" {
|
|
|
+ i = i-11
|
|
|
+ }
|
|
|
+ timeNow, _ := time.Parse("2006-01", time.Now().Format("2006-01"))
|
|
|
+ dateSlice = append(dateSlice, timeNow.AddDate(0, -i, 0).Format("06/01"))
|
|
|
+ //开始日期
|
|
|
+ startDate := timeNow.AddDate(0, -i, 0).Format("2006-01")
|
|
|
+ prevStartDate := timeNow.AddDate(0, -i-1, 0).Format("2006-01")
|
|
|
+ startDate = fmt.Sprint(startDate, "-01")
|
|
|
+ prevStartDate = fmt.Sprint(prevStartDate, "-01")
|
|
|
+
|
|
|
+ //结束日期
|
|
|
+ endDateTime := timeNow.AddDate(0, -i+1, -1)
|
|
|
+ prevEndDateTime := timeNow.AddDate(0, -i, -1)
|
|
|
+ endDate := endDateTime.Format(utils.FormatDate)
|
|
|
+ prevEndDate := prevEndDateTime.Format(utils.FormatDate)
|
|
|
+
|
|
|
+ //因为就算是当月的后续事件还没到,也要计入数据统计,所以不做限制到当天处理
|
|
|
+ //if endDateTime.After(time.Now()) {
|
|
|
+ // endDate = time.Now().AddDate(0, 0, 1).Format(utils.FormatDate)
|
|
|
+ //} else {
|
|
|
+ // endDate = fmt.Sprint(endDate, "-01")
|
|
|
+ //}
|
|
|
+ cond := `1 = 1`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+
|
|
|
+ prevCond := `1 = 1`
|
|
|
+ prevPars := make([]interface{}, 0)
|
|
|
+
|
|
|
+ if req.CompanyType == 1 {
|
|
|
+ cond += ` AND b.new_company = 1 `
|
|
|
+ prevCond += ` AND b.new_company = 1 `
|
|
|
+ } else if req.CompanyType == 2 {
|
|
|
+ cond += ` AND b.new_company = 0 `
|
|
|
+ prevCond += ` AND b.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)
|
|
|
+ prevCond += ` AND (c.seller_id in ? OR d.seller_id in ?)`
|
|
|
+ prevPars = append(prevPars, sellerIds, sellerIds)
|
|
|
+ }
|
|
|
+
|
|
|
+ {
|
|
|
+ st := fmt.Sprint(startDate, " 00:00:00")
|
|
|
+ ed := fmt.Sprint(endDate, " 23:59:59")
|
|
|
+ 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 ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
|
|
|
+ amountPars := make([]interface{}, 0)
|
|
|
+ amountPars = append(amountPars, summaryIds)
|
|
|
+ amountSum, e := fms.GetContractSummaryInvoicePaymentAmount(amountCond, amountPars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取汇总金额合计失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ amountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
|
|
|
+ accumulate += amountTotal
|
|
|
+ }
|
|
|
+ if req.ListParam == "4"{
|
|
|
+ totalMoneySlice = append(totalMoneySlice, accumulate)
|
|
|
+ }else {
|
|
|
+ totalMoneySlice = append(totalMoneySlice, amountTotal)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ { //去年同期,用于计算同比值
|
|
|
+
|
|
|
+ prevSt := fmt.Sprint(prevStartDate, " 00:00:00")
|
|
|
+ prevEd := fmt.Sprint(prevEndDate, " 23:59:59")
|
|
|
+ prevCond += ` AND ((c.invoice_time BETWEEN ? AND ?) or (d.invoice_time BETWEEN ? AND ?))`
|
|
|
+ prevPars = append(prevPars, prevSt, prevEd, prevSt, prevEd)
|
|
|
+ prevSummaryIds, e := fms.GetInvoicePaymentCensusSummaryDataIds(prevCond, prevPars)
|
|
|
+ if e != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开票到款金额合计(换算后)
|
|
|
+ var prevAmountTotal float64
|
|
|
|
|
|
+ if len(prevSummaryIds) > 0 {
|
|
|
+ amountCond := `a.id IN ? AND (a.invoice_id <> 0 OR (a.payment_id <> 0 AND a.invoice_id =0))`
|
|
|
+ amountPars := make([]interface{}, 0)
|
|
|
+ amountPars = append(amountPars, prevSummaryIds)
|
|
|
+ amountSum, e := fms.GetContractSummaryInvoicePaymentAmount(amountCond, amountPars)
|
|
|
+ if e != nil {
|
|
|
+ err = fmt.Errorf("获取汇总金额合计失败, Err: %s", e.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ prevAmountTotal, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", amountSum), 64)
|
|
|
+ }
|
|
|
+ prevTotalMoneySlice = append(prevTotalMoneySlice, prevAmountTotal)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //计算同比值
|
|
|
+ for i := range prevTotalMoneySlice {
|
|
|
+ var yoy float64
|
|
|
+ fmt.Println("1:", prevTotalMoneySlice[i])
|
|
|
+ fmt.Println("2:", totalMoneySlice[i])
|
|
|
+ fmt.Println("3:", totalMoneySlice[i]-prevTotalMoneySlice[i])
|
|
|
+ if prevTotalMoneySlice[i] != 0 {
|
|
|
+ yoy = (totalMoneySlice[i] - prevTotalMoneySlice[i]) / prevTotalMoneySlice[i]
|
|
|
+ }
|
|
|
+ yoySlice = append(yoySlice, yoy)
|
|
|
+ }
|
|
|
+
|
|
|
+ incomeChart.Title = "开票到款统计图"
|
|
|
+ incomeChart.Date = dateSlice
|
|
|
+ incomeChart.TotalMoney = totalMoneySlice
|
|
|
+ incomeChart.Yoy = yoySlice
|
|
|
+
|
|
|
+ //redisJsonData, err := json.Marshal(incomeChart)
|
|
|
+ //if err == nil {
|
|
|
+ // global.Redis.SetEX(context.TODO(), key, string(redisJsonData), time.Minute*30)
|
|
|
+ //}
|
|
|
+ //} else {
|
|
|
+ // err = json.Unmarshal([]byte(redisJsonData), &incomeChart)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println("近两年的收入统计数据,json转换失败")
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+
|
|
|
+ return
|
|
|
+}
|