diff --git a/comm/const.go b/comm/const.go index 0a68df268..14fe8913f 100644 --- a/comm/const.go +++ b/comm/const.go @@ -432,7 +432,7 @@ const ( ) const ( - MaxRankList = 50 + MaxRankList = 50 // 赛季塔 排行榜人数 ) const ( diff --git a/modules/pagoda/api_activate.go b/modules/pagoda/api_activate.go index 1bc60ea76..aada19c85 100644 --- a/modules/pagoda/api_activate.go +++ b/modules/pagoda/api_activate.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/db" + "time" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson/primitive" @@ -38,6 +39,13 @@ func (this *apiComp) Activate(session comm.IUserSession, req *pb.PagodaActivateR server := &pb.DBServerData{} rst.Decode(server) season.Type = server.SeasonType + + dbModel := db.NewDBModel(comm.TableSeasonRecord, time.Hour, conn) + if err = dbModel.Add(session.GetUserId(), season); err != nil { + this.module.Errorf("err:%v", err) + return + } + } this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), season) } diff --git a/modules/pagoda/api_ranklist.go b/modules/pagoda/api_ranklist.go index 4832ce907..fece0562e 100644 --- a/modules/pagoda/api_ranklist.go +++ b/modules/pagoda/api_ranklist.go @@ -35,9 +35,9 @@ func (this *apiComp) RankList(session comm.IUserSession, req *pb.PagodaRankListR pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO()) ) if req.FloorId == 0 { - rd = pipe.ZRange("pagodaSeasonRank", 0, 50) + rd = pipe.ZRange("pagodaSeasonRank", 0, comm.MaxRankList) } else { - rd = pipe.ZRange("pagodaList"+strconv.Itoa(int(req.FloorId)), 0, 50) + rd = pipe.ZRange("pagodaList"+strconv.Itoa(int(req.FloorId)), 0, comm.MaxRankList) } if _, err = pipe.Exec(); err != nil { diff --git a/modules/pagoda/model_rank.go b/modules/pagoda/model_rank.go index e3d9424eb..1d8e167a4 100644 --- a/modules/pagoda/model_rank.go +++ b/modules/pagoda/model_rank.go @@ -2,10 +2,9 @@ package pagoda import ( "context" - "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" - "go_dreamfactory/lego/sys/log" + "strconv" //"go_dreamfactory/lego/sys/redis" "go_dreamfactory/lego/sys/redis/pipe" @@ -13,13 +12,8 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "go_dreamfactory/sys/db" - "sort" "github.com/go-redis/redis/v8" - - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/bson/primitive" - "go.mongodb.org/mongo-driver/mongo/options" ) var floorRankKey = "pagoda:floor" @@ -54,131 +48,6 @@ func (this *ModelRank) getPagodaRankList(uid string) []*pb.DBPagodaRecord { return pagodaRank } -// 插入新的排行数据 -func (this *ModelRank) addPagodaRankList(session comm.IUserSession, data *pb.DBPagoda, Leadpos int32, line []*pb.LineUp, costTime int32) { - uid := session.GetUserId() - var ( - dbModel *db.DBModel - err error - ) - userinfo := this.modulePagoda.ModuleUser.GetUser(session.GetUserId()) - new := &pb.DBPagodaRecord{ - Id: primitive.NewObjectID().Hex(), - Uid: session.GetUserId(), - PagodaId: data.PagodaId, - Type: data.Type, - Nickname: userinfo.Name, - Icon: "", // 暂时没有数据 - Lv: userinfo.Lv, - Leadpos: Leadpos, - Line: line, - CostTime: costTime, - } - if this.modulePagoda.IsCross() { - if dbModel, err = this.modulePagoda.GetDBNoduleByUid(uid, this.TableName, this.Expired); err != nil { - this.modulePagoda.Errorln(err) - - } else { - if err = dbModel.AddList(session.GetUserId(), new.Id, new); err != nil { - this.modulePagoda.Errorf("err:%v", err) - } - } - } else { - if err := this.AddList(session.GetUserId(), new.Id, new); err != nil { - this.modulePagoda.Errorf("err:%v", err) - } - } - - // 查询本层是否上榜 - rankData, ilen, err1 := this.GetFloorLastRankData(data.PagodaId, dbModel) - if err1 != nil { - if rankData.CostTime < costTime || ilen < comm.MaxRankNum { - this.ChangeFloorRankList(session, data.PagodaId, new, dbModel) - } - } - return -} - -// 读取某一层排行数据 -func (this *ModelRank) GetFloorRankList(floor int32) (result []*pb.DBPagodaRecord, err error) { - key := fmt.Sprintf("%s-%d-rank", floorRankKey, floor) - temp := make([]*pb.DBPagodaRecord, 0) - if err = this.Redis.LRange(key, 0, -1, &temp); err != nil { - this.modulePagoda.Errorf("err:%v", err) - return - } - - result = make([]*pb.DBPagodaRecord, len(temp)) - for n, v := range temp { - result[n] = v - //n++ - } - return -} - -// 获取排行榜最后一个元素 -func (this *ModelRank) GetFloorLastRankData(floor int32, dbModel *db.DBModel) (curData *pb.DBPagodaRecord, len int, err error) { - key := fmt.Sprintf("%s-%d-rank", floorRankKey, floor) - len, err = dbModel.Redis.Llen(key) - curData = &pb.DBPagodaRecord{} - if dbModel.Redis.Lindex(key, -1, curData); err != nil { - this.modulePagoda.Errorf("err:%v", err) - return - } - if curData == nil { - data := make([]interface{}, 0) // options.Find().SetLimit(comm.MaxRankList) - if _data, err := dbModel.DB.Find(comm.TableSeasonRecord, bson.M{"pagodaId": floor}, options.Find().SetSort(bson.M{"pagodaId": -1}).SetLimit(comm.MaxRankList)); err == nil { - for _data.Next(context.TODO()) { - temp := &pb.DBPagodaRecord{} - if err = _data.Decode(temp); err == nil { - data = append(data, temp) - curData = temp - } - } - } - err := dbModel.Redis.RPush(key, data...) - if err == nil { - this.modulePagoda.Errorf("rpush failed :%v", err) - } - } - return -} - -// 修改某一层排行数据 -func (this *ModelRank) ChangeFloorRankList(session comm.IUserSession, floor int32, curData *pb.DBPagodaRecord, dbModel *db.DBModel) (err error) { - key := fmt.Sprintf("%s-%d-rank", floorRankKey, floor) - lockkey := fmt.Sprintf("%s-%d-lock", floorRankKey, floor) - - dbModel.Redis.Lock(lockkey, configure.Now().Second()*5) - defer dbModel.Redis.UnLock(lockkey) - if dbModel.Redis.RPush(key, curData); err != nil { - this.modulePagoda.Errorf("err:%v", err) - return - } - temp := make([]*pb.DBPagodaRecord, 0) - if err = dbModel.Redis.LRange(key, 0, -1, &temp); err != nil { - this.modulePagoda.Errorf("err:%v", err) - return - } - // 排序 - sort.SliceStable(temp, func(i, j int) bool { - return temp[i].CostTime < temp[j].CostTime - }) - iLne := len(temp) - if dbModel.Redis.RPush(key, temp); err != nil { - this.modulePagoda.Errorf("err:%v", err) - return - } - if iLne > comm.MaxRankNum { - iLne = comm.MaxRankNum - } - err = dbModel.Redis.Ltrim(key, -1*iLne, -1) //对一个列表进行修剪 - if err != nil { - log.Errorf("delete failed") - } - return -} - func (this *ModelRank) getPagodaRankListByFloorid(uid string, floorid int32) *pb.DBPagodaRecord { pagodaRank := make([]*pb.DBPagodaRecord, 0) err := this.GetList(uid, &pagodaRank) @@ -229,7 +98,7 @@ func (this *ModelRank) seasonSettlement() { Items []*pb.UserAssets ) - rd := pipe.ZRange("pagodaSeasonRank", 0, 50) + rd := pipe.ZRange("pagodaSeasonRank", 0, comm.MaxRankList) if _, err = pipe.Exec(); err != nil { this.modulePagoda.Errorln(err) @@ -254,6 +123,8 @@ func (this *ModelRank) seasonSettlement() { this.modulePagoda.mail.SendNewMail(&pb.DBMailData{ CreateTime: uint64(configure.Now().Unix()), Items: Items, + Cid: "SeasonPagodaReward", + Param: []string{strconv.Itoa(index)}, // 名次 }, uid) break } diff --git a/modules/timer/season.go b/modules/timer/season.go index bbad5be11..6c7388233 100644 --- a/modules/timer/season.go +++ b/modules/timer/season.go @@ -164,9 +164,28 @@ func (this *SeasonPagoda) TimerSeasonOver() { // 赛季塔开始 func (this *SeasonPagoda) TimerSeasonStar() { this.module.Debugf("TimerSeasonStar:%d", configure.Now().Unix()) - - // 打印耗时 //star := configure.Now() - this.DB.DeleteMany(comm.TableSeasonPagoda, bson.M{}, options.Delete()) + + if !db.IsCross() { // 删除本服的赛季塔数据 + conn, err := db.Cross() // 获取跨服的链接对象 + if err == nil { + model := db.NewDBModel(comm.TableServerData, 0, conn) + model.DB.DeleteMany(comm.TableSeasonPagoda, bson.M{}, options.Delete()) + model.DB.DeleteMany(comm.TableSeasonRecord, bson.M{}, options.Delete()) + for pos := 0; pos < comm.MaxRankNum; pos++ { + key1 := fmt.Sprintf("pagodaList%d", pos) + if err := model.Redis.Delete(key1); err != nil { + log.Errorf("delete failed") + } + } + + if err := model.Redis.Delete("pagodaSeasonRank"); err != nil { + log.Errorf("delete failed") + } + } + + this.DB.DeleteMany(comm.TableSeasonRecord, bson.M{}, options.Delete()) + + } //this.module.Debugf("=====%d,", time.Since(star).Milliseconds()) }