From 704c1f5df0951cb39757aa70aa0a390ca27928a0 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 30 Apr 2024 11:33:58 +0800 Subject: [PATCH] =?UTF-8?q?1=E5=90=8E=E5=8F=B0=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/svc/order/svc_order_list.go | 67 ++++++++++++++++++++++----- app/db/model/order_goods.go | 1 + 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index c9750bd..545d8b7 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -60,10 +60,7 @@ func OrderList(c *gin.Context) { } } state := []map[string]string{ - {"name": "待制作", "value": "0"}, {"name": "制作中", "value": "1"}, - {"name": "烘焙中", "value": "2"}, - {"name": "分拣中", "value": "3"}, {"name": "已完成", "value": "4"}, {"name": "已取消", "value": "5"}, } @@ -264,8 +261,7 @@ func OrderTotal(c *gin.Context) { for _, v := range nativeString { res = append(res, "订单总金额(元):"+v["amount"]) res = append(res, "总订单数量:"+v["alls"]) - res = append(res, "待制作订单数:"+v["wait_do"]) - res = append(res, "待烘焙订单数:"+v["dos"]) + res = append(res, "制作中订单数:"+v["dos"]) res = append(res, "已完成订单数:"+v["success"]) res = append(res, "已取消订单数:"+v["cancel"]) } @@ -634,10 +630,10 @@ func OrderEditNum(c *gin.Context) { e.OutErr(c, 400, e.NewErr(400, "订单已取消,不能修改")) return } - if order.State > 0 { - e.OutErr(c, 400, e.NewErr(400, "订单制作中,不能修改")) - return - } + //if order.State > 0 { + // e.OutErr(c, 400, e.NewErr(400, "订单制作中,不能修改")) + // return + //} sess := eg.NewSession() defer sess.Close() sess.Begin() @@ -645,6 +641,25 @@ func OrderEditNum(c *gin.Context) { orderGoods := db.GetOrderGoodsByIdSess(sess, args["id"]) isHasSku := 0 if orderGoods.SkuId != utils.StrToInt64(args["sku_id"]) { + //判断有没有的扣 + all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) + if all == nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "修改失败")) + return + } + if all.WaitMakeNum < orderGoods.Num { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) + return + } + all.WaitBakingNum -= orderGoods.Num + _, err := sess.Where("id=?", all.Id).Cols("wait_baking_num").Update(all) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "修改失败")) + return + } orderGoodsSku := db.GetOrderGoodsBySkuIdSess(sess, args["oid"], args["sku_id"]) if orderGoodsSku != nil { isHasSku = 1 @@ -664,14 +679,23 @@ func OrderEditNum(c *gin.Context) { sqlSecond = fmt.Sprintf(sqlSecond, args["num"], orderGoodsSku.GoodsId) db.QueryNativeStringSess(sess, sqlSecond) //重新计算价格 + tmp := orderGoodsSku orderGoodsSku.Num += utils.StrToInt(args["num"]) order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + utils.StrToFloat64(args["num"])*utils.StrToFloat64(orderGoodsSku.Price)) - _, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num").Update(orderGoodsSku) + orderGoodsSku.DeductMemo = args["memo"] + _, err = sess.Where("id=?", orderGoodsSku.Id).Cols("num,memo").Update(orderGoodsSku) if err != nil { sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "修改失败")) return } + tmp.Num = utils.StrToInt(args["num"]) + err = Total(sess, *tmp) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "下单失败")) + return + } } else { orderGoods.SkuId = utils.StrToInt64(args["sku_id"]) _, sku, _ := db.GetMallSkuBySkuId(eg, args["sku_id"], utils.Int64ToStr(orderGoods.GoodsId)) @@ -682,23 +706,44 @@ func OrderEditNum(c *gin.Context) { } } if isHasSku == 0 { + //判断有没有的扣 + all := db.GetOrderGoodsMakeStockAll(sess, orderGoods.GoodsId, orderGoods.SkuId) + if all == nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "修改失败")) + return + } num := utils.StrToInt(args["num"]) - orderGoods.Num if num < 0 { //少要了 就总金额 减少 + if all.WaitMakeNum < orderGoods.Num { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) + return + } num = orderGoods.Num - utils.StrToInt(args["num"]) + all.WaitBakingNum -= orderGoods.Num order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) - float64(num)*utils.StrToFloat64(orderGoods.Price)) //销量扣除 sqlSecond := `UPDATE goods SET sale=sale-%d WHERE id=%d` sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) db.QueryNativeStringSess(sess, sqlSecond) } else { + all.WaitBakingNum += orderGoods.Num order.Amount = utils.Float64ToStr(utils.StrToFloat64(order.Amount) + float64(num)*utils.StrToFloat64(orderGoods.Price)) //销量增加 sqlSecond := `UPDATE goods SET sale=sale+%d WHERE id=%d` sqlSecond = fmt.Sprintf(sqlSecond, num, orderGoods.GoodsId) db.QueryNativeStringSess(sess, sqlSecond) } + _, err := sess.Where("id=?", all.Id).Cols("wait_baking_num").Update(all) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "修改失败")) + return + } orderGoods.Num = utils.StrToInt(args["num"]) - _, err := sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku").Update(orderGoods) + orderGoods.DeductMemo = args["memo"] + _, err = sess.Where("id=?", orderGoods.Id).Cols("num,sku_code,sku_id,sku,memo").Update(orderGoods) if err != nil { sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "修改失败")) diff --git a/app/db/model/order_goods.go b/app/db/model/order_goods.go index 8779aa6..cfd27cb 100644 --- a/app/db/model/order_goods.go +++ b/app/db/model/order_goods.go @@ -12,6 +12,7 @@ type OrderGoods struct { State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 ') INT(11)"` SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"` GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"` + DeductMemo string `json:"deduct_memo" xorm:"comment('商品标题') VARCHAR(255)"` Sku string `json:"sku" xorm:"comment('规格数据') VARCHAR(1000)"` SuccessNum int `json:"success_num" xorm:"comment('完成数量') INT(11)"` Memo string `json:"memo" xorm:"comment('制作完成备注') VARCHAR(255)"`