From 653a09d1249ccc09c2813169917ea80e633520f2 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Thu, 4 Jul 2024 19:18:20 +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/ipad/hdl/hdl_order_make.go | 3 ++ app/ipad/svc/svc_order_make.go | 92 ++++++++++++++++++++++++++++++++++ app/router/ipad_router.go | 9 ++-- 3 files changed, 100 insertions(+), 4 deletions(-) diff --git a/app/ipad/hdl/hdl_order_make.go b/app/ipad/hdl/hdl_order_make.go index 1ba0ac5..3b43b2a 100644 --- a/app/ipad/hdl/hdl_order_make.go +++ b/app/ipad/hdl/hdl_order_make.go @@ -14,3 +14,6 @@ func NewOrderBakingEnd(c *gin.Context) { func NewOrderSortingEnd(c *gin.Context) { svc.NewOrderSortingEnd(c) } +func NewOrderSortingEndByOrder(c *gin.Context) { + svc.NewOrderSortingEndByOrder(c) +} diff --git a/app/ipad/svc/svc_order_make.go b/app/ipad/svc/svc_order_make.go index 255376f..30b0237 100644 --- a/app/ipad/svc/svc_order_make.go +++ b/app/ipad/svc/svc_order_make.go @@ -124,7 +124,99 @@ func NewOrderSortingEnd(c *gin.Context) { e.OutSuc(c, "success", nil) return } +func NewOrderSortingEndByOrder(c *gin.Context) { + var args md.OrderSorting + 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() + //修改制作记录 + oids := make([]string, 0) + oids = append(oids, args.Oid) + for _, v := range args.GoodsInfo { + record := db.GetOrderGoods(sess, args.Oid, v["gid"], v["sku_id"]) + if record.MakeDate > utils.StrToInt(time.Now().Format("20060102")) { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, v["oid"]+",未到制作时间,请勿提交")) + return + } + if utils.StrToInt(v["num"]) > record.Num-record.SuccessNum { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, record.GoodsTitle+",数量只能提交"+utils.IntToStr(record.Num-record.SuccessNum)+"个")) + return + } + record.SuccessNum += utils.StrToInt(v["num"]) + if record.SuccessNum >= record.Num { + record.State = 4 + } + record.AdminId = utils.StrToInt(args.AdminId) + record.Time = time.Now() + _, err := sess.Where("id=?", record.Id).Cols("success_num,state,time").Update(record) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试")) + return + } + makeRecord := db.GetOrderGoodsMakeStockByDate(sess, utils.StrToInt64(v["gid"]), utils.StrToInt64(v["sku_id"]), record.MakeDate) + if utils.StrToInt(v["num"]) > makeRecord.WaitSortingNum { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, record.GoodsTitle+",数量只能提交"+utils.IntToStr(makeRecord.WaitSortingNum)+"个")) + return + } + makeRecord.WaitSortingNum -= utils.StrToInt(v["num"]) + makeRecord.SuccessNum += utils.StrToInt(v["num"]) + _, err = sess.Where("id=?", makeRecord.Id).Cols("success_num,wait_sorting_num").Update(makeRecord) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试")) + return + } + //写入流程记录 + var recordFlow = &model.OrderGoodsDoingFlow{ + Num: record.Num, + State: 4, + Memo: "", + SuccessNum: utils.StrToInt(v["num"]), + Time: time.Now(), + Gid: record.GoodsId, + SkuId: record.SkuId, + SkuCode: record.SkuCode, + AdminId: utils.StrToInt(args.AdminId), + GoodsTitle: record.GoodsTitle, + Sku: record.Sku, + } + var admin model.Staff + sess.Where("id=?", recordFlow.AdminId).Get(&admin) + recordFlow.AdminName = admin.Name + one, err := sess.InsertOne(recordFlow) + if one == 0 || err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试")) + return + } + } + if len(oids) > 0 { + ord := db.GetOrderByIdsSess(sess, oids) + if ord != nil { + for _, v := range *ord { + err := order.JudgePackageOrdOrdStateSess(sess, &v) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "请重新提交")) + return + } + } + } + } + sess.Commit() + e.OutSuc(c, "success", nil) + return +} func commNewMake(c *gin.Context, args map[string]string) { eg := db.Db sess := eg.NewSession() diff --git a/app/router/ipad_router.go b/app/router/ipad_router.go index 7a7f32a..d53f455 100644 --- a/app/router/ipad_router.go +++ b/app/router/ipad_router.go @@ -16,9 +16,10 @@ func IpadInit(r *gin.RouterGroup) { r.POST("order/goods/list", hdl.OrderGoods) //订单商品 r.GET("responsible", hdl.Responsible) //负责人 - r.POST("order/make/end", hdl.NewOrderMakeEnd) //订单制作完成 - r.POST("order/baking/end", hdl.NewOrderBakingEnd) //订单烘焙完成 - r.POST("order/sorting/end", hdl.NewOrderSortingEnd) //订单分拣完成 - r.POST("order/goods/sorting_list", hdl.SortingOrderGoods) //订单商品 + r.POST("order/make/end", hdl.NewOrderMakeEnd) //订单制作完成 + r.POST("order/baking/end", hdl.NewOrderBakingEnd) //订单烘焙完成 + r.POST("order/sorting/end", hdl.NewOrderSortingEnd) //订单分拣完成 + r.POST("order/sorting/end/by_order", hdl.NewOrderSortingEndByOrder) //按主订单分拣完成 + r.POST("order/goods/sorting_list", hdl.SortingOrderGoods) //订单商品 }