1.优化商品资料excel导出功能;
This commit is contained in:
parent
b817b7fd40
commit
499959fa41
|
@ -1444,44 +1444,85 @@ func ErpStockCommodityToInventory(inventoryStockIdMap map[string]uint32, list []
|
|||
// ErpCommodityListExport 导出商品列表
|
||||
func ErpCommodityListExport(list []ErpCommodity) (string, error) {
|
||||
file := excelize.NewFile()
|
||||
streamWriter, err := file.NewStreamWriter("Sheet1")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
fSheet := "Sheet1"
|
||||
|
||||
url := ExportUrl
|
||||
fileName := time.Now().Format(TimeFormat) + "商品" + ".xlsx"
|
||||
fileName := time.Now().Format(TimeFormat) + "商品资料" + ".xlsx"
|
||||
|
||||
//title := []interface{}{"供应商编号", "供应商名称", "联系人", "手机号", "地址", "开户银行", "银行账号", "付款周期/天"}
|
||||
title := []interface{}{"商品编号", "商品名称", "商品分类", "是否串码", "主供应商", "零售价", "最低零售价", "员工成本价",
|
||||
"采购价", "提成等级1", "提成等级2", "产地", "备注", "会员折扣(零售价的百分比)"}
|
||||
cell, _ := excelize.CoordinatesToCellName(1, 1)
|
||||
if err = streamWriter.SetRow(cell, title); err != nil {
|
||||
fmt.Println(err)
|
||||
title := []interface{}{"商品编号", "商品名称", "商品分类", "商品条码", "是否串码", "系统生成串码", "主供应商", "指导零售价",
|
||||
"最低零售价", "员工成本价加价", "指导采购价", "销售毛利提成", "员工毛利提成", "会员优惠", "产地", "备注"}
|
||||
for i, _ := range title {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+i, 1)
|
||||
err := file.SetCellValue(fSheet, cell, title[i])
|
||||
if err != nil {
|
||||
logger.Errorf("file set value err:", err)
|
||||
}
|
||||
}
|
||||
|
||||
var row []interface{}
|
||||
nExcelStartRow := 0
|
||||
for rowId := 0; rowId < len(list); rowId++ {
|
||||
isIMEI := "否"
|
||||
if list[rowId].IMEIType == 2 {
|
||||
systemIMEI := "否"
|
||||
if list[rowId].IMEIType != 1 { // 非串码
|
||||
isIMEI = "是"
|
||||
if list[rowId].IMEIType == 2 { //2-串码(系统生成)
|
||||
systemIMEI = "是"
|
||||
}
|
||||
}
|
||||
|
||||
row = []interface{}{list[rowId].SerialNumber, list[rowId].Name, list[rowId].ErpCategoryName,
|
||||
isIMEI, list[rowId].ErpSupplierName, list[rowId].RetailPrice,
|
||||
list[rowId].MinRetailPrice, list[rowId].StaffCostPrice, list[rowId].WholesalePrice, list[rowId].Brokerage1,
|
||||
list[rowId].Brokerage2, list[rowId].Origin, list[rowId].Remark, list[rowId].MemberDiscount}
|
||||
cell, _ := excelize.CoordinatesToCellName(1, rowId+2)
|
||||
if err := streamWriter.SetRow(cell, row); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
if err := streamWriter.Flush(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
if err := file.SaveAs("/www/server/images/export/" + fileName); err != nil {
|
||||
//if err := file.SaveAs("./" + fileName); err != nil {
|
||||
row = []interface{}{
|
||||
list[rowId].SerialNumber,
|
||||
list[rowId].Name,
|
||||
list[rowId].ErpCategoryName,
|
||||
list[rowId].ErpBarcode,
|
||||
isIMEI,
|
||||
systemIMEI,
|
||||
list[rowId].ErpSupplierName,
|
||||
list[rowId].RetailPrice,
|
||||
list[rowId].MinRetailPrice,
|
||||
list[rowId].StaffCostPrice,
|
||||
list[rowId].WholesalePrice,
|
||||
list[rowId].Brokerage1,
|
||||
list[rowId].Brokerage2,
|
||||
list[rowId].MemberDiscount,
|
||||
list[rowId].Origin,
|
||||
list[rowId].Remark}
|
||||
|
||||
for j, _ := range row {
|
||||
cell, _ := excelize.CoordinatesToCellName(1+j, nExcelStartRow+2)
|
||||
err := file.SetCellValue(fSheet, cell, row[j])
|
||||
if err != nil {
|
||||
logger.Error("file set value err:", logger.Field("err", err))
|
||||
}
|
||||
}
|
||||
nExcelStartRow++
|
||||
}
|
||||
// 设置所有单元格的样式: 居中、加边框
|
||||
style, _ := file.NewStyle(`{"alignment":{"horizontal":"center","vertical":"center"},
|
||||
"border":[{"type":"left","color":"000000","style":1},
|
||||
{"type":"top","color":"000000","style":1},
|
||||
{"type":"right","color":"000000","style":1},
|
||||
{"type":"bottom","color":"000000","style":1}]}`)
|
||||
|
||||
//设置单元格高度
|
||||
file.SetRowHeight("Sheet1", 1, 20)
|
||||
|
||||
// 设置单元格大小
|
||||
file.SetColWidth("Sheet1", "A", "A", 15)
|
||||
file.SetColWidth("Sheet1", "B", "B", 30)
|
||||
file.SetColWidth("Sheet1", "D", "D", 18)
|
||||
|
||||
endRow := fmt.Sprintf("P"+"%d", nExcelStartRow+2)
|
||||
|
||||
// 应用样式到整个表格
|
||||
_ = file.SetCellStyle("Sheet1", "A1", endRow, style)
|
||||
|
||||
fmt.Println("save fileName:", config.ExportConfig.Path+fileName)
|
||||
if err := file.SaveAs(config.ExportConfig.Path + fileName); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
|
||||
return url + fileName, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user