|
@@ -7,6 +7,7 @@ import ( |
|
|
"applet/app/e" |
|
|
"applet/app/e" |
|
|
"applet/app/svc" |
|
|
"applet/app/svc" |
|
|
"applet/app/utils" |
|
|
"applet/app/utils" |
|
|
|
|
|
"applet/app/utils/logx" |
|
|
"encoding/json" |
|
|
"encoding/json" |
|
|
"fmt" |
|
|
"fmt" |
|
|
"github.com/360EntSecGroup-Skylar/excelize" |
|
|
"github.com/360EntSecGroup-Skylar/excelize" |
|
@@ -83,49 +84,92 @@ func OrderExport(c *gin.Context) { |
|
|
} |
|
|
} |
|
|
eg := db.Db |
|
|
eg := db.Db |
|
|
list, _ := db.GetOrderListExport(eg, args) |
|
|
list, _ := db.GetOrderListExport(eg, args) |
|
|
|
|
|
xlsx, _ := excelize.OpenFile("./static/template/商品销售明细表.xlsx") |
|
|
|
|
|
|
|
|
titleList := []string{"订单编号", "金额", "手机号", "企业名称", "学校名称", "状态", "送达时间", "订单时间"} |
|
|
|
|
|
xlsx := excelize.NewFile() |
|
|
|
|
|
xlsx.SetSheetRow("Sheet1", "A1", &titleList) |
|
|
|
|
|
style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFF00"],"pattern":1}, "alignment":{"horizontal":"center"}}`) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR, err.Error()) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
xlsx.SetCellStyle("Sheet1", "A1", "M1", style) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "A", "A", 35) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "B", "B", 30) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "C", "E", 15) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "F", "I", 10) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "J", "J", 20) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "K", "K", 10) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "L", "L", 25) |
|
|
|
|
|
xlsx.SetColWidth("Sheet1", "M", "M", 15) |
|
|
|
|
|
//表头被第一行用了,只能从第二行开始 |
|
|
|
|
|
j := 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = map[string]map[int64]map[string]string{} |
|
|
if list != nil { |
|
|
if list != nil { |
|
|
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} |
|
|
|
|
|
enterpriseIds := make([]int, 0) |
|
|
enterpriseIds := make([]int, 0) |
|
|
for _, v := range *list { |
|
|
for _, v := range *list { |
|
|
enterpriseIds = append(enterpriseIds, v.EnterpriseId) |
|
|
enterpriseIds = append(enterpriseIds, v.EnterpriseId) |
|
|
} |
|
|
} |
|
|
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) |
|
|
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) |
|
|
|
|
|
|
|
|
for _, v := range *list { |
|
|
for _, v := range *list { |
|
|
v1 := JudgePackageOrdOrdState(&v) |
|
|
|
|
|
enterpriseName := "" |
|
|
|
|
|
|
|
|
enterpriseName := "-" |
|
|
_, ok := enterpriseMap[v.EnterpriseId] |
|
|
_, ok := enterpriseMap[v.EnterpriseId] |
|
|
if ok { |
|
|
if ok { |
|
|
enterpriseName = enterpriseMap[v.EnterpriseId].Name |
|
|
enterpriseName = enterpriseMap[v.EnterpriseId].Name |
|
|
} |
|
|
} |
|
|
|
|
|
if data[enterpriseName] == nil { |
|
|
|
|
|
data[enterpriseName] = make(map[int64]map[string]string) |
|
|
|
|
|
} |
|
|
|
|
|
if data[enterpriseName][v.Oid] == nil { |
|
|
|
|
|
data[enterpriseName][v.Oid] = make(map[string]string) |
|
|
|
|
|
} |
|
|
|
|
|
//TODO:: 查找 `order_goods` |
|
|
|
|
|
var orderGoods []model.OrderGoods |
|
|
|
|
|
err := eg.Where("oid = ?", v.Oid).Find(&orderGoods) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
for _, vv := range orderGoods { |
|
|
|
|
|
data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02") |
|
|
|
|
|
data[enterpriseName][v.Oid]["goods_name"] = vv.GoodsTitle |
|
|
|
|
|
skuData := make([]md.Sku, 0) |
|
|
|
|
|
json.Unmarshal([]byte(vv.Sku), &skuData) |
|
|
|
|
|
skuStr := "" |
|
|
|
|
|
for _, v1 := range skuData { |
|
|
|
|
|
if skuStr != "" { |
|
|
|
|
|
skuStr += ";" |
|
|
|
|
|
} |
|
|
|
|
|
skuStr += v1.Value |
|
|
|
|
|
} |
|
|
|
|
|
data[enterpriseName][v.Oid]["sku_str"] = skuStr |
|
|
|
|
|
data[enterpriseName][v.Oid]["num"] = utils.IntToStr(vv.Num) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 k, v := range data { |
|
|
|
|
|
var total = 0 |
|
|
|
|
|
for kk, vv := range v { |
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ |
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ |
|
|
utils.Int64ToStr(v1.Oid), v1.Amount, v1.BuyPhone, enterpriseName, stateArr[v1.State], |
|
|
|
|
|
gjson.Get(v1.BuyInfo, "date").String() + " " + gjson.Get(v1.BuyInfo, "time").String(), v1.CreateAt.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
|
|
|
vv["date"], |
|
|
|
|
|
utils.Int64ToStr(kk), |
|
|
|
|
|
k, |
|
|
|
|
|
vv["goods_name"], |
|
|
|
|
|
vv["sku_str"], |
|
|
|
|
|
vv["num"], |
|
|
}) |
|
|
}) |
|
|
|
|
|
xlsx.SetRowHeight("Sheet1", j, 18) |
|
|
|
|
|
total += utils.StrToInt(vv["num"]) |
|
|
j++ |
|
|
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{}{ |
|
|
|
|
|
k + " 汇总: " + utils.IntToStr(total), |
|
|
|
|
|
}) |
|
|
|
|
|
xlsx.SetRowHeight("Sheet1", j, 20) |
|
|
|
|
|
j++ |
|
|
|
|
|
} |
|
|
|
|
|
xlsx.DeleteSheet("template") //删除模板表 |
|
|
|
|
|
|
|
|
c.Header("Content-Type", "application/octet-stream") |
|
|
c.Header("Content-Type", "application/octet-stream") |
|
|
c.Header("Content-Disposition", "attachment; filename="+"订单记录"+".xlsx") |
|
|
c.Header("Content-Disposition", "attachment; filename="+"订单记录"+".xlsx") |
|
@@ -417,49 +461,98 @@ func OrderOutput(c *gin.Context) { |
|
|
} |
|
|
} |
|
|
eg := db.Db |
|
|
eg := db.Db |
|
|
list := db.GetOrderListOutput(eg, args) |
|
|
list := db.GetOrderListOutput(eg, args) |
|
|
|
|
|
xlsx, _ := excelize.OpenFile("./static/template/商品销售明细表.xlsx") |
|
|
|
|
|
|
|
|
name := "订单_" + args["page"] |
|
|
|
|
|
//写入数据 |
|
|
|
|
|
data := map[string]string{ |
|
|
|
|
|
"A1": "购买人手机号", |
|
|
|
|
|
"B1": "学校名称", |
|
|
|
|
|
"C1": "订单编号", |
|
|
|
|
|
"D1": "总金额", |
|
|
|
|
|
"E1": "订单状态", |
|
|
|
|
|
"F1": "送达时间", |
|
|
|
|
|
"G1": "下单时间", |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var data = map[string]map[int64]map[string]string{} |
|
|
if list != nil { |
|
|
if list != nil { |
|
|
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} |
|
|
|
|
|
enterpriseIds := make([]int, 0) |
|
|
enterpriseIds := make([]int, 0) |
|
|
for _, v := range *list { |
|
|
for _, v := range *list { |
|
|
enterpriseIds = append(enterpriseIds, v.EnterpriseId) |
|
|
enterpriseIds = append(enterpriseIds, v.EnterpriseId) |
|
|
} |
|
|
} |
|
|
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) |
|
|
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) |
|
|
for k, v := range *list { |
|
|
|
|
|
v1 := v |
|
|
|
|
|
enterpriseName := "" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for _, v := range *list { |
|
|
|
|
|
enterpriseName := "-" |
|
|
_, ok := enterpriseMap[v.EnterpriseId] |
|
|
_, ok := enterpriseMap[v.EnterpriseId] |
|
|
if ok { |
|
|
if ok { |
|
|
enterpriseName = enterpriseMap[v.EnterpriseId].Name |
|
|
enterpriseName = enterpriseMap[v.EnterpriseId].Name |
|
|
} |
|
|
} |
|
|
i := utils.IntToStr(k + 2) |
|
|
|
|
|
data["A"+i] = v1.BuyPhone |
|
|
|
|
|
data["B"+i] = enterpriseName |
|
|
|
|
|
data["C"+i] = utils.Int64ToStr(v1.Oid) |
|
|
|
|
|
data["D"+i] = v1.Amount |
|
|
|
|
|
data["E"+i] = stateArr[v1.State] |
|
|
|
|
|
data["F"+i] = gjson.Get(v1.BuyInfo, "date").String() + " " + gjson.Get(v1.BuyInfo, "time").String() |
|
|
|
|
|
data["G"+i] = v1.CreateAt.Format("2006-01-02 15:04:05") |
|
|
|
|
|
|
|
|
if data[enterpriseName] == nil { |
|
|
|
|
|
data[enterpriseName] = make(map[int64]map[string]string) |
|
|
|
|
|
} |
|
|
|
|
|
if data[enterpriseName][v.Oid] == nil { |
|
|
|
|
|
data[enterpriseName][v.Oid] = make(map[string]string) |
|
|
|
|
|
} |
|
|
|
|
|
//TODO:: 查找 `order_goods` |
|
|
|
|
|
var orderGoods []model.OrderGoods |
|
|
|
|
|
err := eg.Where("oid = ?", v.Oid).Find(&orderGoods) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
e.OutErr(c, e.ERR_DB_ORM, err) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
for _, vv := range orderGoods { |
|
|
|
|
|
data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02") |
|
|
|
|
|
data[enterpriseName][v.Oid]["goods_name"] = vv.GoodsTitle |
|
|
|
|
|
skuData := make([]md.Sku, 0) |
|
|
|
|
|
json.Unmarshal([]byte(vv.Sku), &skuData) |
|
|
|
|
|
skuStr := "" |
|
|
|
|
|
for _, v1 := range skuData { |
|
|
|
|
|
if skuStr != "" { |
|
|
|
|
|
skuStr += ";" |
|
|
|
|
|
} |
|
|
|
|
|
skuStr += v1.Value |
|
|
|
|
|
} |
|
|
|
|
|
data[enterpriseName][v.Oid]["sku_str"] = skuStr |
|
|
|
|
|
data[enterpriseName][v.Oid]["num"] = utils.IntToStr(vv.Num) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
file := utils.Output(c, name, data) |
|
|
|
|
|
filename := name + ".xlsx" |
|
|
|
|
|
r := map[string]string{ |
|
|
|
|
|
"file": file, |
|
|
|
|
|
"filename": filename, |
|
|
|
|
|
} |
|
|
|
|
|
e.OutSuc(c, r, nil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 k, v := range data { |
|
|
|
|
|
var total = 0 |
|
|
|
|
|
for kk, vv := range v { |
|
|
|
|
|
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ |
|
|
|
|
|
vv["date"], |
|
|
|
|
|
utils.Int64ToStr(kk), |
|
|
|
|
|
k, |
|
|
|
|
|
vv["goods_name"], |
|
|
|
|
|
vv["sku_str"], |
|
|
|
|
|
vv["num"], |
|
|
|
|
|
}) |
|
|
|
|
|
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{}{ |
|
|
|
|
|
k + " 汇总: " + 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 |
|
|
return |
|
|
} |
|
|
} |
|
|
func OrderEdit(c *gin.Context) { |
|
|
func OrderEdit(c *gin.Context) { |
|
|