diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index df1d01b..1ced5b5 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -87,7 +87,7 @@ func OrderExport(c *gin.Context) { list, _ := db.GetOrderListExport(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 { @@ -97,27 +97,34 @@ func OrderExport(c *gin.Context) { for _, v := range *list { enterpriseName := "-" + inSideName := "-" _, ok := enterpriseMap[v.EnterpriseId] if ok { enterpriseName = enterpriseMap[v.EnterpriseId].Name + inSideName = enterpriseMap[v.EnterpriseId].InsideName } - if data[enterpriseName] == nil { - data[enterpriseName] = make(map[int64]map[string]string) + if data[utils.IntToStr(v.EnterpriseId)] == nil { + data[utils.IntToStr(v.EnterpriseId)] = make(map[int64][]map[string]string) } - if data[enterpriseName][v.Oid] == nil { - data[enterpriseName][v.Oid] = make(map[string]string) + if data[utils.IntToStr(v.EnterpriseId)][v.Oid] == nil { + data[utils.IntToStr(v.EnterpriseId)][v.Oid] = make([]map[string]string, 0) } //TODO:: 查找 `order_goods` var orderGoods []model.OrderGoods - err := eg.Where("oid = ? and goods_type=0", v.Oid).Find(&orderGoods) + err := eg.Where("oid = ? and goods_type=?", v.Oid, 0).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 - 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["inside_name"] = inSideName + tmp["enterprise_name"] = enterpriseName + tmp["ord_no"] = vv.OrdNo + tmp["goods_type"] = utils.IntToStr(vv.GoodsType) skuData := make([]md.Sku, 0) json.Unmarshal([]byte(vv.Sku), &skuData) skuStr := "" @@ -127,8 +134,9 @@ func OrderExport(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[utils.IntToStr(v.EnterpriseId)][v.Oid] = append(data[utils.IntToStr(v.EnterpriseId)][v.Oid], tmp) } } } @@ -144,20 +152,27 @@ func OrderExport(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) - } - 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++ + for _, v3 := range vv { + if v3["ord_no"] == "" { + v3["ord_no"] = utils.Int64ToStr(kk) + } + if utils.StrToInt(v3["goods_type"]) > 0 { + v3["goods_name"] = "数量不计入汇总-" + v3["goods_name"] + } + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ + v3["date"], + v3["ord_no"], + v3["inside_name"], + v3["goods_name"], + v3["sku_str"], + v3["num"], + }) + xlsx.SetRowHeight("Sheet1", j, 18) + if utils.StrToInt(v3["goods_type"]) == 0 { + total += utils.StrToInt(v3["num"]) + } + j++ + } } style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFFCC"],"pattern":1}, "alignment":{"horizontal":"center", "vertical": "center"}}`) @@ -481,7 +496,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,15 +506,17 @@ func OrderOutput(c *gin.Context) { for _, v := range *list { enterpriseName := "-" + inSideName := "-" _, ok := enterpriseMap[v.EnterpriseId] if ok { enterpriseName = enterpriseMap[v.EnterpriseId].Name + inSideName = enterpriseMap[v.EnterpriseId].InsideName } - if data[enterpriseName] == nil { - data[enterpriseName] = make(map[int64]map[string]string) + if data[utils.IntToStr(v.EnterpriseId)] == nil { + data[utils.IntToStr(v.EnterpriseId)] = make(map[int64][]map[string]string) } - if data[enterpriseName][v.Oid] == nil { - data[enterpriseName][v.Oid] = make(map[string]string) + if data[utils.IntToStr(v.EnterpriseId)][v.Oid] == nil { + data[utils.IntToStr(v.EnterpriseId)][v.Oid] = make([]map[string]string, 0) } //TODO:: 查找 `order_goods` var orderGoods []model.OrderGoods @@ -509,10 +526,14 @@ 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["inside_name"] = inSideName + tmp["enterprise_name"] = enterpriseName + tmp["ord_no"] = vv.OrdNo + tmp["goods_type"] = utils.IntToStr(vv.GoodsType) skuData := make([]md.Sku, 0) json.Unmarshal([]byte(vv.Sku), &skuData) skuStr := "" @@ -522,8 +543,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[utils.IntToStr(v.EnterpriseId)][v.Oid] = append(data[utils.IntToStr(v.EnterpriseId)][v.Oid], tmp) } } } @@ -539,20 +561,27 @@ 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) - } - 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++ + for _, v3 := range vv { + if v3["ord_no"] == "" { + v3["ord_no"] = utils.Int64ToStr(kk) + } + if utils.StrToInt(v3["goods_type"]) > 0 { + v3["goods_name"] = "数量不计入汇总-" + v3["goods_name"] + } + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ + v3["date"], + v3["ord_no"], + v3["inside_name"], + v3["goods_name"], + v3["sku_str"], + v3["num"], + }) + xlsx.SetRowHeight("Sheet1", j, 18) + if utils.StrToInt(v3["goods_type"]) == 0 { + total += utils.StrToInt(v3["num"]) + } + j++ + } } style, err := xlsx.NewStyle(`{"fill":{"type":"pattern","color":["FFFFCC"],"pattern":1}, "alignment":{"horizontal":"center", "vertical": "center"}}`)