package troll import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/utils" "time" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) GetListCheck(session comm.IUserSession, req *pb.TrollGetListReq) (code pb.ErrorCode) { return } func (this *apiComp) GetList(session comm.IUserSession, req *pb.TrollGetListReq) (code pb.ErrorCode, data proto.Message) { var ( update map[string]interface{} maxCoefficient int32 ) update = make(map[string]interface{}) if code = this.GetListCheck(session, req); code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } trolltrain, err := this.module.modelTroll.getTrollList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } maxCoefficient = this.configure.GetTrollMaxCoefficientNux() // 增长幅度的最大值 if maxCoefficient == 0 { code = pb.ErrorCode_ConfigNoFound return } // 跨天 则清除 每日交易次数 if !utils.IsToday(trolltrain.RefreshTime) { trolltrain.SellCount = 0 update["sellCount"] = trolltrain.SellCount this.module.ModifyTrollData(session.GetUserId(), update) } t := time.Now().Unix() - trolltrain.RefreshTime // 经过的时间 /// 计算经过了多少个周期 sz := this.configure.GetTrollAllTrain() var ( circletime int32 // 循环一个周期的时间 circleCount int32 // 循环的次数 leftTime int32 ) for _, v := range sz { circletime += v } circleCount = (int32(t) / circletime) // 经过的周期数 leftTime = (int32(t) % circletime) // 循环次数 trainNum := this.configure.GetTrollMaxTraintNum() trolltrain.TarinPos += circleCount * trainNum // 计算火车的位置信息 for _, v := range sz { if leftTime <= v { trolltrain.RefreshTime = time.Now().Unix() - int64(circleCount) trolltrain.RangeId = (trolltrain.TarinPos % maxCoefficient) trolltrain.TarinPos = (trolltrain.TarinPos % trainNum) + 1 update["refreshTime"] = trolltrain.RefreshTime update["tarinPos"] = trolltrain.TarinPos update["rangeId"] = trolltrain.RangeId break } trolltrain.TarinPos += 1 leftTime -= v } this.module.ModifyTrollData(session.GetUserId(), update) session.SendMsg(string(this.module.GetType()), TrollGetListResp, &pb.TrollGetListResp{Data: trolltrain}) return }