81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
package viking
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/redis/pipe"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
"strconv"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) SeasonRankCheck(session comm.IUserSession, req *pb.VikingSeasonRankReq) (errdata *pb.ErrorData) {
|
|
if req.BoosType == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) SeasonRank(session comm.IUserSession, req *pb.VikingSeasonRankReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
szRank []*pb.DBVSeasonRank
|
|
rd *redis.StringSliceCmd
|
|
conn *db.DBConn
|
|
pipe *pipe.RedisPipe
|
|
err error
|
|
endSeasonTime int64
|
|
bCross bool // 是否是跨服
|
|
)
|
|
if errdata = this.SeasonRankCheck(session, req); errdata != nil {
|
|
return // 参数校验失败直接返回
|
|
}
|
|
if bCross, endSeasonTime = this.module.CheckCurSeasonData(); bCross {
|
|
conn, err = db.Local()
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
conn, _ = db.Cross()
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
dbModel := db.NewDBModelByExpired(comm.TableVikingSRank, conn)
|
|
|
|
pipe = conn.Redis.RedisPipe(context.TODO())
|
|
rd = pipe.ZRevRange("vSeasonRank"+strconv.Itoa(int(req.BoosType)), 0, comm.MaxRankList)
|
|
|
|
if _, err := pipe.Exec(); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
_dataList := rd.Val()
|
|
for _, v := range _dataList {
|
|
result := &pb.DBVSeasonRank{}
|
|
if err := dbModel.Redis.HGetAll(v, result); err == nil {
|
|
szRank = append(szRank, result)
|
|
}
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), VikingSeasonRankReq, &pb.VikingSeasonRankResp{
|
|
Ranks: szRank,
|
|
Etime: endSeasonTime,
|
|
})
|
|
return
|
|
}
|