Compare commits
No commits in common. "c763d90325c3f711cc60ee8dce060b3ad0b3a2db" and "b9ef093b1814a37fe06a83e6ee910f1e32325750" have entirely different histories.
c763d90325
...
b9ef093b18
|
@ -45,18 +45,18 @@ func init() {
|
|||
}
|
||||
|
||||
// 增加积分
|
||||
add := func(psnid, snid, level, tp int32, score, money, rate int64, addMoney bool) error {
|
||||
if psnid <= 0 {
|
||||
add := func(snid int32, score, money, rate int64) error {
|
||||
if snid == 0 {
|
||||
return nil
|
||||
}
|
||||
err = svc.AddInviteScore(log.Platform, psnid, snid, level, tp, score*rate/10000, rate, money, now, addMoney)
|
||||
err = svc.AddInviteScore(log.Platform, snid, score*rate/10000, money, now)
|
||||
if err != nil {
|
||||
logger.Logger.Errorf("EvtInvite add error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
|
||||
logger.Logger.Errorf("EvtInvite add error:%v snid:%v score:%v rate:%v", err, snid, score, rate)
|
||||
return err
|
||||
}
|
||||
msg, err := get(psnid)
|
||||
msg, err := get(snid)
|
||||
if err != nil {
|
||||
logger.Logger.Errorf("EvtInvite add find error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
|
||||
logger.Logger.Errorf("EvtInvite add find error:%v snid:%v score:%v rate:%v", err, snid, score, rate)
|
||||
return err
|
||||
}
|
||||
mq.Send(model.EvtInviteAck, msg)
|
||||
|
@ -120,7 +120,7 @@ func init() {
|
|||
|
||||
var addRechargeScore bool
|
||||
if log.Tp != common.InviteScoreCheckWeek {
|
||||
addRechargeScore, err = svc.CheckInviteScore(&log.InviteScore)
|
||||
addRechargeScore, err = svc.SaveInviteScore(&log.InviteScore, log.RechargeScore)
|
||||
if err != nil {
|
||||
logger.Logger.Errorf("EvtInvite SaveInviteScore error:%v msg:%+v %+v", err, log.InviteScore, log)
|
||||
return err
|
||||
|
@ -143,7 +143,7 @@ func init() {
|
|||
// 更新绑定数量
|
||||
// 更新邀请积分
|
||||
// 1.邀请人增加积分
|
||||
add(log.InviteSnId, log.SnId, 0, log.Tp, log.Score, log.Money, 10000, false)
|
||||
add(log.InviteSnId, log.Score, 0, 10000)
|
||||
// 2.上级增加积分
|
||||
var psnid int32
|
||||
if len(log.Rate) > 0 {
|
||||
|
@ -153,7 +153,7 @@ func init() {
|
|||
return err
|
||||
}
|
||||
if psnid > 0 {
|
||||
add(psnid, log.InviteSnId, 1, log.Tp, log.Score, log.Money, log.Rate[0], false)
|
||||
add(psnid, log.Score, 0, log.Rate[0])
|
||||
}
|
||||
}
|
||||
if len(log.Rate) > 1 && psnid > 0 {
|
||||
|
@ -163,16 +163,16 @@ func init() {
|
|||
return err
|
||||
}
|
||||
if psnid > 0 {
|
||||
add(psnid, log.InviteSnId, 2, log.Tp, log.Score, log.Money, log.Rate[1], false)
|
||||
add(psnid, log.Score, 0, log.Rate[1])
|
||||
}
|
||||
}
|
||||
|
||||
case common.InviteScoreTypePay:
|
||||
// 更新充值积分,上级积分增加
|
||||
add(log.SnId, 0, 0, log.Tp, log.Score, log.Money, 10000, false)
|
||||
add(log.SnId, log.Score, 0, 10000)
|
||||
var psnid int32
|
||||
if len(log.Rate) > 0 {
|
||||
add(log.InviteSnId, log.SnId, 1, log.Tp, log.Score, log.Money, log.Rate[0], true)
|
||||
add(log.InviteSnId, log.Score, log.Money, log.Rate[0])
|
||||
psnid, err = svc.GetPSnId(log.Platform, log.InviteSnId)
|
||||
if err != nil {
|
||||
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 {
|
||||
add(psnid, log.SnId, 2, log.Tp, log.Score, log.Money, log.Rate[1], false)
|
||||
add(psnid, log.Score, 0, log.Rate[1])
|
||||
psnid, err = svc.GetPSnId(log.Platform, psnid)
|
||||
if err != nil {
|
||||
logger.Logger.Errorf("EvtInvite GetPSnId 4 error:%v snid:%v", err, psnid)
|
||||
|
@ -188,19 +188,18 @@ func init() {
|
|||
}
|
||||
}
|
||||
if len(log.Rate) > 2 && psnid > 0 {
|
||||
add(psnid, log.SnId, 3, log.Tp, log.Score, log.Money, log.Rate[2], false)
|
||||
add(psnid, log.Score, 0, log.Rate[2])
|
||||
}
|
||||
if addRechargeScore {
|
||||
add(log.InviteSnId, log.SnId, 0, common.InviteScoreTypeRecharge, log.RechargeScore, log.Money, 10000, true)
|
||||
add(log.InviteSnId, log.RechargeScore, log.Money, 10000)
|
||||
}
|
||||
|
||||
case common.InviteScoreTypeRecharge:
|
||||
// 更新自己的积分
|
||||
if addRechargeScore {
|
||||
add(log.InviteSnId, log.SnId, 0, log.Tp, log.RechargeScore, log.Money, 10000, true)
|
||||
add(log.InviteSnId, log.RechargeScore, log.Money, 10000)
|
||||
} else {
|
||||
// 只增加充值金额
|
||||
add(log.InviteSnId, log.SnId, 0, log.Tp, 0, log.Money, 10000, true)
|
||||
add(log.InviteSnId, 0, log.Money, 10000)
|
||||
}
|
||||
|
||||
case common.InviteScoreCheckWeek:
|
||||
|
|
|
@ -26,9 +26,8 @@ func InviteScoreCollection(plt string) *mongo.Collection {
|
|||
if s != nil {
|
||||
c, first := s.DB().C(InviteScoreCollName)
|
||||
if first {
|
||||
c.EnsureIndex(mgo.Index{Key: []string{"upsnid"}, 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{"snid"}, Background: true, Sparse: true})
|
||||
c.EnsureIndex(mgo.Index{Key: []string{"invitesnid"}, 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})
|
||||
|
@ -44,21 +43,31 @@ func InviteScoreCollection(plt string) *mongo.Collection {
|
|||
type BindScoreSvc struct {
|
||||
}
|
||||
|
||||
func CheckInviteScore(req *model.InviteScore) (b bool, err error) {
|
||||
func SaveInviteScore(req *model.InviteScore, rechargeScore int64) (b bool, err error) {
|
||||
logger.Logger.Tracef("SaveInviteScore req:%+v", *req)
|
||||
if req.InviteSnId == 0 || req.SnId == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
req.Id = bson.NewObjectId()
|
||||
u := PlayerDataCollection(req.Platform)
|
||||
if u == nil {
|
||||
return false, PlayerColError
|
||||
}
|
||||
|
||||
c := InviteScoreCollection(req.Platform)
|
||||
if c == nil {
|
||||
return false, InviteScoreColError
|
||||
}
|
||||
|
||||
// 不能重复绑定
|
||||
if req.Tp == common.InviteScoreTypeBind {
|
||||
psnid, err := GetPSnId(req.Platform, req.SnId)
|
||||
if err == nil && psnid > 0 {
|
||||
a := &model.InviteScore{}
|
||||
err = c.Find(bson.M{"snid": req.SnId, "tp": common.InviteScoreTypeBind}).One(a)
|
||||
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")
|
||||
}
|
||||
|
@ -66,10 +75,11 @@ func CheckInviteScore(req *model.InviteScore) (b bool, err error) {
|
|||
|
||||
// 必须已经绑定
|
||||
if req.Tp != common.InviteScoreTypeBind {
|
||||
psnid, err := GetPSnId(req.Platform, req.SnId)
|
||||
if err != nil || psnid == 0 {
|
||||
a := &model.InviteScore{}
|
||||
err = c.Find(bson.M{"snid": req.SnId, "tp": common.InviteScoreTypeBind}).One(a)
|
||||
if err != nil {
|
||||
// 还没有绑定上级
|
||||
logger.Logger.Errorf("not bind error:%v", err)
|
||||
logger.Logger.Errorf("GetInviteScore Find BindTime error:%v", err)
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
@ -77,20 +87,83 @@ func CheckInviteScore(req *model.InviteScore) (b bool, err error) {
|
|||
// 充值成功记录
|
||||
if req.Tp == common.InviteScoreTypePay || req.Tp == common.InviteScoreTypeRecharge {
|
||||
// 是否已经记录过
|
||||
c := InviteScoreCollection(req.Platform)
|
||||
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)
|
||||
a := &model.InviteScore{}
|
||||
err = c.Find(bson.M{"snid": req.SnId, "tp": common.InviteScoreTypeRecharge}).One(a)
|
||||
if err != nil && !errors.Is(err, mgo.ErrNotFound) {
|
||||
return false, errors.New("find error")
|
||||
}
|
||||
if err == nil && a.UpSnid > 0 {
|
||||
if err == nil && a.InviteSnId > 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 {
|
||||
// 没有充值成功记录
|
||||
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
|
||||
}
|
||||
} else {
|
||||
err = c.Insert(req)
|
||||
if err != nil {
|
||||
logger.Logger.Errorf("SaveInviteScore Insert 3 error:%v", err)
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
return b, nil
|
||||
|
|
|
@ -334,13 +334,13 @@ func (svc *PlayerDataSvc) GetPlayerDataBySnId(args *model.GetPlayerDataBySnIdArg
|
|||
if c == nil {
|
||||
return
|
||||
}
|
||||
res := new(model.LogInviteScore)
|
||||
c.Find(bson.M{"downsnid": args.SnId, "tp": common.InviteScoreTypeBind}).One(res)
|
||||
res := new(model.InviteScore)
|
||||
c.Find(bson.M{"snid": args.SnId, "tp": common.InviteScoreTypeBind}).One(res)
|
||||
param := bson.M{}
|
||||
if res.UpSnid > 0 {
|
||||
p.PSnId = int32(res.UpSnid)
|
||||
param["psnid"] = p.PSnId
|
||||
code, _ := GetCodeBySnId(args.Plt, p.PSnId)
|
||||
if res.InviteSnId > 0 {
|
||||
p.PSnId = res.InviteSnId
|
||||
param["psnid"] = res.InviteSnId
|
||||
code, _ := GetCodeBySnId(args.Plt, res.InviteSnId)
|
||||
if code != "" {
|
||||
p.PCode = code
|
||||
param["pcode"] = code
|
||||
|
@ -1582,46 +1582,14 @@ func ClearInviteScore(platform string, snId int32, now time.Time) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func AddInviteScore(platform string, snId int32, num, money int64, now time.Time) error {
|
||||
c := PlayerDataCollection(platform)
|
||||
if c == nil {
|
||||
return PlayerColError
|
||||
}
|
||||
|
||||
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}})
|
||||
err := c.Update(bson.M{"snid": snId}, bson.M{"$inc": bson.M{"iscore": num, "imoney": money}, "$set": bson.M{"iscorets": now}})
|
||||
if err != nil {
|
||||
i.RemoveId(id)
|
||||
logger.Logger.Error("AddInviteScore error ", err)
|
||||
return err
|
||||
}
|
||||
|
@ -1632,7 +1600,7 @@ func AddInviteScore(platform string, psnId, snid, level, tp int32, num, rate, mo
|
|||
INum int64
|
||||
}
|
||||
res := &m{}
|
||||
err = c.Find(bson.M{"snid": psnId}).Select(bson.M{"iscore": 1, "inum": 1}).One(res)
|
||||
err = c.Find(bson.M{"snid": snId}).Select(bson.M{"iscore": 1, "inum": 1}).One(res)
|
||||
if err != nil {
|
||||
logger.Logger.Error("AddInviteScore find error ", err)
|
||||
return err
|
||||
|
@ -1640,7 +1608,7 @@ func AddInviteScore(platform string, psnId, snid, level, tp int32, num, rate, mo
|
|||
|
||||
SaveRankInvite(&model.RankInvite{
|
||||
Platform: platform,
|
||||
SnId: psnId,
|
||||
SnId: snId,
|
||||
Num: res.INum,
|
||||
Score: res.IScore,
|
||||
Ts: now.Unix(),
|
||||
|
|
|
@ -47,14 +47,15 @@ func GetSnIdByCode(platform string, code string) (int32, error) {
|
|||
|
||||
// InviteScore 积分记录
|
||||
type InviteScore struct {
|
||||
Platform string // 平台id
|
||||
SnId int32 // 被邀请人id
|
||||
InviteSnId int32 // 邀请人id
|
||||
Tp int32 // 积分类型 common.InviteScoreType ~
|
||||
Score int64 // 积分
|
||||
Ts int64 // 时间戳
|
||||
Money int64 // 充值金额
|
||||
Rate []int64 // 返佣比例
|
||||
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 // 返佣比例
|
||||
}
|
||||
|
||||
// 邀请消息
|
||||
|
@ -118,16 +119,3 @@ type RankInvite struct {
|
|||
Ts int64
|
||||
Week int64
|
||||
}
|
||||
|
||||
type LogInviteScore struct {
|
||||
Id bson.ObjectId `bson:"_id"`
|
||||
Platform string `bson:"-"` // 平台id
|
||||
UpSnid int32 // 上级代理
|
||||
DownSnid int32 // 下级代理
|
||||
Level int32 // 代理层级 例如 1:DownSnid 是 UpSnid 的 1 级代理; 2: DownSnid 是 UpSnid 的 2 级代理
|
||||
Tp int32 // 返佣类型
|
||||
Rate int64 // 返佣比例
|
||||
Score int64 // 积分
|
||||
Money int64 // 充值金额
|
||||
Ts int64 // 时间戳
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue