diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index b970876..daff1f6 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -9,6 +9,7 @@ import ( "applet/app/utils" "applet/app/utils/logx" "encoding/json" + "errors" "fmt" "github.com/360EntSecGroup-Skylar/excelize" "github.com/gin-gonic/gin" @@ -428,6 +429,62 @@ func JudgePackageOrdOrdState(ord *model.Order) *model.Order { } return ord } +func JudgePackageOrdOrdStateSess(sess *xorm.Session, ord *model.Order) error { + if ord.State == 5 { + return nil + } + var ordState, oldOrdState int + oldOrdState = ord.State + ordState = oldOrdState + //全部订单 + countAll, err := sess.Where("oid =? and goods_type=?", ord.Oid, 0).Count(&model.OrderGoods{}) + if err != nil { + return err + } + //1、判断是否有 `制作中` 有一个就是制作中 + count1, err := sess.Where("oid =?", ord.Oid).And("state =? and goods_type=?", 1, 0).Count(&model.OrderGoods{}) + if err != nil { + return err + } + if count1 > 0 { + ordState = 1 + } + //3、判断是否有 `烘焙中` 要全部制作完成 + count2, err := sess.Where("oid =?", ord.Oid).And("state =? and goods_type=0", 2).Count(&model.OrderGoods{}) + if err != nil { + return err + } + if count2 > 0 && count2 == countAll { + ordState = 2 + } + //3、判断是否有 `分拣中` 要全部烘焙完成 + count3, err := sess.Where("oid =?", ord.Oid).And("state =? and goods_type=0", 3).Count(&model.OrderGoods{}) + if err != nil { + return err + } + if count3 > 0 && count3 == countAll { + ordState = 3 + } + //4、判断是否有 `已完成` 要全部已完成 + count4, err := sess.Where("oid =?", ord.Oid).And("state =? and goods_type=?", 4, 0).Count(&model.OrderGoods{}) + if err != nil { + return err + } + if count4 > 0 && count4 == countAll { + ordState = 4 + } + if ordState != oldOrdState { + ord.State = ordState + has, err2 := sess.Where("oid=?", ord.Oid).Cols("state").Update(ord) + if has == 0 { + return errors.New("失败") + } + if err2 != nil { + return err + } + } + return nil +} func JudgePackageOrdOrdStateSecond(oid, state string) string { if state == "5" { return state diff --git a/app/db/db_order_list.go b/app/db/db_order_list.go index 31f19ee..4cea6f9 100644 --- a/app/db/db_order_list.go +++ b/app/db/db_order_list.go @@ -24,6 +24,14 @@ func GetOrderByIds(eg *xorm.Engine, id []string) *[]model.Order { } return &order } +func GetOrderByIdsSess(sess *xorm.Session, id []string) *[]model.Order { + var order []model.Order + err := sess.In("oid", id).Find(&order) + if err != nil { + return nil + } + return &order +} func GetOrderByIdSess(sess *xorm.Session, id string) *model.Order { var order model.Order get, err := sess.Where("oid=?", id).Get(&order) diff --git a/app/ipad/svc/svc_order_make.go b/app/ipad/svc/svc_order_make.go index 9514d1a..255376f 100644 --- a/app/ipad/svc/svc_order_make.go +++ b/app/ipad/svc/svc_order_make.go @@ -106,15 +106,21 @@ func NewOrderSortingEnd(c *gin.Context) { return } } - sess.Commit() if len(oids) > 0 { - ord := db.GetOrderByIds(eg, oids) + ord := db.GetOrderByIdsSess(sess, oids) if ord != nil { for _, v := range *ord { - order.JudgePackageOrdOrdState(&v) + 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 }