83 lines
1.9 KiB
Go
83 lines
1.9 KiB
Go
package enchant
|
|
|
|
import (
|
|
"context"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/redis/pipe"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/sys/db"
|
|
|
|
"github.com/go-redis/redis/v8"
|
|
)
|
|
|
|
type ModelRank struct {
|
|
modules.MCompModel
|
|
moduleHunting *Enchant
|
|
}
|
|
|
|
func (this *ModelRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
this.TableName = comm.TableHuntingRecord // 挑战记录
|
|
err = this.MCompModel.Init(service, module, comp, options)
|
|
this.moduleHunting = module.(*Enchant)
|
|
return
|
|
}
|
|
|
|
func (this *ModelRank) AddRankList(uId string, objId string, data *pb.DBHuntingRank) (err error) {
|
|
|
|
if err = this.AddList(uId, objId, data); err != nil {
|
|
return
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (this *ModelRank) getEnchantRankList(uid string) []*pb.DBHuntingRank {
|
|
ranks := make([]*pb.DBHuntingRank, 0)
|
|
err := this.GetList(uid, &ranks)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return ranks
|
|
}
|
|
|
|
func (this *ModelRank) getEnchantRankListByBossType(uid string, bossType int32) *pb.DBHuntingRank {
|
|
ranks := make([]*pb.DBHuntingRank, 0)
|
|
err := this.GetList(uid, &ranks)
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
for _, v := range ranks {
|
|
if v.Bosstype == bossType {
|
|
return v
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// 排行数据写跨服
|
|
func (this *ModelRank) SetRankListData(tableName string, score int32, uid string) {
|
|
if !db.IsCross() {
|
|
if conn, err := db.Cross(); err == nil {
|
|
var (
|
|
pipe *pipe.RedisPipe = conn.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.moduleHunting.Errorln(dock, err1)
|
|
}
|
|
}
|
|
if _, err := pipe.Exec(); err != nil {
|
|
this.moduleHunting.Errorln(err)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
}
|