@@ -11,7 +11,9 @@ func OrderList(c *gin.Context) { | |||||
func OrderGoodsList(c *gin.Context) { | func OrderGoodsList(c *gin.Context) { | ||||
order.OrderGoodsList(c) | order.OrderGoodsList(c) | ||||
} | } | ||||
func NewOrderGoodsList(c *gin.Context) { | |||||
order.NewOrderGoodsList(c) | |||||
} | |||||
func OrderExport(c *gin.Context) { | func OrderExport(c *gin.Context) { | ||||
order.OrderExport(c) | order.OrderExport(c) | ||||
} | } | ||||
@@ -153,6 +153,94 @@ func OrderGoodsList(c *gin.Context) { | |||||
e.OutSuc(c, res, nil) | e.OutSuc(c, res, nil) | ||||
return | return | ||||
} | } | ||||
func NewOrderGoodsList(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.GetOrderGoodsList(eg, args) | |||||
xlsx, _ := excelize.OpenFile("./static/template/综合订单品类明细表.xlsx") | |||||
data := make([]map[string]interface{}, 0) | |||||
if list != nil { | |||||
stateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} | |||||
enterpriseIds := make([]int, 0) | |||||
for _, v := range list { | |||||
enterpriseIds = append(enterpriseIds, utils.StrToInt(v["enterprise_id"])) | |||||
} | |||||
enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) | |||||
for _, v := range list { | |||||
JudgePackageOrdOrdStateSecond(v["oid"], v["state"]) | |||||
enterpriseName := "" | |||||
insideEnterpriseName := "" | |||||
_, ok := enterpriseMap[utils.StrToInt(v["enterprise_id"])] | |||||
if ok { | |||||
enterpriseName = enterpriseMap[utils.StrToInt(v["enterprise_id"])].Name | |||||
insideEnterpriseName = enterpriseMap[utils.StrToInt(v["enterprise_id"])].InsideName | |||||
} | |||||
var tmp = map[string]interface{}{ | |||||
"buy_phone": v["buy_phone"], | |||||
"ord_no": v["ord_no"], | |||||
"goods_title": v["goods_title"], | |||||
"oid": v["oid"], | |||||
"price": v["price"], | |||||
"num": v["num"], | |||||
"state_str": stateArr[utils.StrToInt(v["state"])], | |||||
"state": v["state"], | |||||
"time": gjson.Get(v["buy_info"], "time").String(), | |||||
"date": gjson.Get(v["buy_info"], "date").String(), | |||||
"create_at": v["create_at"], | |||||
"enterprise_name": enterpriseName, | |||||
"inside_name": insideEnterpriseName, | |||||
"memo": v["deduct_memo"], | |||||
"make_date": utils.TimeParseDateStd1(utils.StrToInt(v["make_date"])), | |||||
} | |||||
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 | |||||
data = append(data, 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 _, v := range data { | |||||
xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ | |||||
v["oid"], | |||||
v["enterprise_name"], | |||||
v["goods_title"], | |||||
v["inside_name"], | |||||
"¥" + utils.AnyToString(v["price"]), | |||||
v["num"], | |||||
v["state_str"], | |||||
v["ord_no"], | |||||
v["create_at"], | |||||
v["make_date"], | |||||
}) | |||||
xlsx.SetRowHeight("Sheet1", j, 18) | |||||
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 OrderExport(c *gin.Context) { | func OrderExport(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 { | ||||
@@ -157,3 +157,72 @@ func GetOrderGoodsList(eg *xorm.Engine, param map[string]string) ([]map[string]s | |||||
return nativeString1, int64(count) | return nativeString1, int64(count) | ||||
} | } | ||||
func GetOutputOrderGoodsList(eg *xorm.Engine, param map[string]string) ([]map[string]string, int64) { | |||||
where := "goods_type=0" | |||||
if param["phone"] != "" { | |||||
where += " and o.buy_phone like '%" + param["phone"] + "%'" | |||||
} | |||||
if param["oid"] != "" { | |||||
where += " and o.oid like '%" + param["oid"] + "%'" | |||||
} | |||||
if param["ord_no"] != "" { | |||||
where += " and o.ord_no like '%" + param["ord_no"] + "%'" | |||||
} | |||||
if param["goods_title"] != "" { | |||||
where += " and og.goods_title like '%" + param["goods_title"] + "%'" | |||||
} | |||||
if param["state"] != "" { | |||||
where += " and o.state =" + param["state"] | |||||
} | |||||
if param["start_at"] != "" { | |||||
where += " and o.create_at >='" + param["start_at"] + "'" | |||||
} | |||||
if param["end_at"] != "" { | |||||
where += " and o.create_at <='" + param["end_at"] + "'" | |||||
} | |||||
if param["date"] != "" { | |||||
param["date"] = strings.ReplaceAll(param["date"], "-", "") | |||||
where += " and o.date ='" + param["date"] + "'" | |||||
} | |||||
if param["make_date"] != "" { | |||||
param["make_date"] = strings.ReplaceAll(param["make_date"], "-", "") | |||||
where += " and o.make_date ='" + param["make_date"] + "'" | |||||
} | |||||
if param["enterprise_name"] != "" { | |||||
var enterprise []model.Enterprise | |||||
eg.Where("name like ?", "%"+param["enterprise_name"]+"%").Find(&enterprise) | |||||
oids := []string{"-1"} | |||||
for _, v := range enterprise { | |||||
oids = append(oids, utils.IntToStr(v.Id)) | |||||
} | |||||
where += " and o.enterprise_id in(" + php2go.Implode(",", oids) + ")" | |||||
} | |||||
if param["inside_name"] != "" { | |||||
var enterprise []model.Enterprise | |||||
eg.Where("inside_name like ?", "%"+param["inside_name"]+"%").Find(&enterprise) | |||||
oids := []string{"-1"} | |||||
for _, v := range enterprise { | |||||
oids = append(oids, utils.IntToStr(v.Id)) | |||||
} | |||||
where += " and o.enterprise_id in(" + php2go.Implode(",", oids) + ")" | |||||
} | |||||
size := utils.StrToInt(param["limit"]) | |||||
start := (utils.StrToInt(param["page"]) - 1) * size | |||||
sql := "SELECT %s FROM order_goods og left join `order` o on o.oid=og.oid where %s order by og.id asc %s" | |||||
sql1 := fmt.Sprintf(sql, "og.deduct_memo,og.oid,og.goods_id,og.sku_id,og.num,og.price,og.state,og.sku_code,og.goods_title,og.sku,og.success_num,og.memo,og.time,og.admin_id,og.enterprise_id,og.deduct_memo,og.ord_no,og.make_date,o.create_at,o.buy_info,o.buy_phone", where, "limit "+utils.IntToStr(start)+","+utils.IntToStr(size)) | |||||
sql2 := fmt.Sprintf(sql, "COUNT(*) as count", where, "") | |||||
nativeString, _ := QueryNativeString(eg, sql2) | |||||
count := 0 | |||||
for _, v := range nativeString { | |||||
count = utils.StrToInt(v["count"]) | |||||
} | |||||
nativeString1, _ := QueryNativeString(eg, sql1) | |||||
return nativeString1, int64(count) | |||||
} |
@@ -136,24 +136,26 @@ func rGoodsPay(r *gin.RouterGroup) { | |||||
r.POST("/create", orderHdl.GoodsPayCreate) //商品下单 | r.POST("/create", orderHdl.GoodsPayCreate) //商品下单 | ||||
} | } | ||||
func rOrder(r *gin.RouterGroup) { | func rOrder(r *gin.RouterGroup) { | ||||
r.POST("/list", orderHdl.OrderList) //用户订单 | |||||
r.POST("/goods/list", orderHdl.OrderGoodsList) //用户订单 | |||||
r.POST("/goods/total", orderHdl.OrderGoodsTotal) //用户订单统计 | |||||
r.POST("/total", orderHdl.OrderTotal) //用户订单统计 | |||||
r.POST("/cancel", orderHdl.OrderCancel) //用户订单取消 | |||||
r.POST("/detail", orderHdl.OrderDetail) //用户订单详情 | |||||
r.POST("/output", orderHdl.OrderOutput) //用户订单导出 | |||||
r.POST("/goods/output", orderHdl.OrderGoodsOutput) //用户订单导出 | |||||
r.POST("/del", orderHdl.OrderDel) //用户订单商品删除 | |||||
r.POST("/edit", orderHdl.OrderEdit) //用户订单修改购买人信息 | |||||
r.POST("/editNum", orderHdl.OrderEditNum) //用户订单修改订单数 | |||||
r.POST("/addSku", orderHdl.OrderAddSku) //用户订单修改订单数 | |||||
r.POST("/addNum", orderHdl.OrderAddNum) //用户订单增加数量 | |||||
r.POST("/deductNum", orderHdl.OrderDeductNum) //用户订单减少数量 | |||||
r.POST("/makeRecord", orderHdl.MarkRecord) //制作记录 | |||||
r.POST("/notice", orderHdl.NoticeList) //公告 | |||||
r.POST("/notice_save", orderHdl.NoticeSave) //公告 | |||||
r.POST("/notice_del", orderHdl.NoticeDel) //公告 | |||||
r.POST("/list", orderHdl.OrderList) //用户订单 | |||||
r.POST("/goods/list", orderHdl.OrderGoodsList) //用户订单 | |||||
r.POST("/goods/total", orderHdl.OrderGoodsTotal) //用户订单统计 | |||||
r.POST("/total", orderHdl.OrderTotal) //用户订单统计 | |||||
r.POST("/cancel", orderHdl.OrderCancel) //用户订单取消 | |||||
r.POST("/detail", orderHdl.OrderDetail) //用户订单详情 | |||||
r.POST("/output", orderHdl.OrderOutput) //用户订单导出 | |||||
r.POST("/goods/output", orderHdl.OrderGoodsOutput) //用户订单导出 | |||||
r.POST("/new_goods/output", orderHdl.NewOrderGoodsList) //用户订单 | |||||
r.POST("/del", orderHdl.OrderDel) //用户订单商品删除 | |||||
r.POST("/edit", orderHdl.OrderEdit) //用户订单修改购买人信息 | |||||
r.POST("/editNum", orderHdl.OrderEditNum) //用户订单修改订单数 | |||||
r.POST("/addSku", orderHdl.OrderAddSku) //用户订单修改订单数 | |||||
r.POST("/addNum", orderHdl.OrderAddNum) //用户订单增加数量 | |||||
r.POST("/deductNum", orderHdl.OrderDeductNum) //用户订单减少数量 | |||||
r.POST("/makeRecord", orderHdl.MarkRecord) //制作记录 | |||||
r.POST("/notice", orderHdl.NoticeList) //公告 | |||||
r.POST("/notice_save", orderHdl.NoticeSave) //公告 | |||||
r.POST("/notice_del", orderHdl.NoticeDel) //公告 | |||||
} | } | ||||
func rDataStatistics(r *gin.RouterGroup) { | func rDataStatistics(r *gin.RouterGroup) { | ||||