diff --git a/app/admin/svc/order/svc_order_pay.go b/app/admin/svc/order/svc_order_pay.go index 5a10ec1..14a0bbc 100644 --- a/app/admin/svc/order/svc_order_pay.go +++ b/app/admin/svc/order/svc_order_pay.go @@ -6,10 +6,13 @@ import ( "applet/app/db" "applet/app/db/model" "applet/app/e" + "applet/app/svc" "applet/app/utils" + "errors" "fmt" "github.com/gin-gonic/gin" "time" + "xorm.io/xorm" ) func GoodsPayCalcAmount(c *gin.Context) { @@ -39,7 +42,7 @@ func GoodsPayCreate(c *gin.Context) { sess := db.Db.NewSession() defer sess.Close() sess.Begin() - sess.Commit() + var order = model.Order{ Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(req.EnterpriseId))), CreateAt: time.Now(), @@ -79,6 +82,12 @@ func GoodsPayCreate(c *gin.Context) { } goodsTotal[tmp.GoodsId] += tmp.Num orderGoods = append(orderGoods, tmp) + err = Total(sess, tmp) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "下单失败")) + return + } } for k, v := range goodsTotal { sql := `UPDATE goods SET sale=sale-%d WHERE goods_id=%d` @@ -91,6 +100,8 @@ func GoodsPayCreate(c *gin.Context) { e.OutErr(c, 400, e.NewErr(400, "下单失败")) return } + sess.Commit() + svc.SysCfgSet(c, "has_new_order", "1", "") e.OutSuc(c, "success", nil) return } @@ -128,3 +139,20 @@ func commCalc(c *gin.Context, req md.GoodsPayParam) (float64, map[string]string) return amount, skuPrice } + +// 统计数量 +func Total(sess *xorm.Session, tmp model.OrderGoods) error { + stock := db.GetOrderGoodsMakeStock(sess, tmp.GoodsId, tmp.SkuId) + if stock == nil { + return errors.New("下单失败") + } + stock.Sku = tmp.Sku + stock.SkuCode = tmp.SkuCode + stock.GoodsTitle = tmp.GoodsTitle + stock.WaitMakeNum += tmp.Num + update, err := sess.Where("id=?", stock.Id).Cols("sku,sku_code,goods_title,wait_make_num").Update(stock) + if update == 0 || err != nil { + return errors.New("下单失败") + } + return nil +} diff --git a/app/bigData/hdl/hdl_making_data.go b/app/bigData/hdl/hdl_making_data.go new file mode 100644 index 0000000..afda718 --- /dev/null +++ b/app/bigData/hdl/hdl_making_data.go @@ -0,0 +1,43 @@ +package hdl + +import ( + "applet/app/bigData/svc" + "applet/app/db" + "applet/app/e" + "github.com/gin-gonic/gin" +) + +func MakingData(c *gin.Context) { + args := map[string]string{ + "state": "1", + } + svc.CommMakingData(c, args) +} +func BakingData(c *gin.Context) { + args := map[string]string{ + "state": "2", + } + svc.CommMakingData(c, args) +} +func SortingData(c *gin.Context) { + result, err := svc.LeftDataForSorting() + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, result, nil) + return +} +func NewOrderNotice(c *gin.Context) { + sysCfgDb := db.SysCfgDb{} + sysCfgDb.Set() + cfg, _ := sysCfgDb.SysCfgGetOne("has_new_order") + res := map[string]string{ + "has_new_order": "0", + } + if cfg != nil { + res["has_new_order"] = cfg.Val + } + e.OutSuc(c, res, nil) + return +} diff --git a/app/bigData/svc/svc_data.go b/app/bigData/svc/svc_data.go index e11ecd1..8462708 100644 --- a/app/bigData/svc/svc_data.go +++ b/app/bigData/svc/svc_data.go @@ -200,9 +200,6 @@ func LeftDataForBaking() (resp []md.LeftDataForMakeResp, err error) { } func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { - now := time.Now() - startDate := now.Format("2006-01-02") + " 00:00:00" - endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00" engine := db.Db var enterprise []model.Enterprise err = engine.Where("1=1").Find(&enterprise) @@ -214,9 +211,9 @@ func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { enterpriseMap[v.Id] = v } - //1、查找当天的 order 数据(大于 待制作) + //1、查找不等于4 5 var orders []model.Order - err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 2).Find(&orders) + err = engine.Where(" state != 4 and state != 5").Find(&orders) if err != nil { return } @@ -241,23 +238,12 @@ func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { records = append(records, v.Id) } - //3、用户订单商品操作流程 - var orderGoodsDoingFlows []model.OrderGoodsDoingFlow - err = engine.Where("state = 2").In("record_id", records).Find(&orderGoodsDoingFlows) - if err != nil { - return - } - var orderGoodsDoingFlowsMap = map[int]model.OrderGoodsDoingFlow{} - for _, v := range orderGoodsDoingFlows { - orderGoodsDoingFlowsMap[v.RecordId] = v - } - //4、整合数据 - orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} + orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"} for _, v := range orders { var list []md.LeftDataForMakeList if len(orderGoodsMap[v.Oid]) > 0 { - orderGoodsStateArr := []string{"待制作", "制作中", "烘焙中", "分拣中", "已完成"} + orderGoodsStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成"} for _, vv := range orderGoodsMap[v.Oid] { skuData := make([]md2.Sku, 0) json.Unmarshal([]byte(vv.Sku), &skuData) @@ -273,12 +259,11 @@ func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) { GoodsName: vv.GoodsTitle, Sku: skuStr, Num: vv.Num, - SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum, + SuccessNum: vv.SuccessNum, StateZh: stateZh, State: vv.State, }) } - resp = append(resp, md.LeftDataForMakeResp{ EnterpriseName: enterpriseMap[v.EnterpriseId].Name, EnterpriseId: v.EnterpriseId, diff --git a/app/bigData/svc/svc_making_data.go b/app/bigData/svc/svc_making_data.go new file mode 100644 index 0000000..d5130d6 --- /dev/null +++ b/app/bigData/svc/svc_making_data.go @@ -0,0 +1,54 @@ +package svc + +import ( + "applet/app/admin/md" + "applet/app/db" + "applet/app/e" + "applet/app/utils" + "encoding/json" + "github.com/gin-gonic/gin" +) + +func CommMakingData(c *gin.Context, args map[string]string) { + eg := db.Db + data, _ := db.GetOrderGoodsMakeStockByBigData(eg, args) + list := make([]map[string]string, 0) + if data != nil { + for _, v := range *data { + var tmp = map[string]string{ + "num": "", + "state_str": "", + "goods_title": v.GoodsTitle, + "state": "", + } + if args["state"] == "1" { + tmp["num"] = utils.IntToStr(v.WaitMakeNum) + tmp["state_str"] = "制作中" + tmp["state"] = "1" + } + if args["state"] == "2" { + tmp["num"] = utils.IntToStr(v.WaitBakingNum) + tmp["state_str"] = "烘焙中" + tmp["state"] = "2" + } + if args["state"] == "3" { + tmp["num"] = utils.IntToStr(v.WaitSortingNum) + tmp["state_str"] = "分拣中" + tmp["state"] = "3" + } + skuData := make([]md.Sku, 0) + json.Unmarshal([]byte(v.Sku), &skuData) + skuStr := "" + for _, v1 := range skuData { + if skuStr != "" { + skuStr += ";" + } + skuStr += v1.Value + } + tmp["sku_str"] = skuStr + list = append(list, tmp) + } + } + e.OutSuc(c, list, nil) + return +} diff --git a/app/db/db_order_goods_list.go b/app/db/db_order_goods_list.go index b2cc48c..a34c85b 100644 --- a/app/db/db_order_goods_list.go +++ b/app/db/db_order_goods_list.go @@ -13,6 +13,12 @@ func GetOrderGoodsListByIpad(eg *xorm.Engine, param map[string]string) (*[]model if param["oid"] != "" { sess.And("oid = ?", param["oid"]) } + if param["gid"] != "" { + sess.And("goods_id = ?", param["gid"]) + } + if param["sku_id"] != "" { + sess.And("sku_id = ?", param["sku_id"]) + } if param["state"] != "" { sess.And("state =?", param["state"]) } @@ -43,3 +49,11 @@ func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods { } return &order } +func GetOrderGoods(sess *xorm.Session, oid, gid, skuId string) *model.OrderGoods { + var data model.OrderGoods + get, err := sess.Where("oid=? and goods_id=? and sku_id=?", oid, gid, skuId).Get(&data) + if err != nil || get == false { + return nil + } + return &data +} diff --git a/app/db/db_order_goods_make_stock.go b/app/db/db_order_goods_make_stock.go new file mode 100644 index 0000000..86cacc5 --- /dev/null +++ b/app/db/db_order_goods_make_stock.go @@ -0,0 +1,73 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils" + "xorm.io/xorm" +) + +func GetOrderGoodsMakeStockByIpad(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) { + var order []model.OrderGoodsMakeStock + sess := eg.Where("1=1") + + if param["state"] == "1" { + sess.And("wait_make_num >0") + } + if param["state"] == "2" { + sess.And("wait_baking_num >0") + } + if param["state"] == "3" { + sess.And("wait_sorting_num >0") + } + if param["keyword"] != "" { + sess.And("goods_title like ?", "%"+param["keyword"]+"%") + } + size := utils.StrToInt(param["limit"]) + start := (utils.StrToInt(param["page"]) - 1) * size + count, err := sess.Limit(size, start).OrderBy("id asc").FindAndCount(&order) + if err != nil { + return nil, count + } + return &order, count +} +func GetOrderGoodsMakeStockByBigData(eg *xorm.Engine, param map[string]string) (*[]model.OrderGoodsMakeStock, int64) { + var order []model.OrderGoodsMakeStock + sess := eg.Where("1=1") + + if param["state"] == "1" { + sess.And("wait_make_num >0") + } + if param["state"] == "2" { + sess.And("wait_baking_num >0") + } + if param["state"] == "3" { + sess.And("wait_sorting_num >0") + } + if param["keyword"] != "" { + sess.And("goods_title like ?", "%"+param["keyword"]+"%") + } + count, err := sess.OrderBy("id asc").FindAndCount(&order) + if err != nil { + return nil, count + } + return &order, count +} + +func GetOrderGoodsMakeStock(sess *xorm.Session, gid, skuId int64) *model.OrderGoodsMakeStock { + var data model.OrderGoodsMakeStock + get, err := sess.Where("gid=? and sku_id=?", gid, skuId).Get(&data) + if err != nil { + return nil + } + if get == false { + data = model.OrderGoodsMakeStock{ + Gid: gid, + SkuId: skuId, + } + insert, err := sess.Insert(&data) + if insert == 0 || err != nil { + return nil + } + } + return &data +} diff --git a/app/db/model/order.go b/app/db/model/order.go index e904a5c..1c2e460 100644 --- a/app/db/model/order.go +++ b/app/db/model/order.go @@ -5,13 +5,14 @@ import ( ) type Order struct { - Id int `json:"id" xorm:"not null pk autoincr INT(11)"` - Oid int64 `json:"oid" xorm:"comment('订单号') BIGINT(20)"` - State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 5已取消') INT(11)"` - CreateAt time.Time `json:"create_at" xorm:"comment('下单时间') DATETIME"` - CancelAt time.Time `json:"cancel_at" xorm:"comment('取消时间') DATETIME"` - EnterpriseId int `json:"enterprise_id" xorm:"default 0 comment('校企id') INT(11)"` - BuyInfo string `json:"buy_info" xorm:"comment('购买人信息 json') VARCHAR(2000)"` - Amount string `json:"amount" xorm:"default 0.00 comment('付款金额') DECIMAL(20,2)"` - BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机') VARCHAR(20)"` + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Oid int64 `json:"oid" xorm:"comment('订单号') BIGINT(20)"` + State int `json:"state" xorm:"default 0 comment('状态 0待制作 1制作中 2烘焙中 3分拣中 4已完成 5已取消') INT(11)"` + CreateAt time.Time `json:"create_at" xorm:"comment('下单时间') DATETIME"` + CancelAt time.Time `json:"cancel_at" xorm:"comment('取消时间') DATETIME"` + EnterpriseId int `json:"enterprise_id" xorm:"default 0 comment('校企id') INT(11)"` + BuyInfo string `json:"buy_info" xorm:"comment('购买人信息 json') VARCHAR(2000)"` + Amount string `json:"amount" xorm:"default 0.00 comment('付款金额') DECIMAL(20,2)"` + BuyPhone string `json:"buy_phone" xorm:"comment('购买人手机') VARCHAR(20)"` + EnterpriseName string `json:"enterprise_name" xorm:"comment('校企名称') VARCHAR(20)"` } diff --git a/app/db/model/order_goods_make_stock.go b/app/db/model/order_goods_make_stock.go new file mode 100644 index 0000000..9e707aa --- /dev/null +++ b/app/db/model/order_goods_make_stock.go @@ -0,0 +1,14 @@ +package model + +type OrderGoodsMakeStock struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + Gid int64 `json:"gid" xorm:"BIGINT(20)"` + SkuId int64 `json:"sku_id" xorm:"BIGINT(20)"` + SkuCode string `json:"sku_code" xorm:"VARCHAR(255)"` + GoodsTitle string `json:"goods_title" xorm:"comment('商品标题') VARCHAR(255)"` + Sku string `json:"sku" xorm:"comment('规格数据') VARCHAR(1000)"` + WaitMakeNum int `json:"wait_make_num" xorm:"default 0 comment('待制作') INT(11)"` + WaitBakingNum int `json:"wait_baking_num" xorm:"comment('待烘焙') INT(11)"` + WaitSortingNum int `json:"wait_sorting_num" xorm:"default 0 comment('待分拣') INT(11)"` + SuccessNum int `json:"success_num" xorm:"default 0 comment('已分拣') INT(11)"` +} diff --git a/app/ipad/hdl/hdl_order.go b/app/ipad/hdl/hdl_order.go index 0374e79..b337f69 100644 --- a/app/ipad/hdl/hdl_order.go +++ b/app/ipad/hdl/hdl_order.go @@ -8,11 +8,10 @@ import ( func OrderCate(c *gin.Context) { var res = []map[string]string{ - {"name": "全部", "id": ""}, - {"name": "待制作", "id": "0"}, + {"name": "全部订单", "id": ""}, {"name": "制作中", "id": "1"}, - {"name": "待分拣", "id": "3"}, - {"name": "已完成", "id": "4"}, + {"name": "烘焙中", "id": "2"}, + {"name": "分拣中", "id": "3"}, } e.OutSuc(c, res, nil) return @@ -20,3 +19,6 @@ func OrderCate(c *gin.Context) { func Order(c *gin.Context) { svc.Order(c) } +func StateOrder(c *gin.Context) { + svc.StateOrder(c) +} diff --git a/app/ipad/hdl/hdl_order_goods.go b/app/ipad/hdl/hdl_order_goods.go index a43389e..326f390 100644 --- a/app/ipad/hdl/hdl_order_goods.go +++ b/app/ipad/hdl/hdl_order_goods.go @@ -45,6 +45,7 @@ func OrderGoods(c *gin.Context) { "oid": utils.Int64ToStr(v.Oid), "id": utils.IntToStr(v.Id), "num": utils.IntToStr(v.Num), + "success_num": utils.IntToStr(v.SuccessNum), "state_str": stateArr[v.State], "btn_str": btnArr[v.State], "goods_title": v.GoodsTitle, @@ -79,3 +80,43 @@ func OrderGoods(c *gin.Context) { e.OutSuc(c, list, nil) return } +func SortingOrderGoods(c *gin.Context) { + var args map[string]string + if err := c.ShouldBindJSON(&args); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + eg := db.Db + data, _ := db.GetOrderGoodsListByIpad(eg, args) + list := make([]map[string]string, 0) + if data != nil { + enterpriseIds := make([]int, 0) + for _, v := range *data { + enterpriseIds = append(enterpriseIds, v.EnterpriseId) + } + enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds) + gids := make([]int64, 0) + for _, v := range *data { + gids = append(gids, v.GoodsId) + } + for _, v := range *data { + enterpriseName := "" + _, ok := enterpriseMap[v.EnterpriseId] + if ok { + enterpriseName = enterpriseMap[v.EnterpriseId].Name + } + var tmp = map[string]string{ + "oid": utils.Int64ToStr(v.Oid), + "id": utils.IntToStr(v.Id), + "num": utils.IntToStr(v.Num), + "success_num": utils.IntToStr(v.SuccessNum), + "need_num": utils.IntToStr(v.Num - v.SuccessNum), + "enterprise_name": enterpriseName, + } + list = append(list, tmp) + } + } + + e.OutSuc(c, list, nil) + return +} diff --git a/app/ipad/hdl/hdl_order_make.go b/app/ipad/hdl/hdl_order_make.go index 4a6ae21..d386f45 100644 --- a/app/ipad/hdl/hdl_order_make.go +++ b/app/ipad/hdl/hdl_order_make.go @@ -17,3 +17,12 @@ func OrderBakingEnd(c *gin.Context) { func OrderSortingEnd(c *gin.Context) { svc.OrderSortingEnd(c) } +func NewOrderMakeEnd(c *gin.Context) { + svc.NewOrderMakeEnd(c) +} +func NewOrderBakingEnd(c *gin.Context) { + svc.NewOrderBakingEnd(c) +} +func NewOrderSortingEnd(c *gin.Context) { + svc.NewOrderSortingEnd(c) +} diff --git a/app/ipad/md/md_order.go b/app/ipad/md/md_order.go index 16f2d52..4ab441f 100644 --- a/app/ipad/md/md_order.go +++ b/app/ipad/md/md_order.go @@ -5,3 +5,9 @@ type OrderSorting struct { AdminId string `json:"admin_id"` GoodsInfo []map[string]string `json:"goods_info"` } +type NewOrderSorting struct { + Gid string `json:"gid"` + SkuId string `json:"sku_id"` + AdminId string `json:"admin_id"` + OrderInfo []map[string]string `json:"order_info"` +} diff --git a/app/ipad/svc/svc_order.go b/app/ipad/svc/svc_order.go index 38c33c5..f6ca1d0 100644 --- a/app/ipad/svc/svc_order.go +++ b/app/ipad/svc/svc_order.go @@ -1,9 +1,12 @@ package svc import ( + "applet/app/admin/md" "applet/app/db" "applet/app/e" + "applet/app/svc" "applet/app/utils" + "encoding/json" "github.com/gin-gonic/gin" ) @@ -45,3 +48,78 @@ func Order(c *gin.Context) { e.OutSuc(c, list, nil) return } + +func StateOrder(c *gin.Context) { + var args map[string]string + if err := c.ShouldBindJSON(&args); err != nil { + e.OutErr(c, e.ERR_INVALID_ARGS, err) + return + } + eg := db.Db + data, _ := db.GetOrderGoodsMakeStockByIpad(eg, args) + list := make([]map[string]string, 0) + if data != nil { + gids := make([]int64, 0) + for _, v := range *data { + gids = append(gids, v.Gid) + } + goodsMap := db.GetGoodsMore(eg, gids) + scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c) + var tmpMap interface{} + for _, v := range *data { + var tmp = map[string]string{ + "id": utils.IntToStr(v.Id), + "gid": utils.Int64ToStr(v.Gid), + "sku_id": utils.Int64ToStr(v.SkuId), + "num": "", + "state_str": "", + "btn_str": "", + "goods_title": v.GoodsTitle, + "goods_img": "", + "state": "", + } + if args["state"] == "1" { + tmp["num"] = utils.IntToStr(v.WaitMakeNum) + tmp["state_str"] = "制作中" + tmp["btn_str"] = "制作完成" + tmp["state"] = "1" + } + if args["state"] == "2" { + tmp["num"] = utils.IntToStr(v.WaitBakingNum) + tmp["state_str"] = "烘焙中" + tmp["btn_str"] = "烘焙完成" + tmp["state"] = "2" + } + if args["state"] == "3" { + tmp["num"] = utils.IntToStr(v.WaitSortingNum) + tmp["state_str"] = "分拣中" + tmp["btn_str"] = "分拣完成" + tmp["state"] = "3" + } + // 商品主图 + if goodsMap[v.Gid].ImageList != "" { + utils.Unserialize([]byte(goodsMap[v.Gid].ImageList), &tmpMap) + var imageListUrlTmp []string + for _, v := range tmpMap.([]interface{}) { + imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string))) + } + if imageListUrlTmp != nil { + tmp["goods_img"] = imageListUrlTmp[0] + } + } + skuData := make([]md.Sku, 0) + json.Unmarshal([]byte(v.Sku), &skuData) + skuStr := "" + for _, v1 := range skuData { + if skuStr != "" { + skuStr += ";" + } + skuStr += v1.Value + } + tmp["sku_str"] = skuStr + list = append(list, tmp) + } + } + e.OutSuc(c, list, nil) + return +} diff --git a/app/ipad/svc/svc_order_make.go b/app/ipad/svc/svc_order_make.go index 9f109b9..70ea5ce 100644 --- a/app/ipad/svc/svc_order_make.go +++ b/app/ipad/svc/svc_order_make.go @@ -30,7 +30,6 @@ func OrderMakeEnd(c *gin.Context) { args["str"] = "烘焙" commMake(c, args) } - func OrderBakingEnd(c *gin.Context) { var args map[string]string if err := c.ShouldBindJSON(&args); err != nil { @@ -174,3 +173,129 @@ func commMake(c *gin.Context, args map[string]string) { e.OutSuc(c, "success", nil) return } +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 utils.StrToInt(v["num"]) == 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 + } + //写入流程记录 + var recordFlow = &model.OrderGoodsDoingFlow{ + Num: record.Num, + State: 4, + Memo: "", + SuccessNum: utils.StrToInt(v["num"]), + Time: time.Now(), + RecordId: record.Id, + AdminId: utils.StrToInt(args.AdminId), + } + 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.GetOrderGoodsMakeStock(sess, utils.StrToInt64(args["gid"]), utils.StrToInt64(args["sku_id"])) + + if orderGoods == nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单查找失败,请重试")) + return + } + + WaitMakeNum := orderGoods.WaitMakeNum + if state == 2 { //制作完成 + orderGoods.WaitMakeNum -= utils.StrToInt(args["num"]) + orderGoods.WaitBakingNum += utils.StrToInt(args["num"]) + if orderGoods.WaitMakeNum < 0 { + orderGoods.WaitMakeNum = 0 + } + } + if state == 3 { //烘焙完成 + 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(), + RecordId: orderGoods.Id, + AdminId: utils.StrToInt(args["admin_id"]), + } + 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 +} diff --git a/app/router/big_data_router.go b/app/router/big_data_router.go index 45d087d..c16c96c 100644 --- a/app/router/big_data_router.go +++ b/app/router/big_data_router.go @@ -18,4 +18,10 @@ func BigDataInit(r *gin.RouterGroup) { func rData(r *gin.RouterGroup) { r.GET("/leftData", hdl.LeftData) //左侧数据 r.POST("/rightData", hdl.RightData) //右侧数据 + + r.GET("/making_data", hdl.MakingData) //制作区数据 + r.GET("/baking_data", hdl.BakingData) //烘焙区数据 + r.GET("/sorting_data", hdl.SortingData) //分拣区数据 + r.GET("/new_order_notice", hdl.NewOrderNotice) //新订单提醒 + } diff --git a/app/router/ipad_router.go b/app/router/ipad_router.go index 8217fa0..2204413 100644 --- a/app/router/ipad_router.go +++ b/app/router/ipad_router.go @@ -8,15 +8,18 @@ import ( func IpadInit(r *gin.RouterGroup) { r.POST("/login", hdl.Login) - r.Use(mw.Auth) //检测登录状态 - r.GET("order/cate", hdl.OrderCate) //订单类目 - r.POST("order/list", hdl.Order) //订单 - r.GET("order/goods/cate", hdl.OrderGoodsCate) //订单商品类目 - r.POST("order/goods/list", hdl.OrderGoods) //订单商品 - r.GET("responsible", hdl.Responsible) //负责人 - r.POST("order/make/begin", hdl.OrderMakeBegin) //订单开始制作 - r.POST("order/make/end", hdl.OrderMakeEnd) //订单制作完成 - r.POST("order/baking/end", hdl.OrderBakingEnd) //订单烘焙完成 - r.POST("order/sorting/end", hdl.OrderSortingEnd) //订单分拣完成 + r.Use(mw.Auth) //检测登录状态 + r.GET("order/cate", hdl.OrderCate) //订单类目 + r.POST("order/list", hdl.Order) //订单 + r.POST("order/state_list", hdl.StateOrder) //订单 + r.GET("order/goods/cate", hdl.OrderGoodsCate) //订单商品类目 + r.POST("order/goods/list", hdl.OrderGoods) //订单商品 + r.GET("responsible", hdl.Responsible) //负责人 + r.POST("order/make/begin", hdl.OrderMakeBegin) //订单开始制作 + + 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) //订单商品 }