新邀请活动
This commit is contained in:
parent
70768089da
commit
b067f07b2c
|
|
@ -31,6 +31,15 @@ func init() {
|
||||||
}
|
}
|
||||||
logger.Logger.Tracef("EvtInvite log:%+v", log)
|
logger.Logger.Tracef("EvtInvite log:%+v", log)
|
||||||
|
|
||||||
|
var addRechargeScore bool
|
||||||
|
if log.Tp != common.InviteScoreCheckWeek {
|
||||||
|
addRechargeScore, err = svc.CheckInviteScore(&log.InviteScore)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Errorf("EvtInvite SaveInviteScore error:%v msg:%+v %+v", err, log.InviteScore, log)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
now := time.Unix(log.Ts, 0).Local() // 数据创建时间
|
now := time.Unix(log.Ts, 0).Local() // 数据创建时间
|
||||||
|
|
||||||
get := func(snid int32) (*model.EvtInviteAckMsg, error) {
|
get := func(snid int32) (*model.EvtInviteAckMsg, error) {
|
||||||
|
|
@ -44,25 +53,6 @@ func init() {
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// 增加积分
|
|
||||||
add := func(psnid, snid, level, tp int32, score, money, rate int64, addMoney bool) error {
|
|
||||||
if psnid <= 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
err = svc.AddInviteScore(log.Platform, psnid, snid, level, tp, score*rate/10000, rate, money, now, addMoney)
|
|
||||||
if err != nil {
|
|
||||||
logger.Logger.Errorf("EvtInvite add error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
msg, err := get(psnid)
|
|
||||||
if err != nil {
|
|
||||||
logger.Logger.Errorf("EvtInvite add find error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
mq.Send(model.EvtInviteAck, msg)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重置积分
|
// 重置积分
|
||||||
reset := func(snid int32) error {
|
reset := func(snid int32) error {
|
||||||
if snid == 0 {
|
if snid == 0 {
|
||||||
|
|
@ -110,28 +100,27 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addRechargeScore bool
|
// 增加积分
|
||||||
if log.Tp != common.InviteScoreCheckWeek {
|
add := func(psnid, snid, level, tp int32, score, money, rate int64, addMoney bool) error {
|
||||||
addRechargeScore, err = svc.CheckInviteScore(&log.InviteScore)
|
if psnid <= 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
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 SaveInviteScore error:%v msg:%+v %+v", err, log.InviteScore, log)
|
logger.Logger.Errorf("EvtInvite add error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
msg, err := get(psnid)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Errorf("EvtInvite add find error:%v psnid:%v score:%v rate:%v", err, psnid, score, rate)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
mq.Send(model.EvtInviteAck, msg)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch log.Tp {
|
switch log.Tp {
|
||||||
case common.InviteScoreTypeBind:
|
case common.InviteScoreTypeBind:
|
||||||
code, err := svc.GetCodeBySnId(log.Platform, log.InviteSnId)
|
|
||||||
if err != nil {
|
|
||||||
logger.Logger.Errorf("EvtInvite GetCodeBySnId error:%v %v", err, log.InviteSnId)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// 绑定关系
|
|
||||||
err = svc.BindInviteSnId(log.Platform, log.SnId, log.InviteSnId, code)
|
|
||||||
if err != nil {
|
|
||||||
logger.Logger.Errorf("EvtInvite BindInviteSnId error:%v msg:%+v", err, log.InviteScore)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
// 更新绑定数量
|
// 更新绑定数量
|
||||||
// 更新邀请积分
|
// 更新邀请积分
|
||||||
// 1.邀请人增加积分
|
// 1.邀请人增加积分
|
||||||
|
|
|
||||||
|
|
@ -56,13 +56,13 @@ func CheckInviteScore(req *model.InviteScore) (b bool, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 不能重复绑定
|
// 不能重复绑定
|
||||||
if req.Tp == common.InviteScoreTypeBind {
|
//if req.Tp == common.InviteScoreTypeBind {
|
||||||
psnid, err := GetPSnId(req.Platform, req.SnId)
|
// psnid, err := GetPSnId(req.Platform, req.SnId)
|
||||||
if err == nil && psnid > 0 {
|
// if err == nil && psnid > 0 {
|
||||||
// 已经绑定
|
// // 已经绑定
|
||||||
return false, errors.New("already bind")
|
// return false, errors.New("already bind")
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
// 必须已经绑定
|
// 必须已经绑定
|
||||||
if req.Tp != common.InviteScoreTypeBind {
|
if req.Tp != common.InviteScoreTypeBind {
|
||||||
|
|
|
||||||
|
|
@ -1548,6 +1548,15 @@ func (svc *PlayerDataSvc) GetPlayerInviteSnid(req *model.PlayerIsExistBySnIdArgs
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (svc *PlayerDataSvc) BindInviteSnId(args *model.BindArgs, ret *bool) error {
|
||||||
|
err := BindInviteSnId(args.Platform, args.SnId, args.PSnId, args.PCode)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*ret = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func BindInviteSnId(platform string, snId, inviteSnId int32, code string) error {
|
func BindInviteSnId(platform string, snId, inviteSnId int32, code string) error {
|
||||||
c := PlayerDataCollection(platform)
|
c := PlayerDataCollection(platform)
|
||||||
if c == nil {
|
if c == nil {
|
||||||
|
|
@ -1559,11 +1568,6 @@ func BindInviteSnId(platform string, snId, inviteSnId int32, code string) error
|
||||||
logger.Logger.Error("BindInviteSnId error ", err)
|
logger.Logger.Error("BindInviteSnId error ", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.Update(bson.M{"snid": inviteSnId}, bson.M{"$inc": bson.D{{"inum", 1}}})
|
|
||||||
if err != nil {
|
|
||||||
logger.Logger.Error("BindInviteSnId inc error ", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1619,7 +1623,12 @@ func AddInviteScore(platform string, psnId, snid, level, tp int32, num, rate, mo
|
||||||
myMoney = 0
|
myMoney = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Update(bson.M{"snid": psnId}, bson.M{"$inc": bson.M{"iscore": num, "imoney": myMoney}, "$set": bson.M{"iscorets": now}})
|
addNum := int64(0)
|
||||||
|
if level == 0 && tp == common.InviteScoreTypeBind {
|
||||||
|
addNum = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
err = c.Update(bson.M{"snid": psnId}, bson.M{"$inc": bson.M{"iscore": num, "imoney": myMoney, "inum": addNum}, "$set": bson.M{"iscorets": now}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
i.RemoveId(id)
|
i.RemoveId(id)
|
||||||
logger.Logger.Error("AddInviteScore error ", err)
|
logger.Logger.Error("AddInviteScore error ", err)
|
||||||
|
|
|
||||||
|
|
@ -2941,3 +2941,31 @@ func (this *PlayerData) GetRoleId() int32 {
|
||||||
}
|
}
|
||||||
return common.DefaultRoleId
|
return common.DefaultRoleId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BindArgs struct {
|
||||||
|
Platform string
|
||||||
|
PSnId, SnId int32
|
||||||
|
PCode string
|
||||||
|
}
|
||||||
|
|
||||||
|
func BindInviteSnId(platform string, snId, pSnId int32, code string) error {
|
||||||
|
if rpcCli == nil {
|
||||||
|
return fmt.Errorf("db may be close")
|
||||||
|
}
|
||||||
|
var args = &BindArgs{
|
||||||
|
Platform: platform,
|
||||||
|
PSnId: pSnId,
|
||||||
|
SnId: snId,
|
||||||
|
PCode: code,
|
||||||
|
}
|
||||||
|
var ret bool
|
||||||
|
err := rpcCli.CallWithTimeout("PlayerDataSvc.BindInviteSnId", args, &ret, time.Second*30)
|
||||||
|
if err != nil {
|
||||||
|
logger.Logger.Warnf("BindInviteSnId error:%v", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if ret {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("bind error")
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -440,15 +440,21 @@ func CSBindInvite(s *netlib.Session, packetid int, data interface{}, sid int64)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SaveInviteScore(&model.InviteScore{
|
|
||||||
Platform: p.Platform,
|
if err == nil {
|
||||||
SnId: p.SnId,
|
err = model.BindInviteSnId(p.Platform, p.SnId, inviteSnId, msg.Code)
|
||||||
InviteSnId: inviteSnId,
|
}
|
||||||
Tp: common.InviteScoreTypeBind,
|
if err == nil {
|
||||||
Score: cfg.GetBindScore(),
|
SaveInviteScore(&model.InviteScore{
|
||||||
Ts: now.Unix(),
|
Platform: p.Platform,
|
||||||
Money: 0,
|
SnId: p.SnId,
|
||||||
})
|
InviteSnId: inviteSnId,
|
||||||
|
Tp: common.InviteScoreTypeBind,
|
||||||
|
Score: cfg.GetBindScore(),
|
||||||
|
Ts: now.Unix(),
|
||||||
|
Money: 0,
|
||||||
|
})
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
}), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -459,7 +465,7 @@ func CSBindInvite(s *netlib.Session, packetid int, data interface{}, sid int64)
|
||||||
p.PCode = msg.GetCode()
|
p.PCode = msg.GetCode()
|
||||||
ret.OpRetCode = welfare.OpResultCode_OPRC_Sucess
|
ret.OpRetCode = welfare.OpResultCode_OPRC_Sucess
|
||||||
send()
|
send()
|
||||||
})).Start()
|
})).StartByFixExecutor("invite_score")
|
||||||
})).Start()
|
})).Start()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue