136 lines
3.1 KiB
Go
136 lines
3.1 KiB
Go
package pagoda
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"strconv"
|
|
|
|
//"go_dreamfactory/lego/sys/redis"
|
|
"go_dreamfactory/lego/sys/redis/pipe"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/configure"
|
|
"go_dreamfactory/sys/db"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
var floorRankKey = "pagoda:floor"
|
|
|
|
type ModelRank struct {
|
|
modules.MCompModel
|
|
modulePagoda *Pagoda
|
|
}
|
|
|
|
func (this *ModelRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TablePagodaRecord
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.modulePagoda = module.(*Pagoda)
|
|
return
|
|
}
|
|
|
|
func (this *ModelRank) GetRankData() (data []*pb.DBPagodaRecord, err error) {
|
|
data = make([]*pb.DBPagodaRecord, 0)
|
|
if conn, err := db.Cross(); err == nil {
|
|
err = conn.Redis.LRange(comm.TableSeasonRankList, 0, -1, &data)
|
|
}
|
|
//err = this.Redis.LRange(comm.TablePagodaRankList, 0, -1, &data)
|
|
|
|
return
|
|
}
|
|
func (this *ModelRank) getPagodaRankList(uid string) []*pb.DBPagodaRecord {
|
|
pagodaRank := make([]*pb.DBPagodaRecord, 0)
|
|
err := this.GetList(uid, &pagodaRank)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return pagodaRank
|
|
}
|
|
|
|
func (this *ModelRank) getPagodaRankListByFloorid(uid string, floorid int32) *pb.DBPagodaRecord {
|
|
pagodaRank := make([]*pb.DBPagodaRecord, 0)
|
|
err := this.GetList(uid, &pagodaRank)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
for _, v := range pagodaRank {
|
|
if v.PagodaId == floorid {
|
|
return v
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (this *ModelRank) SetNormalPagodaRankList(tableName string, score int32, uid string) {
|
|
|
|
var (
|
|
pipe *pipe.RedisPipe = this.DBModel.Redis.RedisPipe(context.TODO())
|
|
menbers *redis.Z
|
|
)
|
|
|
|
menbers = &redis.Z{Score: float64(score), Member: uid}
|
|
|
|
if cmd := pipe.ZAdd(tableName, menbers); cmd != nil {
|
|
|
|
dock, err1 := cmd.Result()
|
|
if err1 != nil {
|
|
this.modulePagoda.Errorln(dock, err1)
|
|
}
|
|
}
|
|
if _, err := pipe.Exec(); err != nil {
|
|
this.modulePagoda.Errorln(err)
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
func (this *ModelRank) seasonSettlement() {
|
|
rankReward := this.modulePagoda.configure.GetPagodaSeasonReward()
|
|
if rankReward == nil {
|
|
return
|
|
}
|
|
if !db.IsCross() {
|
|
if conn, err := db.Cross(); err == nil {
|
|
var (
|
|
pipe *pipe.RedisPipe = conn.Redis.RedisPipe(context.TODO())
|
|
Items []*pb.UserAssets
|
|
)
|
|
|
|
rd := pipe.ZRange("pagodaSeasonRank", 0, comm.MaxRankList)
|
|
|
|
if _, err = pipe.Exec(); err != nil {
|
|
this.modulePagoda.Errorln(err)
|
|
return
|
|
}
|
|
uids := rd.Val()
|
|
|
|
for index, uid := range uids {
|
|
Items = make([]*pb.UserAssets, 0) //TO 排名配置
|
|
for _, v := range rankReward {
|
|
if len(v.Ranking) != 2 {
|
|
continue
|
|
}
|
|
if index >= int(v.Ranking[0]) && index <= int(v.Ranking[1]) {
|
|
for _, v1 := range v.Reward {
|
|
Items = append(Items, &pb.UserAssets{
|
|
A: v1.A,
|
|
T: v1.T,
|
|
N: v1.N,
|
|
})
|
|
}
|
|
this.modulePagoda.mail.SendNewMail(&pb.DBMailData{
|
|
CreateTime: uint64(configure.Now().Unix()),
|
|
Items: Items,
|
|
Cid: "SeasonPagodaReward",
|
|
Param: []string{strconv.Itoa(index)}, // 名次
|
|
}, uid)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|