From 2b6a75727012ee4212dabb1312c11631cc081644 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 17 Jun 2024 09:16:53 +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/svc/order/svc_order_list.go | 70 +++++++++++++++++++++++++-- app/db/db_sku.go | 2 +- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index 6009324..73177e1 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -1196,20 +1196,63 @@ func OrderEditNum(c *gin.Context) { e.OutErr(c, 400, e.NewErr(400, "修改失败")) return } - if all.WaitMakeNum < orderGoods.Num { + newNum := orderGoods.Num + num := orderGoods.Num + WaitMakeNum := 0 + if all.WaitMakeNum > 0 { + leave := all.WaitMakeNum - num + deNum := num + if leave < 0 { + deNum = all.WaitMakeNum + } + all.WaitMakeNum -= deNum + newNum -= deNum + WaitMakeNum = deNum + + } + if newNum > 0 && all.WaitSortingNum > 0 { + leave := all.WaitSortingNum - num + deNum := num + if leave < 0 { + deNum = all.WaitSortingNum + } + newNum -= deNum + all.WaitSortingNum -= deNum + } + WaitBakingNum := 0 + if newNum > 0 && all.WaitBakingNum > 0 { + leave := all.WaitBakingNum - num + deNum := num + if leave < 0 { + deNum = all.WaitBakingNum + } + newNum -= deNum + all.WaitBakingNum -= deNum + WaitBakingNum = deNum + } + fmt.Println(WaitMakeNum) + fmt.Println(WaitBakingNum) + if newNum > 0 { sess.Rollback() - e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) + e.OutErr(c, 400, e.NewErr(400, "数量不足,减少数量失败")) return } - all.WaitMakeNum -= orderGoods.Num - _, err := sess.Where("id=?", all.Id).Cols("wait_make_num").Update(all) + _, err := sess.Where("id=?", all.Id).Cols("wait_make_num,wait_sorting_num,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"]) + var goodsId int64 = 0 + var skuId int64 = 0 + code := "" + skuStr := "" if orderGoodsSku != nil { + skuId = orderGoodsSku.SkuId + goodsId = orderGoodsSku.GoodsId + code = orderGoodsSku.SkuCode + skuStr = orderGoodsSku.Sku isHasSku = 1 //先删掉修改的 ,然后改另外的sku i, err := sess.Where("id=?", args["id"]).Delete(&model.OrderGoods{}) @@ -1258,7 +1301,26 @@ func OrderEditNum(c *gin.Context) { if sku != nil { orderGoods.SkuCode = sku.SkuCode orderGoods.Sku = sku.Sku + orderGoods.SkuCode = sku.SkuCode + code = sku.SkuCode + skuStr = sku.Sku + } + skuId = orderGoods.SkuId + goodsId = sku.GoodsId + } + all1 := db.GetOrderGoodsMakeStockAllByDate(sess, goodsId, skuId, 0, orderGoods.MakeDate) + if all1 == nil { + var tmp = &model.OrderGoodsMakeStock{ + Gid: goodsId, + SkuId: skuId, + SkuCode: code, + GoodsTitle: orderGoods.GoodsTitle, + Sku: skuStr, + WaitMakeNum: utils.StrToInt(args["num"]), + GoodsType: 0, + MakeDate: orderGoods.MakeDate, } + sess.Insert(tmp) } } if isHasSku == 0 { diff --git a/app/db/db_sku.go b/app/db/db_sku.go index 5ae1d23..7e14fda 100644 --- a/app/db/db_sku.go +++ b/app/db/db_sku.go @@ -24,7 +24,7 @@ func GetMallSkuBySkuCode(engine *xorm.Engine, skuCode, goodsId string) (isHas bo func GetMallSkuBySkuId(engine *xorm.Engine, skuId, goodsId string) (isHas bool, mm *model.Sku, err error) { isHas = false var m model.Sku - isHas, err = engine.Where("sku_id=?", skuId).And("goods_id!=?", goodsId).Get(&m) + isHas, err = engine.Where("sku_id=?", skuId).And("goods_id=?", goodsId).Get(&m) if err != nil { return isHas, &m, err }