修改邀请绑定数量

This commit is contained in:
sk 2024-07-14 15:20:56 +08:00
parent 41361621ef
commit c72b74824e
6 changed files with 191 additions and 22 deletions

View File

@ -22,5 +22,6 @@
"RobotInviteIntervalMax": 1,
"ClosePreCreateRoom": true,
"AgoraAddress": "http://47.105.78.29:8081",
"InviteUrl": "http://47.105.78.29:8000/"
"InviteUrl": "http://47.105.78.29:8000/",
"RankTimeout": 5
}

View File

@ -13,6 +13,7 @@ import (
"mongo.games.com/game/dbproxy/svc"
"mongo.games.com/game/model"
"mongo.games.com/game/mq"
rankproto "mongo.games.com/game/protocol/rank"
)
var InviteNumCache = cache.NewMemoryCache()
@ -44,7 +45,7 @@ func init() {
if n > 0 {
n++
} else {
n, err = svc.GetInviteNum(log.Platform, log.InviteSnId)
n, err = svc.GetInviteNum(log.Platform, log.InviteSnId, int32(rankproto.RankInvite_InviteType_Total))
if err != nil {
logger.Logger.Errorf("BindInviteSnId error:%v", err)
return err

View File

@ -269,7 +269,7 @@ func (b *BindScoreSvc) GetInviteRankList(req *model.FindPlayerRankInviteListArgs
}
RankInvite.ModId = int32(roleId)
RankInvite.InviteNum, _ = GetInviteNum(req.Platform, inviteInfo.InviteSnId)
RankInvite.InviteNum, _ = GetInviteNum(req.Platform, inviteInfo.InviteSnId, req.RankType)
ret.List = append(ret.List, &RankInvite)
break
@ -282,6 +282,86 @@ func (b *BindScoreSvc) GetInviteRankList(req *model.FindPlayerRankInviteListArgs
return nil
}
func (b *BindScoreSvc) GetInviteScoreByType(req *model.FindPlayerRankInviteScoreArgs, ret *model.FindPlayerRankInviteScoreReply) error {
c := InviteScoreCollection(req.Platform)
if c == nil {
return InviteScoreColError
}
matchParam := bson.M{
"invitesnid": req.SnId,
"score": bson.M{"$gt": 0},
}
now := time.Now().Local()
startTime := now.AddDate(-100, 0, 0).UnixNano()
year, month, day := now.Date()
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
if req.RankType == int32(rankproto.RankInvite_InviteType_Week) {
// 本周起始日期(周日)
matchParam["weekindex"] = today.AddDate(0, 0, -int(today.Weekday())).Unix()
} else if req.RankType == int32(rankproto.RankInvite_InviteType_Month) {
// 本月起始日期
matchParam["monthindex"] = time.Date(year, month, 1, 0, 0, 0, 0, time.Local).Unix()
} else {
matchParam["ts"] = bson.M{"$gte": startTime, "$lte": now.UnixNano()}
}
type M struct {
InviteSnId int32 // 邀请人id
Score int64 // 积分
}
var tc []M
err := c.Pipe([]bson.M{
{"$match": matchParam},
{"$group": bson.M{
"_id": nil,
"invitesnid": bson.M{"$first": "$invitesnid"},
"score": bson.M{"$sum": "$score"},
}},
}).AllowDiskUse().All(&tc)
if err != nil {
logger.Logger.Error("GetInviteScoreByType z AllowDiskUse is error", err)
return err
}
type PInfo struct {
SnId int32
Name string // 昵称
Roles *model.RolePetInfo
}
var retPlayer PInfo
u := PlayerDataCollection(req.Platform)
if u == nil {
return err
}
err = u.Find(bson.M{"snid": req.SnId}).Select(bson.M{"snid": 1, "name": 1, "roles": 1}).One(&retPlayer)
if err != nil {
logger.Logger.Error("svc.GetInviteScoreByType is error", err)
return nil
}
var rankInvite model.PlayerRankInvite
rankInvite.Name = retPlayer.Name
if len(tc) > 0 {
rankInvite.Score = tc[0].Score
}
rankInvite.SnId = req.SnId
// 头像模型ID
roleId := common.DefaultRoleId
if retPlayer.Roles != nil {
roleId = int(retPlayer.Roles.ModId)
}
rankInvite.ModId = int32(roleId)
rankInvite.InviteNum, _ = GetInviteNum(req.Platform, req.SnId, req.RankType)
ret.Data = rankInvite
ret.RankType = req.RankType
return nil
}
func (b *BindScoreSvc) GetInviteList(req *model.InviteLisArgs, ret *model.InviteListRet) error {
c := InviteScoreCollection(req.Platform)
if c == nil {

View File

@ -12,13 +12,16 @@ import (
"time"
"mongo.games.com/goserver/core/basic"
"mongo.games.com/goserver/core/logger"
"mongo.games.com/goserver/core/task"
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
"mongo.games.com/game/common"
"mongo.games.com/game/dbproxy/mongo"
"mongo.games.com/game/model"
"mongo.games.com/goserver/core/logger"
rankproto "mongo.games.com/game/protocol/rank"
)
var (
@ -1509,7 +1512,7 @@ func (svc *PlayerDataSvc) GetPlayerInviteSnid(req *model.PlayerIsExistBySnIdArgs
}
func (svc *PlayerDataSvc) GetInviteNum(req *model.PlayerIsExistBySnIdArgs, resp *int32) error {
n, err := GetInviteNum(req.Plt, req.SnId)
n, err := GetInviteNum(req.Plt, req.SnId, int32(rankproto.RankInvite_InviteType_Total))
if err != nil {
return err
}
@ -1517,15 +1520,43 @@ func (svc *PlayerDataSvc) GetInviteNum(req *model.PlayerIsExistBySnIdArgs, resp
return nil
}
func GetInviteNum(platform string, snId int32) (int32, error) {
c := PlayerDataCollection(platform)
if c == nil {
return 0, PlayerColError
}
func GetInviteNum(platform string, snId int32, rankType int32) (int32, error) {
var err error
var n int
switch rankType {
case int32(rankproto.RankInvite_InviteType_Week), int32(rankproto.RankInvite_InviteType_Month):
matchParam := bson.M{
"invitesnid": snId,
"tp": common.InviteScoreTypeBind,
}
now := time.Now().Local()
year, month, day := now.Date()
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
if rankType == int32(rankproto.RankInvite_InviteType_Week) {
// 本周起始日期(周日)
matchParam["weekindex"] = today.AddDate(0, 0, -int(today.Weekday())).Unix()
} else if rankType == int32(rankproto.RankInvite_InviteType_Month) {
// 本月起始日期
matchParam["monthindex"] = time.Date(year, month, 1, 0, 0, 0, 0, time.Local).Unix()
}
c := InviteScoreCollection(platform)
if c == nil {
return 0, InviteScoreColError
}
n, err = c.Find(matchParam).Count()
if err != nil {
return 0, err
}
n, err := c.Find(bson.M{"invitesnid": snId}).Count()
if err != nil {
return 0, err
default:
c := PlayerDataCollection(platform)
if c == nil {
return 0, PlayerColError
}
n, err = c.Find(bson.M{"invitesnid": snId}).Count()
if err != nil {
return 0, err
}
}
return int32(n), nil

View File

@ -154,6 +154,32 @@ func FindPlayerRankInviteList(args *FindPlayerRankInviteListArgs) (*FindPlayerRa
return ret, nil
}
type FindPlayerRankInviteScoreArgs struct {
Platform string
RankType int32 // 邀请榜时间类型: 总榜 周榜 月榜
SnId int32
}
type FindPlayerRankInviteScoreReply struct {
RankType int32 // 邀请榜时间类型: 总榜 周榜 月榜
Data PlayerRankInvite
}
func FindPlayerRankInviteScoreType(args *FindPlayerRankInviteScoreArgs) (*FindPlayerRankInviteScoreReply, error) {
if rpcCli == nil {
logger.Logger.Error("model.FindPlayerRankInviteScoreType rpcCli == nil")
return nil, nil
}
ret := new(FindPlayerRankInviteScoreReply)
err := rpcCli.CallWithTimeout("BindScoreSvc.GetInviteScoreByType", args, ret, time.Second*30)
if err != nil {
logger.Logger.Error("FindPlayerRankInviteScoreType error:", err)
return ret, err
}
return ret, nil
}
type WinCoinInfo struct {
SnId int32
Name string

View File

@ -236,17 +236,47 @@ func CSInvite(s *netlib.Session, d *rankproto.GateTransmit, packetId int, data i
}
}
pack := &rankproto.SCInvite{
Id: msg.GetId(),
Ranks: ranks,
Me: me,
Skip: msg.GetSkip(),
IsEndNum: IsEndNum,
RankMaxNum: model.GameParamData.RankInviteMaxNum,
f := func() {
pack := &rankproto.SCInvite{
Id: msg.GetId(),
Ranks: ranks,
Me: me,
Skip: msg.GetSkip(),
IsEndNum: IsEndNum,
RankMaxNum: model.GameParamData.RankInviteMaxNum,
}
common.SendToGate(sid, int(rankproto.Rank_PACKET_RANK_SCInvite), pack, s)
logger.Logger.Tracef("SCInvite: %v", pack)
}
common.SendToGate(sid, int(rankproto.Rank_PACKET_RANK_SCInvite), pack, s)
logger.Logger.Tracef("SCInvite: %v", pack)
// 查询自己
if me == nil {
task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} {
r, err := model.FindPlayerRankInviteScoreType(&model.FindPlayerRankInviteScoreArgs{
Platform: d.Platform,
RankType: msg.GetId(),
SnId: d.Snid,
})
if err != nil || r == nil {
logger.Logger.Errorf("FindPlayerRankInviteScoreType error: %v", err)
return nil
}
me = &rankproto.InviteRank{
Snid: r.Data.SnId,
Name: r.Data.Name,
Rank: model.GameParamData.RankInviteMaxNum,
Score: r.Data.Score,
InviteNum: r.Data.InviteNum,
ModId: r.Data.ModId,
}
return nil
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
f()
}), "rank_invite_me").Start()
} else {
f()
}
})
return nil
}