|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/ipad/md"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func NewOrderMakeEnd(c *gin.Context) {
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- args["state"] = "2"
- args["str"] = "烘焙"
- commNewMake(c, args)
- }
- func NewOrderBakingEnd(c *gin.Context) {
- var args map[string]string
- if err := c.ShouldBindJSON(&args); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- args["state"] = "3"
- args["str"] = "烘焙"
- commNewMake(c, args)
- }
- func NewOrderSortingEnd(c *gin.Context) {
- var args md.NewOrderSorting
- 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()
- //修改制作记录
- for _, v := range args.OrderInfo {
- record := db.GetOrderGoods(sess, v["oid"], args.Gid, args.SkuId)
- 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(args.Gid), utils.StrToInt64(args.SkuId), 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
- }
- }
-
- sess.Commit()
- e.OutSuc(c, "success", nil)
- return
- }
-
- func commNewMake(c *gin.Context, args map[string]string) {
- eg := db.Db
- sess := eg.NewSession()
- defer sess.Close()
- sess.Begin()
- state := utils.StrToInt(args["state"])
- orderGoods := db.GetOrderGoodsMakeStockById(sess, utils.StrToInt64(args["id"]))
- if orderGoods == nil {
- sess.Rollback()
- e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试"))
- return
- }
- WaitMakeNum := orderGoods.WaitMakeNum
- if state == 2 { //制作完成
- if utils.StrToInt(args["num"]) > orderGoods.WaitMakeNum {
- sess.Rollback()
- e.OutErr(c, 400, e.NewErr(400, "数量只能提交"+utils.IntToStr(orderGoods.WaitMakeNum)+"个"))
- return
- }
- orderGoods.WaitMakeNum -= utils.StrToInt(args["num"])
- orderGoods.WaitBakingNum += utils.StrToInt(args["num"])
- if orderGoods.WaitMakeNum < 0 {
- orderGoods.WaitMakeNum = 0
- }
- }
- if state == 3 { //烘焙完成
- if utils.StrToInt(args["num"]) > orderGoods.WaitBakingNum {
- sess.Rollback()
- e.OutErr(c, 400, e.NewErr(400, "数量只能提交"+utils.IntToStr(orderGoods.WaitBakingNum)+"个"))
- return
- }
- WaitMakeNum = orderGoods.WaitBakingNum
- orderGoods.WaitBakingNum -= utils.StrToInt(args["num"])
- orderGoods.WaitSortingNum += utils.StrToInt(args["num"])
- if orderGoods.WaitBakingNum < 0 {
- orderGoods.WaitBakingNum = 0
- }
- }
- _, err := sess.Where("id=?", orderGoods.Id).Cols("wait_make_num,wait_baking_num,wait_sorting_num").Update(orderGoods)
- if err != nil {
- sess.Rollback()
- e.OutErr(c, 400, e.NewErr(400, "提交失败,请重试"))
- return
- }
- //写入流程记录
- var recordFlow = &model.OrderGoodsDoingFlow{
- Num: WaitMakeNum,
- State: state,
- Memo: args["memo"],
- SuccessNum: utils.StrToInt(args["num"]),
- Time: time.Now(),
- Gid: orderGoods.Gid,
- SkuId: orderGoods.SkuId,
- SkuCode: orderGoods.SkuCode,
- AdminId: utils.StrToInt(args["admin_id"]),
- GoodsTitle: orderGoods.GoodsTitle,
- Sku: orderGoods.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
- }
- sess.Commit()
- e.OutSuc(c, "success", nil)
- return
- }
|