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