diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index 10d8b7b..273aaac 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -476,7 +476,7 @@ func OrderOutput(c *gin.Context) { list := db.GetOrderListOutput(eg, args) xlsx, _ := excelize.OpenFile("./static/template/商品销售明细表.xlsx") - var data = map[string]map[int64]map[string]string{} + var data = map[string]map[int64][]map[string]string{} if list != nil { enterpriseIds := make([]int, 0) for _, v := range *list { @@ -491,10 +491,10 @@ func OrderOutput(c *gin.Context) { enterpriseName = enterpriseMap[v.EnterpriseId].Name } if data[enterpriseName] == nil { - data[enterpriseName] = make(map[int64]map[string]string) + data[enterpriseName] = make(map[int64][]map[string]string) } if data[enterpriseName][v.Oid] == nil { - data[enterpriseName][v.Oid] = make(map[string]string) + data[enterpriseName][v.Oid] = make([]map[string]string, 0) } //TODO:: 查找 `order_goods` var orderGoods []model.OrderGoods @@ -504,10 +504,11 @@ func OrderOutput(c *gin.Context) { return } for _, vv := range orderGoods { - data[enterpriseName][v.Oid]["date"] = v.CreateAt.Format("2006-01-02") - data[enterpriseName][v.Oid]["send_date"] = gjson.Get(v.BuyInfo, "date").String() - data[enterpriseName][v.Oid]["goods_name"] = vv.GoodsTitle - data[enterpriseName][v.Oid]["ord_no"] = vv.OrdNo + tmp := make(map[string]string) + tmp["date"] = v.CreateAt.Format("2006-01-02") + tmp["send_date"] = gjson.Get(v.BuyInfo, "date").String() + tmp["goods_name"] = vv.GoodsTitle + tmp["ord_no"] = vv.OrdNo skuData := make([]md.Sku, 0) json.Unmarshal([]byte(vv.Sku), &skuData) skuStr := "" @@ -517,8 +518,9 @@ func OrderOutput(c *gin.Context) { } skuStr += v1.Value } - data[enterpriseName][v.Oid]["sku_str"] = skuStr - data[enterpriseName][v.Oid]["num"] = utils.IntToStr(vv.Num) + tmp["sku_str"] = skuStr + tmp["num"] = utils.IntToStr(vv.Num) + data[enterpriseName][v.Oid] = append(data[enterpriseName][v.Oid], tmp) } } } @@ -534,19 +536,22 @@ func OrderOutput(c *gin.Context) { for k, v := range data { var total = 0 for kk, vv := range v { - if vv["ord_no"] == "" { - vv["ord_no"] = utils.Int64ToStr(kk) + for _, vv1 := range vv { + if vv1["ord_no"] == "" { + vv1["ord_no"] = utils.Int64ToStr(kk) + } + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ + vv1["date"], + vv1["ord_no"], + k, + vv1["goods_name"], + vv1["sku_str"], + vv1["num"], + }) + xlsx.SetRowHeight("Sheet1", j, 18) + total += utils.StrToInt(vv1["num"]) } - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ - vv["date"], - vv["ord_no"], - k, - vv["goods_name"], - vv["sku_str"], - vv["num"], - }) - xlsx.SetRowHeight("Sheet1", j, 18) - total += utils.StrToInt(vv["num"]) + j++ }