1、产品库存汇总(按门店)总金额四舍五入。
This commit is contained in:
parent
51baf26dcc
commit
58418effd3
|
@ -263,6 +263,11 @@ type ErpOrderStoreManageDataResp struct {
|
|||
PageIndex int `json:"pageIndex"` // 页码
|
||||
PageSize int `json:"pageSize"` // 每页展示条数
|
||||
ExportUrl string `json:"export_url"`
|
||||
TotalSalesAmount float64 `json:"total_sales_amount"` // 总销售额
|
||||
TotalPromotionFee float64 `json:"total_promotion_fee"` // 总推广费
|
||||
TotalSalesProfit float64 `json:"total_sales_profit"` // 总销售毛利
|
||||
TotalStaffProfit float64 `json:"total_staff_profit"` // 总员工毛利
|
||||
TotalCount int64 `json:"total_count"` // 总销售数量
|
||||
}
|
||||
|
||||
// StoreManageData 门店经营数据
|
||||
|
@ -2293,7 +2298,26 @@ func QueryStoreManageData(req *ErpOrderStoreManageDataReq, c *gin.Context) (*Erp
|
|||
}
|
||||
qs.Where("state = ?", ErpOrderStateAudited)
|
||||
|
||||
// 查询数据
|
||||
// 查询汇总数据
|
||||
var summary struct {
|
||||
TotalSalesAmount float64
|
||||
TotalPromotionFee float64
|
||||
TotalSalesProfit float64
|
||||
TotalStaffProfit float64
|
||||
TotalCount int64
|
||||
}
|
||||
err = qs.Select("SUM(CASE WHEN retail_type = 'sale' THEN total_amount ELSE -total_amount END) AS total_sales_amount, " +
|
||||
"SUM(CASE WHEN retail_type = 'sale' THEN total_discount ELSE -total_discount END) AS total_promotion_fee, " +
|
||||
"SUM(CASE WHEN retail_type = 'sale' THEN total_sales_profit ELSE -total_sales_profit END) AS total_sales_profit, " +
|
||||
"SUM(CASE WHEN retail_type = 'sale' THEN total_staff_profit ELSE -total_staff_profit END) AS total_staff_profit, " +
|
||||
"SUM(CASE WHEN retail_type = 'sale' THEN total_count ELSE -total_count END) AS total_count").
|
||||
Find(&summary).Error
|
||||
if err != nil {
|
||||
logger.Error("QueryStoreManageData summary err:", logger.Field("err", err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 查询分页数据
|
||||
if req.SortType == "asc" {
|
||||
err = qs.Select("DATE_FORMAT(maker_time, '%Y-%m-%d') AS date, " +
|
||||
"SUM(CASE WHEN retail_type = 'sale' THEN total_discount ELSE -total_discount END) AS promotion_fee, " +
|
||||
|
@ -2322,6 +2346,13 @@ func QueryStoreManageData(req *ErpOrderStoreManageDataReq, c *gin.Context) (*Erp
|
|||
|
||||
finalStoreManageDataList := constructFinalStoreManageDataList(storeManageDataList, req)
|
||||
|
||||
// 汇总数据赋值给响应
|
||||
resp.TotalSalesAmount = math.Round(summary.TotalSalesAmount*100) / 100
|
||||
resp.TotalPromotionFee = math.Round(summary.TotalPromotionFee*100) / 100
|
||||
resp.TotalSalesProfit = math.Round(summary.TotalSalesProfit*100) / 100
|
||||
resp.TotalStaffProfit = math.Round(summary.TotalStaffProfit*100) / 100
|
||||
resp.TotalCount = summary.TotalCount
|
||||
|
||||
if req.IsExport == 1 { //导出excel
|
||||
storeName := "所有门店"
|
||||
if req.StoreId != 0 {
|
||||
|
@ -2334,7 +2365,7 @@ func QueryStoreManageData(req *ErpOrderStoreManageDataReq, c *gin.Context) (*Erp
|
|||
}
|
||||
|
||||
finalStoreManageDataList = constructFinalStoreManageDataList(storeManageDataList, req)
|
||||
filePath, err := storeManageDataExport(finalStoreManageDataList, storeName, c)
|
||||
filePath, err := storeManageDataExport(finalStoreManageDataList, storeName, summary, c)
|
||||
if err != nil {
|
||||
logger.Error("StoreManageDataExport err:", logger.Field("err", err))
|
||||
return nil, err
|
||||
|
@ -2413,7 +2444,13 @@ func constructFinalStoreManageDataList(storeManageDataList []StoreManageData, re
|
|||
}
|
||||
|
||||
// StoreManageDataExport 导出门店经营数据
|
||||
func storeManageDataExport(list []StoreManageData, storeName string, c *gin.Context) (string, error) {
|
||||
func storeManageDataExport(list []StoreManageData, storeName string, summary struct {
|
||||
TotalSalesAmount float64
|
||||
TotalPromotionFee float64
|
||||
TotalSalesProfit float64
|
||||
TotalStaffProfit float64
|
||||
TotalCount int64
|
||||
}, c *gin.Context) (string, error) {
|
||||
file := excelize.NewFile()
|
||||
fSheet := "Sheet1"
|
||||
|
||||
|
@ -2477,6 +2514,25 @@ func storeManageDataExport(list []StoreManageData, storeName string, c *gin.Cont
|
|||
nExcelStartRow++
|
||||
}
|
||||
|
||||
totalData := "汇总 记录数:" + strconv.FormatInt(int64(len(list)), 10)
|
||||
end := []interface{}{totalData, summary.TotalSalesAmount, summary.TotalPromotionFee}
|
||||
|
||||
if flag1 { // 销售毛利
|
||||
end = append(end, summary.TotalSalesProfit)
|
||||
}
|
||||
if flag2 { // 员工毛利
|
||||
end = append(end, summary.TotalStaffProfit)
|
||||
}
|
||||
end = append(end, summary.TotalCount)
|
||||
|
||||
for i, _ := range end {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+i, nExcelStartRow+2)
|
||||
err := file.SetCellValue(fSheet, cell, end[i])
|
||||
if err != nil {
|
||||
logger.Error("file set value err:", logger.Field("err", err))
|
||||
}
|
||||
}
|
||||
|
||||
// 设置所有单元格的样式: 居中、加边框
|
||||
style, _ := file.NewStyle(`{"alignment":{"horizontal":"center","vertical":"center"},
|
||||
"border":[{"type":"left","color":"000000","style":1},
|
||||
|
@ -2493,11 +2549,11 @@ func storeManageDataExport(list []StoreManageData, storeName string, c *gin.Cont
|
|||
var endRow string
|
||||
switch nEndCount {
|
||||
case 1:
|
||||
endRow = fmt.Sprintf("E"+"%d", nExcelStartRow+1)
|
||||
endRow = fmt.Sprintf("E"+"%d", nExcelStartRow+2)
|
||||
case 2:
|
||||
endRow = fmt.Sprintf("F"+"%d", nExcelStartRow+1)
|
||||
endRow = fmt.Sprintf("F"+"%d", nExcelStartRow+2)
|
||||
default:
|
||||
endRow = fmt.Sprintf("D"+"%d", nExcelStartRow+1)
|
||||
endRow = fmt.Sprintf("D"+"%d", nExcelStartRow+2)
|
||||
}
|
||||
// 应用样式到整个表格
|
||||
_ = file.SetCellStyle("Sheet1", "A1", endRow, style)
|
||||
|
|
Loading…
Reference in New Issue
Block a user