1、优化零售明细excel导出,新增日期字段;

This commit is contained in:
chenlin 2024-11-06 15:57:10 +08:00
parent 6d801b1404
commit 602f73a7a9

View File

@ -1845,9 +1845,8 @@ func GetSysUserInfoByIds() (map[uint32]SysUser, error) {
for _, user := range userInfos {
if countDigits(user.Uid) == 8 {
userMap[user.Uid] = user
} else {
userMap[uint32(user.UserId)] = user
}
userMap[uint32(user.UserId)] = user
}
return userMap, nil
@ -3782,10 +3781,10 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
flag10, _ := checkRoleMenu(c, DetailStorePerMenu)
nEndCount := 0
title := []interface{}{"订单编号", "订单类型", "用户ID", "客户手机号", "审核时间", "店铺", "银联流水号", "销售员1", "销售员2", "商品分类", "", "", "商品名称",
title := []interface{}{"订单编号", "订单类型", "用户ID", "客户手机号", "日期", "审核时间", "店铺", "银联流水号", "销售员1", "销售员2", "商品分类", "", "", "商品名称",
"供应商", "是否串码", "商品串码", "是否赠送", "销售数量", "指导零售价", "零售价", "零售优惠", "会员优惠", "实际零售价/退货价"}
title2 := []interface{}{"订单编号", "订单类型", "用户ID", "客户手机号", "审核时间", "店铺", "银联流水号", "销售员1", "销售员2", "一级分类", "二级分类", "三级分类", "商品名称",
title2 := []interface{}{"订单编号", "订单类型", "用户ID", "客户手机号", "日期", "审核时间", "店铺", "银联流水号", "销售员1", "销售员2", "一级分类", "二级分类", "三级分类", "商品名称",
"供应商", "是否串码", "商品串码", "是否赠送", "销售数量", "指导零售价", "零售价", "零售优惠", "会员优惠", "实际零售价/退货价"}
if flag1 { // 采购单价
@ -3884,6 +3883,8 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
}
orderFlag := false
salesMan1 := ""
salesMan2 := ""
// 先判断商品数量,确定要写几行数据
for rowId := 0; rowId < len(list[i].Commodities); rowId++ {
if list[i].RetailType == RetailTypeSale {
@ -3902,11 +3903,13 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
}
// 审核时间
var auditTime string
var auditTime, auditDate string
if list[i].AuditTime != nil {
auditTime = list[i].AuditTime.Format(ExcelTimeFormat)
auditDate = list[i].AuditTime.Format(DateTimeFormat) // Extract date only
} else {
auditTime = ""
auditDate = ""
}
// 商品分类
@ -3945,8 +3948,6 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
}
}
salesMan1 := ""
salesMan2 := ""
// 单个订单的汇总数据只记录一次
if !orderFlag {
orderFlag = true
@ -3967,6 +3968,7 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
saleType,
userId,
list[i].Tel,
auditDate,
auditTime,
list[i].StoreName,
list[i].BankTrxNo,
@ -4060,6 +4062,7 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
saleType,
userId,
list[i].Tel,
auditDate,
auditTime,
list[i].StoreName,
list[i].BankTrxNo,
@ -4152,11 +4155,12 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
saleType,
userId,
list[i].Tel,
auditDate,
auditTime,
list[i].StoreName,
list[i].BankTrxNo,
salesMan1, //销售员1
"", //销售员2
salesMan2, //销售员2
categoryLevels.Level1.Name, // 一级分类
categoryLevels.Level2.Name, // 二级分类
categoryLevels.Level3.Name, // 三级分类
@ -4353,7 +4357,7 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
}
totalData := "订单数:" + strconv.FormatInt(int64(len(list)), 10)
end := []interface{}{totalData, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
end := []interface{}{totalData, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
sumData.Count,
sumData.RetailPrice,
sumData.SalePrice,
@ -4447,27 +4451,27 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
var endRow string
switch nEndCount {
case 1:
endRow = fmt.Sprintf("AG"+"%d", nExcelStartRow+3)
case 2:
endRow = fmt.Sprintf("AH"+"%d", nExcelStartRow+3)
case 3:
case 2:
endRow = fmt.Sprintf("AI"+"%d", nExcelStartRow+3)
case 4:
case 3:
endRow = fmt.Sprintf("AJ"+"%d", nExcelStartRow+3)
case 5:
case 4:
endRow = fmt.Sprintf("AK"+"%d", nExcelStartRow+3)
case 6:
case 5:
endRow = fmt.Sprintf("AL"+"%d", nExcelStartRow+3)
case 7:
case 6:
endRow = fmt.Sprintf("AM"+"%d", nExcelStartRow+3)
case 8:
case 7:
endRow = fmt.Sprintf("AN"+"%d", nExcelStartRow+3)
case 9:
case 8:
endRow = fmt.Sprintf("AO"+"%d", nExcelStartRow+3)
case 10:
case 9:
endRow = fmt.Sprintf("AP"+"%d", nExcelStartRow+3)
case 10:
endRow = fmt.Sprintf("AQ"+"%d", nExcelStartRow+3)
default:
endRow = fmt.Sprintf("AF"+"%d", nExcelStartRow+3)
endRow = fmt.Sprintf("AG"+"%d", nExcelStartRow+3)
}
//endRow := fmt.Sprintf("AL%d", nExcelStartRow+2)
// 应用样式到整个表格
@ -4486,15 +4490,15 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
endRow3 := fmt.Sprintf("AJ%d", nExcelStartRow+3)
endRow4 := fmt.Sprintf("AK%d", nExcelStartRow+3)
_ = file.SetCellStyle("Sheet1", "A1", "AN1", style1)
_ = file.SetCellStyle("Sheet1", "AI2", endRow2, style1)
_ = file.SetCellStyle("Sheet1", "AL2", endRow2, style1)
_ = file.SetCellStyle("Sheet1", "AJ2", endRow3, style1)
_ = file.SetCellStyle("Sheet1", "AK2", endRow4, style1)
// 合并单元格
// 定义要排除的列
excludeCols := map[string]bool{"J": true, "K": true, "L": true}
excludeCols := map[string]bool{"K": true, "L": true, "M": true}
// 合并 J1-L1
_ = file.MergeCell("Sheet1", "J1", "L1")
_ = file.MergeCell("Sheet1", "K1", "M1")
// 根据 nEndCount 动态合并列
for i := 0; i < len(title); i++ {
// 获取当前列名
@ -4513,9 +4517,10 @@ func retailDetailExport(list []ErpOrder, sumData RetailDetailTotalData, c *gin.C
// 设置单元格大小
file.SetColWidth("Sheet1", "A", "A", 15)
file.SetColWidth("Sheet1", "D", "D", 15)
file.SetColWidth("Sheet1", "E", "E", 18)
file.SetColWidth("Sheet1", "F", "F", 25)
file.SetColWidth("Sheet1", "E", "E", 12)
file.SetColWidth("Sheet1", "F", "F", 18)
file.SetColWidth("Sheet1", "G", "G", 25)
file.SetColWidth("Sheet1", "H", "H", 25)
fmt.Println("save fileName:", config.ExportConfig.Path+fileName)
if err := file.SaveAs(config.ExportConfig.Path + fileName); err != nil {