|
@@ -640,6 +640,131 @@ func OrderOutput(c *gin.Context) { |
|
|
_ = xlsx.Write(c.Writer) |
|
|
_ = xlsx.Write(c.Writer) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
func OrderGoodsOutput(c *gin.Context) { |
|
|
|
|
|
var args map[string]string |
|
|
|
|
|
if err := c.ShouldBindJSON(&args); err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_INVALID_ARGS, err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
eg := db.Db |
|
|
|
|
|
list := db.GetOrderListOutput(eg, args) |
|
|
|
|
|
xlsx, _ := excelize.OpenFile("./static/template/订单品类明细表.xlsx") |
|
|
|
|
|
|
|
|
|
|
|
var data = map[string]map[string][]map[string]string{} |
|
|
|
|
|
var enterpriseMap = make(map[int]model.Enterprise) |
|
|
|
|
|
enterpriseIds := make([]int, 0) |
|
|
|
|
|
dateList := make([]string, 0) |
|
|
|
|
|
|
|
|
|
|
|
oids := make([]int64, 0) |
|
|
|
|
|
|
|
|
|
|
|
if list != nil { |
|
|
|
|
|
ordMap := make(map[int64]model.Order) |
|
|
|
|
|
for _, v := range *list { |
|
|
|
|
|
_, ok := ordMap[v.Oid] |
|
|
|
|
|
if ok == false { |
|
|
|
|
|
ordMap[v.Oid] = model.Order{} |
|
|
|
|
|
} |
|
|
|
|
|
ordMap[v.Oid] = v |
|
|
|
|
|
oids = append(oids, v.Oid) |
|
|
|
|
|
enterpriseIds = append(enterpriseIds, v.EnterpriseId) |
|
|
|
|
|
} |
|
|
|
|
|
enterpriseMap = db.GetEnterpriseMore(eg, enterpriseIds) |
|
|
|
|
|
|
|
|
|
|
|
ord := db.GetOrderGoodsByOid(eg, oids) |
|
|
|
|
|
|
|
|
|
|
|
for _, v := range *ord { |
|
|
|
|
|
dateStr := ordMap[v.Oid].CreateAt.Format("2006-01-02") |
|
|
|
|
|
if utils.InArr(dateStr, dateList) == false { |
|
|
|
|
|
dateList = append(dateList, dateStr) |
|
|
|
|
|
} |
|
|
|
|
|
if data[dateStr] == nil { |
|
|
|
|
|
data[dateStr] = make(map[string][]map[string]string) |
|
|
|
|
|
} |
|
|
|
|
|
gidStr := utils.Int64ToStr(v.GoodsId) + "_" + utils.Int64ToStr(v.SkuId) |
|
|
|
|
|
if data[dateStr][gidStr] == nil { |
|
|
|
|
|
data[dateStr][gidStr] = make([]map[string]string, 0) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tmp := make(map[string]string) |
|
|
|
|
|
tmp["date"] = ordMap[v.Oid].CreateAt.Format("2006-01-02") |
|
|
|
|
|
tmp["send_date"] = gjson.Get(ordMap[v.Oid].BuyInfo, "date").String() |
|
|
|
|
|
tmp["goods_name"] = v.GoodsTitle |
|
|
|
|
|
tmp["make_date"] = utils.TimeParseDateStd1(v.MakeDate) |
|
|
|
|
|
if v.OrdNo == "" { |
|
|
|
|
|
v.OrdNo = utils.Int64ToStr(v.Oid) |
|
|
|
|
|
} |
|
|
|
|
|
tmp["ord_no"] = v.OrdNo |
|
|
|
|
|
tmp["goods_type"] = utils.IntToStr(v.GoodsType) |
|
|
|
|
|
skuData := make([]md.Sku, 0) |
|
|
|
|
|
json.Unmarshal([]byte(v.Sku), &skuData) |
|
|
|
|
|
skuStr := "" |
|
|
|
|
|
for _, v1 := range skuData { |
|
|
|
|
|
if skuStr != "" { |
|
|
|
|
|
skuStr += ";" |
|
|
|
|
|
} |
|
|
|
|
|
skuStr += v1.Value |
|
|
|
|
|
} |
|
|
|
|
|
tmp["sku_str"] = skuStr |
|
|
|
|
|
tmp["num"] = utils.IntToStr(v.Num) |
|
|
|
|
|
inSideName := "" |
|
|
|
|
|
_, ok := enterpriseMap[v.EnterpriseId] |
|
|
|
|
|
if ok { |
|
|
|
|
|
inSideName = enterpriseMap[v.EnterpriseId].InsideName |
|
|
|
|
|
} |
|
|
|
|
|
tmp["inSideName"] = inSideName |
|
|
|
|
|
data[dateStr][gidStr] = append(data[dateStr][gidStr], tmp) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
sheetIndex := 2 //第一个表是模板表 |
|
|
|
|
|
xlsx.NewSheet("Sheet1") //新建表格 |
|
|
|
|
|
xlsx.CopySheet(1, sheetIndex) |
|
|
|
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(2), &[]interface{}{ |
|
|
|
|
|
"日期:" + utils.TimeParseStd(args["start_at"]).Format("2006-01-02") + " ~ " + utils.TimeParseStd(args["end_at"]).Format("2006-01-02"), |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
j := 4 //表头前三行被占用了,只能从第四行开始 |
|
|
|
|
|
for _, v0 := range dateList { |
|
|
|
|
|
for _, v := range data[v0] { |
|
|
|
|
|
var total = 0 |
|
|
|
|
|
title := "" |
|
|
|
|
|
for _, vv := range v { |
|
|
|
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ |
|
|
|
|
|
vv["date"], |
|
|
|
|
|
vv["ord_no"], |
|
|
|
|
|
vv["inSideName"], |
|
|
|
|
|
vv["num"], |
|
|
|
|
|
vv["make_date"], |
|
|
|
|
|
}) |
|
|
|
|
|
title = vv["goods_name"] + " " + vv["sku_st"] |
|
|
|
|
|
xlsx.SetRowHeight("Sheet1", j, 18) |
|
|
|
|
|
total += utils.StrToInt(vv["num"]) |
|
|
|
|
|
j++ |
|
|
|
|
|
} |
|
|
|
|
|
style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFFCC"],"pattern":1}, "alignment":{"horizontal":"center", "vertical": "center"}}`) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
logx.Error(err) |
|
|
|
|
|
println("<<<<SelfSupportForSchoolDataStatisticsExport4>>>>>Error:::", err.Error()) |
|
|
|
|
|
panic(err) |
|
|
|
|
|
} |
|
|
|
|
|
xlsx.MergeCell("Sheet1", "A"+strconv.Itoa(j), "F"+strconv.Itoa(j)) //合并单元格 |
|
|
|
|
|
xlsx.SetCellStyle("Sheet1", "A"+strconv.Itoa(j), "F"+strconv.Itoa(j), style) |
|
|
|
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ |
|
|
|
|
|
title + " 汇总: " + utils.IntToStr(total), |
|
|
|
|
|
}) |
|
|
|
|
|
xlsx.SetRowHeight("Sheet1", j, 20) |
|
|
|
|
|
j++ |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
xlsx.DeleteSheet("template") //删除模板表 |
|
|
|
|
|
|
|
|
|
|
|
c.Header("Content-Type", "application/octet-stream") |
|
|
|
|
|
c.Header("Content-Disposition", "attachment; filename="+"订单记录"+".xlsx") |
|
|
|
|
|
c.Header("Content-Transfer-Encoding", "binary") |
|
|
|
|
|
//回写到web 流媒体 形成下载 |
|
|
|
|
|
_ = xlsx.Write(c.Writer) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
func OrderEdit(c *gin.Context) { |
|
|
func OrderEdit(c *gin.Context) { |
|
|
var args map[string]string |
|
|
var args map[string]string |
|
|
if err := c.ShouldBindJSON(&args); err != nil { |
|
|
if err := c.ShouldBindJSON(&args); err != nil { |
|
|