From 733cd5045ca05935fdd0a75c35bdcafd4c399e53 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 4 Jul 2024 18:16:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/hdl/order/hdl_order_list.go | 4 ++- app/admin/svc/order/svc_order_list.go | 42 +++++++++++++++++++++++++- app/bigData/svc/svc_data.go | 2 +- app/db/db_order_goods_make_stock.go | 15 +++++---- app/db/db_order_list.go | 12 ++++++++ app/db/model/order_goods_make_stock.go | 1 + app/router/admin_router.go | 1 + 7 files changed, 68 insertions(+), 9 deletions(-) diff --git a/app/admin/hdl/order/hdl_order_list.go b/app/admin/hdl/order/hdl_order_list.go index 3e517e5..711935d 100644 --- a/app/admin/hdl/order/hdl_order_list.go +++ b/app/admin/hdl/order/hdl_order_list.go @@ -27,7 +27,9 @@ func OrderGoodsTotal(c *gin.Context) { func OrderCancel(c *gin.Context) { order.OrderCancel(c) } - +func OrderUpdateState(c *gin.Context) { + order.OrderUpdateState(c) +} func OrderDetail(c *gin.Context) { order.OrderDetail(c) } diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index 52f2bdf..94cc125 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -752,7 +752,46 @@ func OrderCancel(c *gin.Context) { e.OutSuc(c, "success", nil) return } - +func OrderUpdateState(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 + sess := eg.NewSession() + defer sess.Close() + sess.Begin() + order := db.GetOrderByMore(sess, args) + if order == nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单不存在")) + return + } + sess1 := sess.Where("state!=5") + if args["ids"] != "" { + sess1.In("oid", strings.Split(args["ids"], ",")) + } + _, err := sess1.Cols("state").Update(&model.Order{State: 4}) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "操作失败")) + return + } + sess2 := sess.Where("state!=5") + if args["ids"] != "" { + sess2.In("oid", strings.Split(args["ids"], ",")) + } + _, err = sess2.Cols("state").Update(&model.OrderGoods{State: 4}) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "操作失败")) + return + } + sess.Commit() + e.OutSuc(c, "success", nil) + return +} func OrderDetail(c *gin.Context) { var args map[string]string if err := c.ShouldBindJSON(&args); err != nil { @@ -1373,6 +1412,7 @@ func OrderEditNum(c *gin.Context) { Sku: skuStr, GoodsType: 0, MakeDate: orderGoods.MakeDate, + CreateTime: int(time.Now().Unix()), } sess.Insert(tmp) } diff --git a/app/bigData/svc/svc_data.go b/app/bigData/svc/svc_data.go index 024931f..5d85f41 100644 --- a/app/bigData/svc/svc_data.go +++ b/app/bigData/svc/svc_data.go @@ -585,7 +585,7 @@ func NewSortingGoodsData(arg map[string]string) []map[string]string { } oIds = append(oIds, utils.Int64ToStr(v.Oid)) } - sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id,enterprise_id FROM order_goods WHERE oid in (%s) and goods_id=%s and goods_type=0 and sku_id=%s and make_date=%s GROUP BY enterprise_id` + sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id,enterprise_id FROM order_goods WHERE oid in (%s) and goods_id=%s and goods_type=0 and sku_id=%s and make_date=%s GROUP BY enterprise_id ORDER BY id asc` sql = fmt.Sprintf(sql, strings.Join(oIds, ","), arg["goods_id"], arg["sku_id"], now) nativeString, err := db.QueryNativeString(engine, sql) for _, v := range nativeString { diff --git a/app/db/db_order_goods_make_stock.go b/app/db/db_order_goods_make_stock.go index 45cbb3e..607ecb4 100644 --- a/app/db/db_order_goods_make_stock.go +++ b/app/db/db_order_goods_make_stock.go @@ -3,6 +3,7 @@ package db import ( "applet/app/db/model" "applet/app/utils" + "time" "xorm.io/xorm" ) @@ -67,7 +68,7 @@ func GetOrderGoodsMakeStockByBigData(eg *xorm.Engine, param map[string]string) ( } sess.In("gid", gids) sess.In("sku_id", skuids) - count, err := sess.OrderBy("id asc").FindAndCount(&order) + count, err := sess.OrderBy("create_time asc,id asc").FindAndCount(&order) if err != nil { return nil, count } @@ -82,8 +83,9 @@ func GetOrderGoodsMakeStock(sess *xorm.Session, gid, skuId int64) *model.OrderGo } if get == false { data = model.OrderGoodsMakeStock{ - Gid: gid, - SkuId: skuId, + Gid: gid, + SkuId: skuId, + CreateTime: int(time.Now().Unix()), } insert, err := sess.Insert(&data) if insert == 0 || err != nil { @@ -126,9 +128,10 @@ func GetOrderGoodsMakeStockByDate(sess *xorm.Session, gid, skuId int64, date int } if get == false { data = model.OrderGoodsMakeStock{ - Gid: gid, - SkuId: skuId, - MakeDate: date, + Gid: gid, + SkuId: skuId, + MakeDate: date, + CreateTime: int(time.Now().Unix()), } insert, err := sess.Insert(&data) if insert == 0 || err != nil { diff --git a/app/db/db_order_list.go b/app/db/db_order_list.go index 4cea6f9..3392562 100644 --- a/app/db/db_order_list.go +++ b/app/db/db_order_list.go @@ -16,6 +16,18 @@ func GetOrderById(eg *xorm.Engine, id string) *model.Order { } return &order } +func GetOrderByMore(sess *xorm.Session, args map[string]string) *[]model.Order { + var order []model.Order + sess1 := sess.Where("state!=5") + if args["ids"] != "" { + sess1.In("oid", strings.Split(args["ids"], ",")) + } + err := sess1.Find(&order) + if err != nil { + return nil + } + return &order +} func GetOrderByIds(eg *xorm.Engine, id []string) *[]model.Order { var order []model.Order err := eg.In("oid", id).Find(&order) diff --git a/app/db/model/order_goods_make_stock.go b/app/db/model/order_goods_make_stock.go index 2cbfa65..73837e9 100644 --- a/app/db/model/order_goods_make_stock.go +++ b/app/db/model/order_goods_make_stock.go @@ -13,4 +13,5 @@ type OrderGoodsMakeStock struct { SuccessNum int `json:"success_num" xorm:"default 0 comment('已分拣') INT(11)"` GoodsType int `json:"goods_type" xorm:"default 0 comment('') INT(11)"` MakeDate int `json:"make_date" xorm:"comment('') default 0 INT(11)"` + CreateTime int `json:"create_time" xorm:"comment('') default 0 INT(11)"` } diff --git a/app/router/admin_router.go b/app/router/admin_router.go index ac88a12..cf68c4d 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -141,6 +141,7 @@ func rOrder(r *gin.RouterGroup) { r.POST("/goods/total", orderHdl.OrderGoodsTotal) //用户订单统计 r.POST("/total", orderHdl.OrderTotal) //用户订单统计 r.POST("/cancel", orderHdl.OrderCancel) //用户订单取消 + r.POST("/update/state", orderHdl.OrderUpdateState) //修改状态 r.POST("/detail", orderHdl.OrderDetail) //用户订单详情 r.POST("/output", orderHdl.OrderOutput) //用户订单导出 r.POST("/goods/output", orderHdl.OrderGoodsOutput) //用户订单导出