Compare commits

...

2 Commits

Author SHA1 Message Date
sk c763d90325 Merge branch 'develop' of git.pogorockgames.com:mango-games/server/game into develop 2024-06-27 11:43:35 +08:00
sk bc3be9673d 新版邀请活动 2024-06-27 10:55:11 +08:00
4 changed files with 97 additions and 125 deletions

View File

@ -45,18 +45,18 @@ func init() {
} }
// 增加积分 // 增加积分
add := func(snid int32, score, money, rate int64) error { add := func(psnid, snid, level, tp int32, score, money, rate int64, addMoney bool) error {
if snid == 0 { if psnid <= 0 {
return nil return nil
} }
err = svc.AddInviteScore(log.Platform, snid, score*rate/10000, money, now) err = svc.AddInviteScore(log.Platform, psnid, snid, level, tp, score*rate/10000, rate, money, now, addMoney)
if err != nil { if err != nil {
logger.Logger.Errorf("EvtInvite add error:%v snid:%v score:%v rate:%v", err, snid, score, rate) logger.Logger.Errorf("EvtInvite add error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
return err return err
} }
msg, err := get(snid) msg, err := get(psnid)
if err != nil { if err != nil {
logger.Logger.Errorf("EvtInvite add find error:%v snid:%v score:%v rate:%v", err, snid, score, rate) logger.Logger.Errorf("EvtInvite add find error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
return err return err
} }
mq.Send(model.EvtInviteAck, msg) mq.Send(model.EvtInviteAck, msg)
@ -120,7 +120,7 @@ func init() {
var addRechargeScore bool var addRechargeScore bool
if log.Tp != common.InviteScoreCheckWeek { if log.Tp != common.InviteScoreCheckWeek {
addRechargeScore, err = svc.SaveInviteScore(&log.InviteScore, log.RechargeScore) addRechargeScore, err = svc.CheckInviteScore(&log.InviteScore)
if err != nil { if err != nil {
logger.Logger.Errorf("EvtInvite SaveInviteScore error:%v msg:%+v %+v", err, log.InviteScore, log) logger.Logger.Errorf("EvtInvite SaveInviteScore error:%v msg:%+v %+v", err, log.InviteScore, log)
return err return err
@ -143,7 +143,7 @@ func init() {
// 更新绑定数量 // 更新绑定数量
// 更新邀请积分 // 更新邀请积分
// 1.邀请人增加积分 // 1.邀请人增加积分
add(log.InviteSnId, log.Score, 0, 10000) add(log.InviteSnId, log.SnId, 0, log.Tp, log.Score, log.Money, 10000, false)
// 2.上级增加积分 // 2.上级增加积分
var psnid int32 var psnid int32
if len(log.Rate) > 0 { if len(log.Rate) > 0 {
@ -153,7 +153,7 @@ func init() {
return err return err
} }
if psnid > 0 { if psnid > 0 {
add(psnid, log.Score, 0, log.Rate[0]) add(psnid, log.InviteSnId, 1, log.Tp, log.Score, log.Money, log.Rate[0], false)
} }
} }
if len(log.Rate) > 1 && psnid > 0 { if len(log.Rate) > 1 && psnid > 0 {
@ -163,16 +163,16 @@ func init() {
return err return err
} }
if psnid > 0 { if psnid > 0 {
add(psnid, log.Score, 0, log.Rate[1]) add(psnid, log.InviteSnId, 2, log.Tp, log.Score, log.Money, log.Rate[1], false)
} }
} }
case common.InviteScoreTypePay: case common.InviteScoreTypePay:
// 更新充值积分,上级积分增加 // 更新充值积分,上级积分增加
add(log.SnId, log.Score, 0, 10000) add(log.SnId, 0, 0, log.Tp, log.Score, log.Money, 10000, false)
var psnid int32 var psnid int32
if len(log.Rate) > 0 { if len(log.Rate) > 0 {
add(log.InviteSnId, log.Score, log.Money, log.Rate[0]) add(log.InviteSnId, log.SnId, 1, log.Tp, log.Score, log.Money, log.Rate[0], true)
psnid, err = svc.GetPSnId(log.Platform, log.InviteSnId) psnid, err = svc.GetPSnId(log.Platform, log.InviteSnId)
if err != nil { if err != nil {
logger.Logger.Errorf("EvtInvite GetPSnId 3 error:%v snid:%v", err, log.InviteSnId) logger.Logger.Errorf("EvtInvite GetPSnId 3 error:%v snid:%v", err, log.InviteSnId)
@ -180,7 +180,7 @@ func init() {
} }
} }
if len(log.Rate) > 1 && psnid > 0 { if len(log.Rate) > 1 && psnid > 0 {
add(psnid, log.Score, 0, log.Rate[1]) add(psnid, log.SnId, 2, log.Tp, log.Score, log.Money, log.Rate[1], false)
psnid, err = svc.GetPSnId(log.Platform, psnid) psnid, err = svc.GetPSnId(log.Platform, psnid)
if err != nil { if err != nil {
logger.Logger.Errorf("EvtInvite GetPSnId 4 error:%v snid:%v", err, psnid) logger.Logger.Errorf("EvtInvite GetPSnId 4 error:%v snid:%v", err, psnid)
@ -188,18 +188,19 @@ func init() {
} }
} }
if len(log.Rate) > 2 && psnid > 0 { if len(log.Rate) > 2 && psnid > 0 {
add(psnid, log.Score, 0, log.Rate[2]) add(psnid, log.SnId, 3, log.Tp, log.Score, log.Money, log.Rate[2], false)
} }
if addRechargeScore { if addRechargeScore {
add(log.InviteSnId, log.RechargeScore, log.Money, 10000) add(log.InviteSnId, log.SnId, 0, common.InviteScoreTypeRecharge, log.RechargeScore, log.Money, 10000, true)
} }
case common.InviteScoreTypeRecharge: case common.InviteScoreTypeRecharge:
// 更新自己的积分 // 更新自己的积分
if addRechargeScore { if addRechargeScore {
add(log.InviteSnId, log.RechargeScore, log.Money, 10000) add(log.InviteSnId, log.SnId, 0, log.Tp, log.RechargeScore, log.Money, 10000, true)
} else { } else {
add(log.InviteSnId, 0, log.Money, 10000) // 只增加充值金额
add(log.InviteSnId, log.SnId, 0, log.Tp, 0, log.Money, 10000, true)
} }
case common.InviteScoreCheckWeek: case common.InviteScoreCheckWeek:

View File

@ -26,8 +26,9 @@ func InviteScoreCollection(plt string) *mongo.Collection {
if s != nil { if s != nil {
c, first := s.DB().C(InviteScoreCollName) c, first := s.DB().C(InviteScoreCollName)
if first { if first {
c.EnsureIndex(mgo.Index{Key: []string{"snid"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"upsnid"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"invitesnid"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"downsnid"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"level"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"tp"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"tp"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"ts"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"ts"}, Background: true, Sparse: true})
c.EnsureIndex(mgo.Index{Key: []string{"-ts"}, Background: true, Sparse: true}) c.EnsureIndex(mgo.Index{Key: []string{"-ts"}, Background: true, Sparse: true})
@ -43,31 +44,21 @@ func InviteScoreCollection(plt string) *mongo.Collection {
type BindScoreSvc struct { type BindScoreSvc struct {
} }
func SaveInviteScore(req *model.InviteScore, rechargeScore int64) (b bool, err error) { func CheckInviteScore(req *model.InviteScore) (b bool, err error) {
logger.Logger.Tracef("SaveInviteScore req:%+v", *req) logger.Logger.Tracef("SaveInviteScore req:%+v", *req)
if req.InviteSnId == 0 || req.SnId == 0 { if req.InviteSnId == 0 || req.SnId == 0 {
return false, nil return false, nil
} }
req.Id = bson.NewObjectId()
u := PlayerDataCollection(req.Platform) u := PlayerDataCollection(req.Platform)
if u == nil { if u == nil {
return false, PlayerColError return false, PlayerColError
} }
c := InviteScoreCollection(req.Platform)
if c == nil {
return false, InviteScoreColError
}
// 不能重复绑定 // 不能重复绑定
if req.Tp == common.InviteScoreTypeBind { if req.Tp == common.InviteScoreTypeBind {
a := &model.InviteScore{} psnid, err := GetPSnId(req.Platform, req.SnId)
err = c.Find(bson.M{"snid": req.SnId, "tp": common.InviteScoreTypeBind}).One(a) if err == nil && psnid > 0 {
if err != nil && !errors.Is(err, mgo.ErrNotFound) {
return false, errors.New("find error")
}
if err == nil && a.InviteSnId > 0 {
// 已经绑定 // 已经绑定
return false, errors.New("already bind") return false, errors.New("already bind")
} }
@ -75,11 +66,10 @@ func SaveInviteScore(req *model.InviteScore, rechargeScore int64) (b bool, err e
// 必须已经绑定 // 必须已经绑定
if req.Tp != common.InviteScoreTypeBind { if req.Tp != common.InviteScoreTypeBind {
a := &model.InviteScore{} psnid, err := GetPSnId(req.Platform, req.SnId)
err = c.Find(bson.M{"snid": req.SnId, "tp": common.InviteScoreTypeBind}).One(a) if err != nil || psnid == 0 {
if err != nil {
// 还没有绑定上级 // 还没有绑定上级
logger.Logger.Errorf("GetInviteScore Find BindTime error:%v", err) logger.Logger.Errorf("not bind error:%v", err)
return false, err return false, err
} }
} }
@ -87,83 +77,20 @@ func SaveInviteScore(req *model.InviteScore, rechargeScore int64) (b bool, err e
// 充值成功记录 // 充值成功记录
if req.Tp == common.InviteScoreTypePay || req.Tp == common.InviteScoreTypeRecharge { if req.Tp == common.InviteScoreTypePay || req.Tp == common.InviteScoreTypeRecharge {
// 是否已经记录过 // 是否已经记录过
a := &model.InviteScore{} c := InviteScoreCollection(req.Platform)
err = c.Find(bson.M{"snid": req.SnId, "tp": common.InviteScoreTypeRecharge}).One(a) if c == nil {
return false, InviteScoreColError
}
a := &model.LogInviteScore{}
err = c.Find(bson.M{"downsnid": req.SnId, "upsnid": req.InviteSnId, "tp": common.InviteScoreTypeRecharge}).One(a)
if err != nil && !errors.Is(err, mgo.ErrNotFound) { if err != nil && !errors.Is(err, mgo.ErrNotFound) {
return false, errors.New("find error") return false, errors.New("find error")
} }
if err == nil && a.InviteSnId > 0 { if err == nil && a.UpSnid > 0 {
// 已有记录
if req.Tp == common.InviteScoreTypeRecharge {
} else {
err = c.Insert(req)
if err != nil {
logger.Logger.Errorf("SaveInviteScore Insert 1 error:%v", err)
return false, err
}
// 自己加积分
err = c.Insert(&model.InviteScore{
Id: bson.NewObjectId(),
Platform: req.Platform,
SnId: req.SnId,
InviteSnId: req.InviteSnId,
Tp: common.InviteScoreTypePayMe,
Score: req.Score,
Ts: req.Ts,
Money: req.Money,
Rate: req.Rate,
})
if err != nil {
logger.Logger.Errorf("SaveInviteScore Insert me error:%v", err)
return false, err
}
}
} else { } else {
// 没有充值成功记录
err = c.Insert(req)
if err != nil {
logger.Logger.Errorf("SaveInviteScore Insert 2 error:%v", err)
return false, err
}
if req.Tp == common.InviteScoreTypePay {
// 自己加积分
err = c.Insert(&model.InviteScore{
Id: bson.NewObjectId(),
Platform: req.Platform,
SnId: req.SnId,
InviteSnId: req.InviteSnId,
Tp: common.InviteScoreTypePayMe,
Score: req.Score,
Ts: req.Ts,
Money: req.Money,
Rate: req.Rate,
})
if err != nil {
logger.Logger.Errorf("SaveInviteScore Insert me 2 error:%v", err)
return false, err
}
}
newReq := *req
if newReq.Tp != common.InviteScoreTypeRecharge {
newReq.Id = bson.NewObjectId()
newReq.Tp = common.InviteScoreTypeRecharge
newReq.Score = rechargeScore
err = c.Insert(newReq)
if err != nil {
logger.Logger.Errorf("SaveInviteScore InviteScoreTypeRecharge Insert error:%v", err)
return false, err
}
}
b = true b = true
} }
} else {
err = c.Insert(req)
if err != nil {
logger.Logger.Errorf("SaveInviteScore Insert 3 error:%v", err)
return false, err
}
} }
return b, nil return b, nil

View File

@ -334,13 +334,13 @@ func (svc *PlayerDataSvc) GetPlayerDataBySnId(args *model.GetPlayerDataBySnIdArg
if c == nil { if c == nil {
return return
} }
res := new(model.InviteScore) res := new(model.LogInviteScore)
c.Find(bson.M{"snid": args.SnId, "tp": common.InviteScoreTypeBind}).One(res) c.Find(bson.M{"downsnid": args.SnId, "tp": common.InviteScoreTypeBind}).One(res)
param := bson.M{} param := bson.M{}
if res.InviteSnId > 0 { if res.UpSnid > 0 {
p.PSnId = res.InviteSnId p.PSnId = int32(res.UpSnid)
param["psnid"] = res.InviteSnId param["psnid"] = p.PSnId
code, _ := GetCodeBySnId(args.Plt, res.InviteSnId) code, _ := GetCodeBySnId(args.Plt, p.PSnId)
if code != "" { if code != "" {
p.PCode = code p.PCode = code
param["pcode"] = code param["pcode"] = code
@ -1582,14 +1582,46 @@ func ClearInviteScore(platform string, snId int32, now time.Time) error {
return nil return nil
} }
func AddInviteScore(platform string, snId int32, num, money int64, now time.Time) error { func AddInviteScore(platform string, psnId, snid, level, tp int32, num, rate, money int64, now time.Time, addMoney bool) error {
logger.Logger.Tracef("AddInviteScore ==> platform %v, psnId %v, snid %v, level %v, tp %v, num %v, rate %v, money %v, now %v, addMoney %v",
platform, psnId, snid, level, tp, num, rate, money, now, addMoney)
i := InviteScoreCollection(platform)
if i == nil {
return InviteScoreColError
}
id := bson.NewObjectId()
err := i.Insert(&model.LogInviteScore{
Id: id,
Platform: platform,
UpSnid: psnId,
DownSnid: snid,
Level: level,
Tp: tp,
Rate: rate,
Score: num,
Money: money,
Ts: now.Unix(),
})
if err != nil {
logger.Logger.Error("AddInviteScore LogInviteScore error ", err)
return err
}
c := PlayerDataCollection(platform) c := PlayerDataCollection(platform)
if c == nil { if c == nil {
return PlayerColError return PlayerColError
} }
err := c.Update(bson.M{"snid": snId}, bson.M{"$inc": bson.M{"iscore": num, "imoney": money}, "$set": bson.M{"iscorets": now}}) myMoney := money
if !addMoney {
myMoney = 0
}
err = c.Update(bson.M{"snid": psnId}, bson.M{"$inc": bson.M{"iscore": num, "imoney": myMoney}, "$set": bson.M{"iscorets": now}})
if err != nil { if err != nil {
i.RemoveId(id)
logger.Logger.Error("AddInviteScore error ", err) logger.Logger.Error("AddInviteScore error ", err)
return err return err
} }
@ -1600,7 +1632,7 @@ func AddInviteScore(platform string, snId int32, num, money int64, now time.Time
INum int64 INum int64
} }
res := &m{} res := &m{}
err = c.Find(bson.M{"snid": snId}).Select(bson.M{"iscore": 1, "inum": 1}).One(res) err = c.Find(bson.M{"snid": psnId}).Select(bson.M{"iscore": 1, "inum": 1}).One(res)
if err != nil { if err != nil {
logger.Logger.Error("AddInviteScore find error ", err) logger.Logger.Error("AddInviteScore find error ", err)
return err return err
@ -1608,7 +1640,7 @@ func AddInviteScore(platform string, snId int32, num, money int64, now time.Time
SaveRankInvite(&model.RankInvite{ SaveRankInvite(&model.RankInvite{
Platform: platform, Platform: platform,
SnId: snId, SnId: psnId,
Num: res.INum, Num: res.INum,
Score: res.IScore, Score: res.IScore,
Ts: now.Unix(), Ts: now.Unix(),

View File

@ -47,15 +47,14 @@ func GetSnIdByCode(platform string, code string) (int32, error) {
// InviteScore 积分记录 // InviteScore 积分记录
type InviteScore struct { type InviteScore struct {
Id bson.ObjectId `bson:"_id"` Platform string // 平台id
Platform string `bson:"-"` // 平台id SnId int32 // 被邀请人id
SnId int32 // 被邀请人id InviteSnId int32 // 邀请人id
InviteSnId int32 // 邀请人id Tp int32 // 积分类型 common.InviteScoreType ~
Tp int32 // 积分类型 common.InviteScoreType ~ Score int64 // 积分
Score int64 // 积分 Ts int64 // 时间戳
Ts int64 // 时间戳 Money int64 // 充值金额
Money int64 // 充值金额 Rate []int64 // 返佣比例
Rate []int64 // 返佣比例
} }
// 邀请消息 // 邀请消息
@ -119,3 +118,16 @@ type RankInvite struct {
Ts int64 Ts int64
Week int64 Week int64
} }
type LogInviteScore struct {
Id bson.ObjectId `bson:"_id"`
Platform string `bson:"-"` // 平台id
UpSnid int32 // 上级代理
DownSnid int32 // 下级代理
Level int32 // 代理层级 例如 1DownSnid 是 UpSnid 的 1 级代理; 2: DownSnid 是 UpSnid 的 2 级代理
Tp int32 // 返佣类型
Rate int64 // 返佣比例
Score int64 // 积分
Money int64 // 充值金额
Ts int64 // 时间戳
}