go_dreamfactory/modules/viking/api_getlist.go
2022-11-09 14:18:03 +08:00

73 lines
1.9 KiB
Go

package viking
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go_dreamfactory/utils"
"google.golang.org/protobuf/proto"
)
//参数校验
func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.VikingGetListReq) (code pb.ErrorCode) {
return
}
func (this *apiComp) GetList(session comm.IUserSession, req *pb.VikingGetListReq) (code pb.ErrorCode, data proto.Message) {
var (
mapData map[string]interface{}
)
mapData = make(map[string]interface{}, 0)
code = this.GetListCheck(session, req)
if code != pb.ErrorCode_Success {
return // 参数校验失败直接返回
}
list, err := this.module.modelViking.getVikingList(session.GetUserId())
if err != nil {
code = pb.ErrorCode_DBError
return
}
// 校验 是不是当天
if !utils.IsToday(list.CTime) {
list.CTime = configure.Now().Unix()
list.BuyCount = 0
list.ChallengeCount = 0
mapData["cTime"] = list.CTime
mapData["buyCount"] = list.BuyCount
mapData["challengeCount"] = list.ChallengeCount
}
// 检查恢复时间
conf := this.module.configure.GetGlobalConf()
if conf == nil {
code = pb.ErrorCode_ConfigNoFound
return
}
if list.LeftCount != conf.VikingNum {
if list.RecoveryTime == 0 {
list.RecoveryTime = configure.Now().Unix()
}
count := (configure.Now().Unix() - list.RecoveryTime) / int64(conf.VikingExpeditionRecoveryTime*60)
if count > 1 {
list.LeftCount += int32(count)
}
if list.LeftCount >= conf.VikingNum {
list.LeftCount = conf.VikingNum
list.RecoveryTime = 0
} else {
list.RecoveryTime += count * int64(conf.VikingExpeditionRecoveryTime*60) // 更新刷新时间
}
} else {
list.RecoveryTime = 0
}
mapData["recoveryTime"] = list.RecoveryTime
code = this.module.ModifyVikingData(session.GetUserId(), mapData) //修改内存信息
session.SendMsg(string(this.module.GetType()), VikingGetListResp, &pb.VikingGetListResp{Data: list})
return
}