美食馆订单优化
This commit is contained in:
parent
829edf4465
commit
30ef92bd95
@ -39,13 +39,14 @@ func (this *apiComp) CreateOrder(session comm.IUserSession, req *pb.GourmetCreat
|
|||||||
// 记录每个食材耗时
|
// 记录每个食材耗时
|
||||||
for k, v := range _gourmet.Skill {
|
for k, v := range _gourmet.Skill {
|
||||||
_skillCfg := this.module.configure.GetGourmetConfigData(k, v)
|
_skillCfg := this.module.configure.GetGourmetConfigData(k, v)
|
||||||
szTime[k] = _skillCfg.Needtime
|
szTime[k] += _skillCfg.Needtime
|
||||||
}
|
// 高效制作技能
|
||||||
// 高效制作技能
|
for k1, v1 := range _gourmet.SpecialSkill {
|
||||||
for k, v := range _gourmet.SpecialSkill {
|
specalSkill := this.module.configure.GetGourmetConfigData(k1, v1)
|
||||||
specalSkill := this.module.configure.GetGourmetConfigData(k, v)
|
szTime[k] += specalSkill.Needtime
|
||||||
szTime[k] = specalSkill.Needtime
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -67,123 +67,88 @@ 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 (
|
||||||
bCooking bool
|
szTime map[int32]int32
|
||||||
costTime int32
|
zeroTime int64 // 当前时间对应的0点时间戳,用来判断是否跨天了
|
||||||
curTime int32
|
|
||||||
szTime map[int32]int32
|
|
||||||
zeroTime int64 // 订单开始的时间对应第二天0点时间
|
|
||||||
nextDay bool // 是否跨天了
|
|
||||||
nextDayTime int32 // 跨天累计时间
|
|
||||||
)
|
)
|
||||||
mapData := make(map[string]interface{}, 0)
|
mapData := make(map[string]interface{}, 0)
|
||||||
szTime = make(map[int32]int32, 0)
|
szTime = make(map[int32]int32, 0)
|
||||||
defer this.module.ModifyGourmetData(uid, mapData)
|
|
||||||
|
|
||||||
// 记录每个食材耗时
|
// 记录每个食材耗时
|
||||||
for k, v := range gourmet.Skill {
|
for k, v := range gourmet.Skill {
|
||||||
var _time int32
|
|
||||||
// 计算出需要的时间
|
// 计算出需要的时间
|
||||||
_skillCfg := this.module.configure.GetGourmetConfigData(k, v)
|
_skillCfg := this.module.configure.GetGourmetConfigData(k, v)
|
||||||
_time += _skillCfg.Needtime
|
szTime[k] += _skillCfg.Needtime
|
||||||
// 高效制作技能
|
// 高效制作技能
|
||||||
for k, v := range gourmet.SpecialSkill {
|
for k1, v1 := range gourmet.SpecialSkill {
|
||||||
specalSkill := this.module.configure.GetGourmetConfigData(k, v)
|
specalSkill := this.module.configure.GetGourmetConfigData(k1, v1)
|
||||||
_time += specalSkill.Needtime
|
szTime[k] += specalSkill.Needtime
|
||||||
}
|
|
||||||
szTime[k] = _time
|
|
||||||
}
|
|
||||||
if gourmet.CookingFood != nil && gourmet.CookingFood.ETime > 0 {
|
|
||||||
zeroTime = utils.GetZeroTime(gourmet.CookingFood.STime) // 获取订单开始时间当天的0点
|
|
||||||
costTime = int32(configure.Now().Unix() - gourmet.CookingFood.ETime) // 当前过去的时间
|
|
||||||
if costTime < 0 { // 没有完成 不做处理
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, order := range gourmet.Foods {
|
// 有订单在做
|
||||||
if order.FoodCount == 0 {
|
zeroTime = utils.GetTodayZeroTime(configure.Now().Unix())
|
||||||
continue
|
for {
|
||||||
}
|
if gourmet.CookingFood != nil {
|
||||||
foodtype := order.FoodType
|
if configure.Now().Unix() < gourmet.CookingFood.ETime {
|
||||||
skillLv := gourmet.Skill[foodtype] // 获取技能等级
|
|
||||||
// 计算出需要的时间
|
|
||||||
_gourmetcfg := this.module.configure.GetGourmetConfigData(foodtype, skillLv) // 美食家配置表
|
|
||||||
iCount := int(order.FoodCount)
|
|
||||||
for i := 0; i < iCount; i++ {
|
|
||||||
curTime += szTime[order.FoodType]
|
|
||||||
order.FoodCount--
|
|
||||||
if order.FoodCount == 0 {
|
|
||||||
order.CookTime = 0
|
|
||||||
}
|
|
||||||
order.CookTime = order.FoodCount * szTime[order.FoodType]
|
|
||||||
if gourmet.CookingFood == nil {
|
|
||||||
if zeroTime == 0 {
|
|
||||||
zeroTime = utils.GetZeroTime(configure.Now().Unix())
|
|
||||||
}
|
|
||||||
gourmet.CookingFood = &pb.Cooking{}
|
|
||||||
gourmet.CookingFood.STime = configure.Now().Unix()
|
|
||||||
gourmet.CookingFood.ETime = configure.Now().Unix() + int64(szTime[order.FoodType])
|
|
||||||
} else {
|
|
||||||
gourmet.CookingFood.STime += int64(szTime[order.FoodType])
|
|
||||||
gourmet.CookingFood.ETime += int64(szTime[order.FoodType])
|
|
||||||
}
|
|
||||||
gourmet.CookingFood.FoodType = order.FoodType
|
|
||||||
|
|
||||||
// 判断订单是否跨天
|
|
||||||
if gourmet.CookingFood.ETime >= zeroTime && !nextDay {
|
|
||||||
gourmet.Ctime = zeroTime // 设置
|
|
||||||
gourmet.OrderCostTime = 0
|
|
||||||
nextDay = true
|
|
||||||
}
|
|
||||||
if nextDay {
|
|
||||||
nextDayTime += szTime[order.FoodType]
|
|
||||||
}
|
|
||||||
gourmet.Items = this.module.configure.GetMultipleDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items) // 获取掉落奖励
|
|
||||||
|
|
||||||
if curTime > costTime {
|
|
||||||
// 转时间戳
|
|
||||||
gourmet.CookingFood.FoodType = order.FoodType
|
|
||||||
gourmet.CookingFood.ETime = configure.Now().Unix() + int64(curTime-costTime)
|
|
||||||
gourmet.CookingFood.STime = gourmet.CookingFood.ETime - int64(szTime[order.FoodType])
|
|
||||||
bCooking = true
|
|
||||||
|
|
||||||
// 记录下订单时间
|
|
||||||
gourmet.Ctime = gourmet.CookingFood.ETime
|
|
||||||
mapData["ctime"] = gourmet.Ctime
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bRet := false
|
||||||
|
for _, order := range gourmet.Foods {
|
||||||
|
_gourmetcfg := this.module.configure.GetGourmetConfigData(order.FoodType, gourmet.Skill[order.FoodType]) // 美食家配置表
|
||||||
|
if order.FoodCount > 0 {
|
||||||
|
order.FoodCount--
|
||||||
|
if order.FoodCount == 0 {
|
||||||
|
order.CookTime = 0
|
||||||
|
}
|
||||||
|
order.CookTime = order.FoodCount * szTime[order.FoodType]
|
||||||
|
if gourmet.CookingFood == nil {
|
||||||
|
gourmet.CookingFood = &pb.Cooking{}
|
||||||
|
gourmet.CookingFood.STime = configure.Now().Unix()
|
||||||
|
gourmet.CookingFood.ETime = configure.Now().Unix() + int64(szTime[order.FoodType])
|
||||||
|
|
||||||
if bCooking { // 分配了正在製作的食物
|
} else {
|
||||||
|
gourmet.CookingFood.STime += int64(szTime[order.FoodType])
|
||||||
|
oldTime := gourmet.CookingFood.ETime
|
||||||
|
gourmet.CookingFood.ETime += int64(szTime[order.FoodType])
|
||||||
|
// 如果此时跨天了 清除订单时常
|
||||||
|
if oldTime < zeroTime && zeroTime <= gourmet.CookingFood.ETime { // 跨天清空订单耗时
|
||||||
|
gourmet.OrderCostTime = 0
|
||||||
|
// 重新计算订单时常
|
||||||
|
for _, order := range gourmet.Foods {
|
||||||
|
gourmet.OrderCostTime += order.FoodCount * szTime[order.FoodType]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gourmet.CookingFood.FoodType = order.FoodType
|
||||||
|
// 设置掉落组
|
||||||
|
gourmet.Items = this.module.configure.GetMultipleDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items) // 获取掉落奖励
|
||||||
|
// 记录下订单时间
|
||||||
|
gourmet.Ctime = gourmet.CookingFood.ETime
|
||||||
|
mapData["ctime"] = gourmet.Ctime
|
||||||
|
bRet = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !bRet { // 没有订单可以做
|
||||||
|
if gourmet.CookingFood != nil {
|
||||||
|
if gourmet.CookingFood.ETime <= configure.Now().Unix() {
|
||||||
|
_gourmetcfg := this.module.configure.GetGourmetConfigData(gourmet.CookingFood.FoodType, gourmet.Skill[gourmet.CookingFood.FoodType])
|
||||||
|
gourmet.Items = this.module.configure.GetMultipleDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items)
|
||||||
|
gourmet.CookingFood = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if nextDay {
|
|
||||||
gourmet.OrderCostTime += nextDayTime
|
|
||||||
for _, order := range gourmet.Foods {
|
|
||||||
if order.FoodCount == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
gourmet.OrderCostTime += szTime[order.FoodType] * order.FoodCount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if utils.GetZeroTime(gourmet.Ctime) <= configure.Now().Unix() {
|
|
||||||
gourmet.OrderCostTime = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if gourmet.CookingFood != nil && gourmet.CookingFood.ETime <= configure.Now().Unix() { // 当前时间超过正在做的时间
|
|
||||||
foodtype := gourmet.CookingFood.FoodType
|
|
||||||
skillLv := gourmet.Skill[foodtype] // 获取技能等级
|
|
||||||
_gourmetcfg := this.module.configure.GetGourmetConfigData(foodtype, skillLv) // 美食家配置表
|
|
||||||
gourmet.Items = this.module.configure.GetMultipleDropReward(_gourmetcfg.Using, _gourmetcfg.Propsgroup, gourmet.Items)
|
|
||||||
gourmet.CookingFood = nil
|
|
||||||
}
|
|
||||||
// 保存信息
|
// 保存信息
|
||||||
mapData["items"] = gourmet.Items
|
mapData["items"] = gourmet.Items
|
||||||
mapData["foods"] = gourmet.Foods
|
mapData["foods"] = gourmet.Foods
|
||||||
mapData["orderCostTime"] = gourmet.OrderCostTime
|
mapData["orderCostTime"] = gourmet.OrderCostTime
|
||||||
mapData["cookingFood"] = gourmet.CookingFood // 正在做的
|
mapData["cookingFood"] = gourmet.CookingFood // 正在做的
|
||||||
|
|
||||||
|
this.module.ModifyGourmetData(uid, mapData) // 同步数据
|
||||||
}
|
}
|
||||||
|
|
||||||
// 技能等级提高了 重新计算订单时间(只对订单中数据有影响)
|
// 技能等级提高了 重新计算订单时间(只对订单中数据有影响)
|
||||||
|
@ -155,7 +155,7 @@ type DBGourmet struct {
|
|||||||
|
|
||||||
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID
|
Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID
|
||||||
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID
|
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID
|
||||||
CookingFood *Cooking `protobuf:"bytes,3,opt,name=cookingFood,proto3" json:"cookingFood" bson:"cooking"` //正在烹饪的食品
|
CookingFood *Cooking `protobuf:"bytes,3,opt,name=cookingFood,proto3" json:"cookingFood" bson:"cookingFood"` //正在烹饪的食品
|
||||||
Foods []*OrderCook `protobuf:"bytes,4,rep,name=foods,proto3" json:"foods" bson:"foods"` //等待烹饪的食品
|
Foods []*OrderCook `protobuf:"bytes,4,rep,name=foods,proto3" json:"foods" bson:"foods"` //等待烹饪的食品
|
||||||
Items []*UserAssets `protobuf:"bytes,5,rep,name=items,proto3" json:"items" bson:"items"` //已经做好的食品
|
Items []*UserAssets `protobuf:"bytes,5,rep,name=items,proto3" json:"items" bson:"items"` //已经做好的食品
|
||||||
Skill map[int32]int32 `protobuf:"bytes,6,rep,name=skill,proto3" json:"skill" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"skill"` //技能ID
|
Skill map[int32]int32 `protobuf:"bytes,6,rep,name=skill,proto3" json:"skill" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"skill"` //技能ID
|
||||||
|
@ -108,3 +108,11 @@ func GetMonthStartEnd() (int64, int64) {
|
|||||||
fmt.Printf("%d,%d", _d1, _d2)
|
fmt.Printf("%d,%d", _d1, _d2)
|
||||||
return _d1, _d2
|
return _d1, _d2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取今天零点时间戳
|
||||||
|
func GetTodayZeroTime(curTime int64) int64 {
|
||||||
|
currentTime := time.Unix(curTime, 0)
|
||||||
|
startTime := time.Date(currentTime.Year(), currentTime.Month(), currentTime.Day(), 0, 0, 0, 0, currentTime.Location())
|
||||||
|
|
||||||
|
return startTime.Unix()
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user