赛季结束清除赛季塔数据,根据排名奖励发送对应的奖励邮件

This commit is contained in:
meixiongfeng 2022-11-14 16:12:35 +08:00
parent 62f4b85ba6
commit bd9a503386
5 changed files with 37 additions and 139 deletions

View File

@ -432,7 +432,7 @@ const (
)
const (
MaxRankList = 50
MaxRankList = 50 // 赛季塔 排行榜人数
)
const (

View File

@ -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)
}

View File

@ -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 {

View File

@ -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
}

View File

@ -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())
}