美食城优化

This commit is contained in:
meixiongfeng 2023-01-11 16:39:08 +08:00
parent ceef317391
commit b9b4cb0909
4 changed files with 28 additions and 23 deletions

View File

@ -5,7 +5,6 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -22,8 +21,8 @@ func (this *apiComp) CreateOrderCheck(session comm.IUserSession, req *pb.Gourmet
///美食城创建订单 ///美食城创建订单
func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreateOrderReq) (code pb.ErrorCode, data proto.Message) { func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreateOrderReq) (code pb.ErrorCode, data proto.Message) {
var ( var (
res []*cfg.Gameatn // 订单消耗 res []*cfg.Gameatn // 订单消耗
costTime int32 costTime int32 // 当前订单的总耗时
szTime map[int32]int32 // 记录每个类型的订单耗时 key 是技能组type value 订单耗时 szTime map[int32]int32 // 记录每个类型的订单耗时 key 是技能组type value 订单耗时
privilegeAddItme int32 // 特权额外增加的时间 privilegeAddItme int32 // 特权额外增加的时间
) )
@ -48,10 +47,10 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreat
} }
} }
if !utils.IsToday(_gourmet.Ctime) { // 跨天了 // if !utils.IsToday(_gourmet.Ctime) { // 跨天了
_gourmet.Ctime = configure.Now().Unix() // _gourmet.Ctime = configure.Now().Unix()
_gourmet.OrderCostTime = 0 // _gourmet.OrderCostTime = 0
} // }
// 计算消耗 // 计算消耗
for _, order := range req.Order { for _, order := range req.Order {
if order.FoodCount == 0 { if order.FoodCount == 0 {
@ -97,9 +96,6 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreat
} }
// 重新计算时间 // 重新计算时间
for _, v := range _gourmet.Foods { for _, v := range _gourmet.Foods {
if v.FoodCount == 0 {
continue
}
if v1, ok := szTime[v.FoodType]; ok { if v1, ok := szTime[v.FoodType]; ok {
v.CookTime = v1 * v.FoodCount v.CookTime = v1 * v.FoodCount
} }

View File

@ -67,8 +67,8 @@ func (this *modelGourmet) modifyGourmetDataByObjId(uid string, data map[string]i
// 计算订单信息 // 计算订单信息
func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet) { func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet) {
var ( var (
szTime map[int32]int32 szTime map[int32]int32 // 食材耗时
zeroTime int64 // 当前时间对应的0点时间戳,用来判断是否跨天了 zeroTime int64 // 当前时间对应的0点时间戳,用来判断是否跨天了
) )
mapData := make(map[string]interface{}, 0) mapData := make(map[string]interface{}, 0)
szTime = make(map[int32]int32, 0) szTime = make(map[int32]int32, 0)
@ -109,7 +109,13 @@ func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet)
gourmet.CookingFood = &pb.Cooking{} gourmet.CookingFood = &pb.Cooking{}
gourmet.CookingFood.STime = configure.Now().Unix() gourmet.CookingFood.STime = configure.Now().Unix()
gourmet.CookingFood.ETime = configure.Now().Unix() + int64(szTime[order.FoodType]) gourmet.CookingFood.ETime = configure.Now().Unix() + int64(szTime[order.FoodType])
// 如果此时跨天了 清除订单时常
if gourmet.CookingFood.STime < zeroTime && zeroTime <= gourmet.CookingFood.ETime { // 跨天清空订单耗时
gourmet.OrderCostTime = 0
for _, order := range gourmet.Foods { // 重新计算订单时常
gourmet.OrderCostTime += order.FoodCount * szTime[order.FoodType]
}
}
} else { } else {
gourmet.CookingFood.STime += int64(szTime[order.FoodType]) gourmet.CookingFood.STime += int64(szTime[order.FoodType])
oldTime := gourmet.CookingFood.ETime oldTime := gourmet.CookingFood.ETime
@ -117,8 +123,7 @@ func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet)
// 如果此时跨天了 清除订单时常 // 如果此时跨天了 清除订单时常
if oldTime < zeroTime && zeroTime <= gourmet.CookingFood.ETime { // 跨天清空订单耗时 if oldTime < zeroTime && zeroTime <= gourmet.CookingFood.ETime { // 跨天清空订单耗时
gourmet.OrderCostTime = 0 gourmet.OrderCostTime = 0
// 重新计算订单时常 for _, order := range gourmet.Foods { // 重新计算订单时常
for _, order := range gourmet.Foods {
gourmet.OrderCostTime += order.FoodCount * szTime[order.FoodType] gourmet.OrderCostTime += order.FoodCount * szTime[order.FoodType]
} }
} }
@ -132,6 +137,7 @@ func (this *modelGourmet) CalculationGourmet(uid string, gourmet *pb.DBGourmet)
bRet = true bRet = true
gourmet.TotalTime += szTime[order.FoodType] gourmet.TotalTime += szTime[order.FoodType]
mapData["totalTime"] = gourmet.TotalTime mapData["totalTime"] = gourmet.TotalTime
//break
} }
} }
if !bRet { // 没有订单可以做 if !bRet { // 没有订单可以做

View File

@ -5,7 +5,6 @@ import (
"go_dreamfactory/pb" "go_dreamfactory/pb"
"go_dreamfactory/sys/configure" "go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs" cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
) )
@ -46,10 +45,10 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.SmithyCreate
if _smithy.Ctime == 0 { if _smithy.Ctime == 0 {
_smithy.Ctime = configure.Now().Unix() _smithy.Ctime = configure.Now().Unix()
} }
if !utils.IsToday(_smithy.Ctime) { // if !utils.IsToday(_smithy.Ctime) {
_smithy.Ctime = configure.Now().Unix() // _smithy.Ctime = configure.Now().Unix()
_smithy.OrderCostTime = 0 // _smithy.OrderCostTime = 0
} // }
_smithy.Orders = append(_smithy.Orders, req.Order...) // 直接追加订单数据 _smithy.Orders = append(_smithy.Orders, req.Order...) // 直接追加订单数据
if _smithy.Clang == nil || (_smithy.Clang != nil && _smithy.Clang.ETime == 0) { if _smithy.Clang == nil || (_smithy.Clang != nil && _smithy.Clang.ETime == 0) {
for _, v := range _smithy.Orders { for _, v := range _smithy.Orders {

View File

@ -101,7 +101,12 @@ func (this *modelSmithy) CalculationSmithy(uid string, smithy *pb.DBSmithy) {
smithy.Clang = &pb.Clang{} smithy.Clang = &pb.Clang{}
smithy.Clang.STime = configure.Now().Unix() smithy.Clang.STime = configure.Now().Unix()
smithy.Clang.ETime = configure.Now().Unix() + int64(szTime[order.DeskType]) smithy.Clang.ETime = configure.Now().Unix() + int64(szTime[order.DeskType])
if smithy.Clang.STime < zeroTime && zeroTime <= smithy.Clang.ETime { // 跨天清空订单耗时
smithy.OrderCostTime = 0
for _, order := range smithy.Orders { // 重新计算订单时常
smithy.OrderCostTime += order.Count * szTime[order.DeskType]
}
}
} else { } else {
smithy.Clang.STime += int64(szTime[order.DeskType]) smithy.Clang.STime += int64(szTime[order.DeskType])
oldTime := smithy.Clang.ETime oldTime := smithy.Clang.ETime
@ -109,8 +114,7 @@ func (this *modelSmithy) CalculationSmithy(uid string, smithy *pb.DBSmithy) {
// 如果此时跨天了 清除订单时常 // 如果此时跨天了 清除订单时常
if oldTime < zeroTime && zeroTime <= smithy.Clang.ETime { // 跨天清空订单耗时 if oldTime < zeroTime && zeroTime <= smithy.Clang.ETime { // 跨天清空订单耗时
smithy.OrderCostTime = 0 smithy.OrderCostTime = 0
// 重新计算订单时常 for _, order := range smithy.Orders { // 重新计算订单时常
for _, order := range smithy.Orders {
smithy.OrderCostTime += order.Count * szTime[order.DeskType] smithy.OrderCostTime += order.Count * szTime[order.DeskType]
} }
} }