122 lines
2.5 KiB
Go
122 lines
2.5 KiB
Go
package model
|
|
|
|
import (
|
|
"errors"
|
|
"time"
|
|
|
|
"github.com/globalsign/mgo/bson"
|
|
|
|
"mongo.games.com/goserver/core/logger"
|
|
)
|
|
|
|
type InviteCode struct {
|
|
Id bson.ObjectId `bson:"_id"`
|
|
SnId int32
|
|
Code string
|
|
}
|
|
|
|
type InviteSnIdReq struct {
|
|
Platform string
|
|
Code string
|
|
}
|
|
|
|
type InviteSnIdRet struct {
|
|
SnId int32
|
|
}
|
|
|
|
// GetSnIdByCode 根据邀请码获取被邀请人id
|
|
func GetSnIdByCode(platform string, code string) (int32, error) {
|
|
if rpcCli == nil {
|
|
logger.Logger.Warnf("rpcCli is nil")
|
|
return 0, errors.New("rpcCli is nil")
|
|
}
|
|
|
|
req := &InviteSnIdReq{
|
|
Platform: platform,
|
|
Code: code,
|
|
}
|
|
ret := &InviteSnIdRet{}
|
|
err := rpcCli.CallWithTimeout("InviteCodeSvc.GetSnIdByCode", req, ret, time.Second*30)
|
|
if err != nil {
|
|
logger.Logger.Warnf("GetSnIdByCode err:%v", err)
|
|
return 0, err
|
|
}
|
|
|
|
return ret.SnId, err
|
|
}
|
|
|
|
// InviteScore 积分记录
|
|
type InviteScore struct {
|
|
Id bson.ObjectId `bson:"_id"`
|
|
Platform string `bson:"-"` // 平台id
|
|
SnId int32 // 被邀请人id
|
|
InviteSnId int32 // 邀请人id
|
|
Tp int32 // 积分类型 common.InviteScoreType ~
|
|
Score int64 // 积分
|
|
Ts int64 // 时间戳
|
|
Money int64 // 充值金额
|
|
Rate []int64 // 返佣比例
|
|
}
|
|
|
|
// 邀请消息
|
|
const EvtInvite = "evt_invite" // 绑定邀请人 worldsrv -> dbproxy
|
|
type EvtInviteMsg struct {
|
|
InviteScore
|
|
RechargeScore int64 // 充值成功积分
|
|
}
|
|
|
|
const EvtInviteAck = "evt_invite_ack" // 绑定邀请人 dbproxy -> worldsrv
|
|
type EvtInviteAckMsg struct {
|
|
Platform string
|
|
Snid int32
|
|
Score int64
|
|
Money int64
|
|
Num int64
|
|
}
|
|
|
|
type InviteLisArgs struct {
|
|
Platform string
|
|
SnId int32
|
|
}
|
|
|
|
type InviteInfo struct {
|
|
Name string
|
|
SnId int32
|
|
CreateTs int64
|
|
Score int64
|
|
ModId int32
|
|
}
|
|
|
|
type InviteListRet struct {
|
|
List []*InviteInfo
|
|
}
|
|
|
|
// GetInviteList 获取邀请人列表
|
|
func GetInviteList(platform string, snid int32) ([]*InviteInfo, error) {
|
|
if rpcCli == nil {
|
|
logger.Logger.Error("model.GetInviteList rpcCli == nil")
|
|
return nil, nil
|
|
}
|
|
|
|
req := &InviteLisArgs{
|
|
Platform: platform,
|
|
SnId: snid,
|
|
}
|
|
ret := new(InviteListRet)
|
|
err := rpcCli.CallWithTimeout("BindScoreSvc.GetInviteList", req, ret, time.Second*30)
|
|
if err != nil {
|
|
logger.Logger.Error("GetInviteList error:", err)
|
|
return nil, err
|
|
}
|
|
return ret.List, nil
|
|
}
|
|
|
|
type RankInvite struct {
|
|
Platform string `bson:"-"`
|
|
SnId int32
|
|
Num int64
|
|
Score int64
|
|
Ts int64
|
|
Week int64
|
|
}
|