diff --git a/app/admin/svc/order/svc_order_list.go b/app/admin/svc/order/svc_order_list.go index 882c26f..0e25183 100644 --- a/app/admin/svc/order/svc_order_list.go +++ b/app/admin/svc/order/svc_order_list.go @@ -246,13 +246,47 @@ func OrderCancel(c *gin.Context) { e.OutErr(c, 400, e.NewErr(400, "订单已取消")) return } - if order.State > 0 { - e.OutErr(c, 400, e.NewErr(400, "订单制作中,不能取消")) - return + sess := eg.NewSession() + defer sess.Close() + sess.Begin() + goods := db.GetOrderGoodsByIds(sess, args["oid"]) + if goods != nil { + for _, v := range *goods { + //判断有没有的扣 + all := db.GetOrderGoodsMakeStockAll(sess, v.GoodsId, v.SkuId) + if all == nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单取消失败")) + return + } + if all.WaitMakeNum < v.Num { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单已经在制作,取消失败")) + return + } + all.WaitBakingNum -= v.Num + _, err := sess.Where("id=?", all.Id).Cols("wait_baking_num").Update(all) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单取消失败")) + return + } + } } order.State = 5 - eg.Where("oid=?", order.Oid).Cols("state").Update(order) - eg.Where("oid=?", order.Oid).Cols("state").Update(&model.OrderGoods{State: 5}) + _, err := sess.Where("oid=?", order.Oid).Cols("state").Update(order) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单取消失败")) + return + } + _, err = sess.Where("oid=?", order.Oid).Cols("state").Update(&model.OrderGoods{State: 5}) + if err != nil { + sess.Rollback() + e.OutErr(c, 400, e.NewErr(400, "订单取消失败")) + return + } + sess.Commit() e.OutSuc(c, "success", nil) return } diff --git a/app/bigData/svc/svc_data.go b/app/bigData/svc/svc_data.go index 8462708..6ec4713 100644 --- a/app/bigData/svc/svc_data.go +++ b/app/bigData/svc/svc_data.go @@ -10,192 +10,192 @@ import ( ) func LeftDataForMake() (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) - if err != nil { - return - } - var enterpriseMap = map[int]model.Enterprise{} - for _, v := range enterprise { - enterpriseMap[v.Id] = v - } - - //1、查找当天的 order 数据(大于 待制作) - var orders []model.Order - err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).Find(&orders) - if err != nil { - return - } - var oIds []int64 - for _, v := range orders { - oIds = append(oIds, v.Oid) - } - - //2、查找对应的订单产品记录 - var orderGoods []model.OrderGoods - err = engine.In("oid", oIds).Find(&orderGoods) - if err != nil { - return - } - var orderGoodsMap = map[int64][]model.OrderGoods{} - var records []int - for _, v := range orderGoods { - if orderGoodsMap[v.Oid] == nil { - orderGoodsMap[v.Oid] = []model.OrderGoods{} - } - orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v) - 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{"待制作", "制作中", "烘焙完成", "分拣完成", "已取消"} - for _, v := range orders { - var list []md.LeftDataForMakeList - if len(orderGoodsMap[v.Oid]) > 0 { - orderGoodsStateArr := []string{"待制作", "制作中"} - for _, vv := range orderGoodsMap[v.Oid] { - skuData := make([]md2.Sku, 0) - json.Unmarshal([]byte(vv.Sku), &skuData) - skuStr := "" - for _, v1 := range skuData { - if skuStr != "" { - skuStr += ";" - } - skuStr += v1.Value - } - var stateZh = "已完成" - if vv.State <= 1 { - stateZh = orderGoodsStateArr[vv.State] - } - list = append(list, md.LeftDataForMakeList{ - GoodsName: vv.GoodsTitle, - Sku: skuStr, - Num: vv.Num, - SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum, - StateZh: stateZh, - State: vv.State, - }) - } - - resp = append(resp, md.LeftDataForMakeResp{ - EnterpriseName: enterpriseMap[v.EnterpriseId].Name, - EnterpriseId: v.EnterpriseId, - StateZh: orderStateArr[v.State], - State: v.State, - List: list, - }) - } - } + //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) + //if err != nil { + // return + //} + //var enterpriseMap = map[int]model.Enterprise{} + //for _, v := range enterprise { + // enterpriseMap[v.Id] = v + //} + // + ////1、查找当天的 order 数据(大于 待制作) + //var orders []model.Order + //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).Find(&orders) + //if err != nil { + // return + //} + //var oIds []int64 + //for _, v := range orders { + // oIds = append(oIds, v.Oid) + //} + // + ////2、查找对应的订单产品记录 + //var orderGoods []model.OrderGoods + //err = engine.In("oid", oIds).Find(&orderGoods) + //if err != nil { + // return + //} + //var orderGoodsMap = map[int64][]model.OrderGoods{} + //var records []int + //for _, v := range orderGoods { + // if orderGoodsMap[v.Oid] == nil { + // orderGoodsMap[v.Oid] = []model.OrderGoods{} + // } + // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v) + // 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{"待制作", "制作中", "烘焙完成", "分拣完成", "已取消"} + //for _, v := range orders { + // var list []md.LeftDataForMakeList + // if len(orderGoodsMap[v.Oid]) > 0 { + // orderGoodsStateArr := []string{"待制作", "制作中"} + // for _, vv := range orderGoodsMap[v.Oid] { + // skuData := make([]md2.Sku, 0) + // json.Unmarshal([]byte(vv.Sku), &skuData) + // skuStr := "" + // for _, v1 := range skuData { + // if skuStr != "" { + // skuStr += ";" + // } + // skuStr += v1.Value + // } + // var stateZh = "已完成" + // if vv.State <= 1 { + // stateZh = orderGoodsStateArr[vv.State] + // } + // list = append(list, md.LeftDataForMakeList{ + // GoodsName: vv.GoodsTitle, + // Sku: skuStr, + // Num: vv.Num, + // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum, + // StateZh: stateZh, + // State: vv.State, + // }) + // } + // + // resp = append(resp, md.LeftDataForMakeResp{ + // EnterpriseName: enterpriseMap[v.EnterpriseId].Name, + // EnterpriseId: v.EnterpriseId, + // StateZh: orderStateArr[v.State], + // State: v.State, + // List: list, + // }) + // } + //} return } func LeftDataForBaking() (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) - if err != nil { - return - } - var enterpriseMap = map[int]model.Enterprise{} - for _, v := range enterprise { - enterpriseMap[v.Id] = v - } - - //1、查找当天的 order 数据(大于 待制作) - var orders []model.Order - err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).Find(&orders) - if err != nil { - return - } - var oIds []int64 - for _, v := range orders { - oIds = append(oIds, v.Oid) - } - - //2、查找对应的订单产品记录 - var orderGoods []model.OrderGoods - err = engine.In("oid", oIds).Find(&orderGoods) - if err != nil { - return - } - var orderGoodsMap = map[int64][]model.OrderGoods{} - var records []int - for _, v := range orderGoods { - if orderGoodsMap[v.Oid] == nil { - orderGoodsMap[v.Oid] = []model.OrderGoods{} - } - orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v) - 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{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} - for _, v := range orders { - var list []md.LeftDataForMakeList - if len(orderGoodsMap[v.Oid]) > 0 { - for _, vv := range orderGoodsMap[v.Oid] { - skuData := make([]md2.Sku, 0) - json.Unmarshal([]byte(vv.Sku), &skuData) - skuStr := "" - for _, v1 := range skuData { - if skuStr != "" { - skuStr += ";" - } - skuStr += v1.Value - } - var stateZh = "已完成" - if vv.State == 2 { - stateZh = "烘焙中" - } - - list = append(list, md.LeftDataForMakeList{ - GoodsName: vv.GoodsTitle, - Sku: skuStr, - Num: vv.Num, - SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum, - StateZh: stateZh, - State: vv.State, - }) - } - - resp = append(resp, md.LeftDataForMakeResp{ - EnterpriseName: enterpriseMap[v.EnterpriseId].Name, - EnterpriseId: v.EnterpriseId, - StateZh: orderStateArr[v.State], - State: v.State, - List: list, - }) - } - } + //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) + //if err != nil { + // return + //} + //var enterpriseMap = map[int]model.Enterprise{} + //for _, v := range enterprise { + // enterpriseMap[v.Id] = v + //} + // + ////1、查找当天的 order 数据(大于 待制作) + //var orders []model.Order + //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).Find(&orders) + //if err != nil { + // return + //} + //var oIds []int64 + //for _, v := range orders { + // oIds = append(oIds, v.Oid) + //} + // + ////2、查找对应的订单产品记录 + //var orderGoods []model.OrderGoods + //err = engine.In("oid", oIds).Find(&orderGoods) + //if err != nil { + // return + //} + //var orderGoodsMap = map[int64][]model.OrderGoods{} + //var records []int + //for _, v := range orderGoods { + // if orderGoodsMap[v.Oid] == nil { + // orderGoodsMap[v.Oid] = []model.OrderGoods{} + // } + // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v) + // 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{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"} + //for _, v := range orders { + // var list []md.LeftDataForMakeList + // if len(orderGoodsMap[v.Oid]) > 0 { + // for _, vv := range orderGoodsMap[v.Oid] { + // skuData := make([]md2.Sku, 0) + // json.Unmarshal([]byte(vv.Sku), &skuData) + // skuStr := "" + // for _, v1 := range skuData { + // if skuStr != "" { + // skuStr += ";" + // } + // skuStr += v1.Value + // } + // var stateZh = "已完成" + // if vv.State == 2 { + // stateZh = "烘焙中" + // } + // + // list = append(list, md.LeftDataForMakeList{ + // GoodsName: vv.GoodsTitle, + // Sku: skuStr, + // Num: vv.Num, + // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum, + // StateZh: stateZh, + // State: vv.State, + // }) + // } + // + // resp = append(resp, md.LeftDataForMakeResp{ + // EnterpriseName: enterpriseMap[v.EnterpriseId].Name, + // EnterpriseId: v.EnterpriseId, + // StateZh: orderStateArr[v.State], + // State: v.State, + // List: list, + // }) + // } + //} return } diff --git a/app/db/db_order_goods_list.go b/app/db/db_order_goods_list.go index a34c85b..5eff185 100644 --- a/app/db/db_order_goods_list.go +++ b/app/db/db_order_goods_list.go @@ -41,6 +41,14 @@ func GetOrderGoodsById(eg *xorm.Engine, id string) *model.OrderGoods { } return &order } +func GetOrderGoodsByIds(sess *xorm.Session, id string) *[]model.OrderGoods { + var order []model.OrderGoods + err := sess.Where("oid=?", id).Find(&order) + if err != nil { + return nil + } + return &order +} func GetOrderGoodsByIdSess(sess *xorm.Session, id string) *model.OrderGoods { var order model.OrderGoods get, err := sess.Where("id=?", id).Get(&order) diff --git a/app/db/db_order_goods_make_stock.go b/app/db/db_order_goods_make_stock.go index 86cacc5..295c28d 100644 --- a/app/db/db_order_goods_make_stock.go +++ b/app/db/db_order_goods_make_stock.go @@ -71,3 +71,12 @@ func GetOrderGoodsMakeStock(sess *xorm.Session, gid, skuId int64) *model.OrderGo } return &data } +func GetOrderGoodsMakeStockAll(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 || get == false { + return nil + } + + return &data +} diff --git a/app/db/model/order_goods_doing_flow.go b/app/db/model/order_goods_doing_flow.go index 7848cb3..360836f 100644 --- a/app/db/model/order_goods_doing_flow.go +++ b/app/db/model/order_goods_doing_flow.go @@ -11,6 +11,8 @@ type OrderGoodsDoingFlow struct { SuccessNum int `json:"success_num" xorm:"comment('完成数量') INT(11)"` Memo string `json:"memo" xorm:"comment('制作完成备注') VARCHAR(255)"` Time time.Time `json:"time" xorm:"DATETIME"` - RecordId int `json:"record_id" xorm:"default 0 comment('order_goods_doing 的id') 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)"` AdminId int `json:"admin_id" xorm:"default 0 comment('admin 的id') INT(11)"` } diff --git a/app/ipad/svc/svc_order_make.go b/app/ipad/svc/svc_order_make.go index 70ea5ce..59861d6 100644 --- a/app/ipad/svc/svc_order_make.go +++ b/app/ipad/svc/svc_order_make.go @@ -81,7 +81,9 @@ func OrderSortingEnd(c *gin.Context) { Memo: "", SuccessNum: utils.StrToInt(v["num"]), Time: time.Now(), - RecordId: record.Id, + Gid: record.GoodsId, + SkuId: record.SkuId, + SkuCode: record.SkuCode, AdminId: utils.StrToInt(args.AdminId), } one, err := sess.InsertOne(recordFlow) @@ -149,7 +151,9 @@ func commMake(c *gin.Context, args map[string]string) { Memo: args["memo"], SuccessNum: utils.StrToInt(args["num"]), Time: time.Now(), - RecordId: orderGoods.Id, + Gid: orderGoods.GoodsId, + SkuId: orderGoods.SkuId, + SkuCode: orderGoods.SkuCode, AdminId: utils.StrToInt(args["admin_id"]), } one, err := sess.InsertOne(recordFlow) @@ -225,7 +229,9 @@ func NewOrderSortingEnd(c *gin.Context) { Memo: "", SuccessNum: utils.StrToInt(v["num"]), Time: time.Now(), - RecordId: record.Id, + Gid: record.GoodsId, + SkuId: record.SkuId, + SkuCode: record.SkuCode, AdminId: utils.StrToInt(args.AdminId), } one, err := sess.InsertOne(recordFlow) @@ -285,7 +291,9 @@ func commNewMake(c *gin.Context, args map[string]string) { Memo: args["memo"], SuccessNum: utils.StrToInt(args["num"]), Time: time.Now(), - RecordId: orderGoods.Id, + Gid: orderGoods.Gid, + SkuId: orderGoods.SkuId, + SkuCode: orderGoods.SkuCode, AdminId: utils.StrToInt(args["admin_id"]), } one, err := sess.InsertOne(recordFlow)