|
|
@@ -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 |
|
|
|