go_dreamfactory/modules/pagoda/model_rank.go
2024-01-05 11:33:06 +08:00

85 lines
2.0 KiB
Go

package pagoda
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/sys/db"
//"go_dreamfactory/lego/sys/redis"
"go_dreamfactory/lego/sys/redis/pipe"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"github.com/go-redis/redis/v8"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/x/bsonx"
)
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)
//创建uid索引
this.DB.CreateIndex(core.SqlTable(comm.TablePagodaRecord), mongo.IndexModel{
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
})
return
}
func (this *ModelRank) getPagodaRankListByFloorid(uid string, cid int32) *pb.DBPagodaRecord {
pagodaRank := make([]*pb.DBPagodaRecord, 0)
if db.IsCross() {
if err := this.GetList(uid, &pagodaRank); err != nil {
return nil
}
} else {
if conn, err := db.Cross(); err == nil {
dbModel := db.NewDBModel(db.CrossTag(), comm.TablePagodaRecord, conn)
if err = dbModel.GetList(uid, &pagodaRank); err != nil {
return nil
}
}
}
for _, v := range pagodaRank {
if conf, err := this.modulePagoda.configure.GetPagodaConfigData(cid); err == nil {
if v.Tab == conf.Tab {
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
}
}