diff --git a/dbproxy/mq/c_invite.go b/dbproxy/mq/c_invite.go index 2c84406..90b1e64 100644 --- a/dbproxy/mq/c_invite.go +++ b/dbproxy/mq/c_invite.go @@ -31,6 +31,15 @@ func init() { } 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() // 数据创建时间 get := func(snid int32) (*model.EvtInviteAckMsg, error) { @@ -44,25 +53,6 @@ func init() { 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 { if snid == 0 { @@ -110,28 +100,27 @@ func init() { } } - var addRechargeScore bool - if log.Tp != common.InviteScoreCheckWeek { - addRechargeScore, err = svc.CheckInviteScore(&log.InviteScore) + // 增加积分 + 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 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 } + 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 { 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.邀请人增加积分 diff --git a/dbproxy/svc/l_invitescore.go b/dbproxy/svc/l_invitescore.go index 7b29c11..bd4dc30 100644 --- a/dbproxy/svc/l_invitescore.go +++ b/dbproxy/svc/l_invitescore.go @@ -56,13 +56,13 @@ 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 { - // 已经绑定 - return false, errors.New("already bind") - } - } + //if req.Tp == common.InviteScoreTypeBind { + // psnid, err := GetPSnId(req.Platform, req.SnId) + // if err == nil && psnid > 0 { + // // 已经绑定 + // return false, errors.New("already bind") + // } + //} // 必须已经绑定 if req.Tp != common.InviteScoreTypeBind { diff --git a/dbproxy/svc/u_player.go b/dbproxy/svc/u_player.go index 92a5804..c6ff636 100644 --- a/dbproxy/svc/u_player.go +++ b/dbproxy/svc/u_player.go @@ -1548,6 +1548,15 @@ func (svc *PlayerDataSvc) GetPlayerInviteSnid(req *model.PlayerIsExistBySnIdArgs 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 { c := PlayerDataCollection(platform) if c == nil { @@ -1559,11 +1568,6 @@ func BindInviteSnId(platform string, snId, inviteSnId int32, code string) error logger.Logger.Error("BindInviteSnId error ", 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 } @@ -1619,7 +1623,12 @@ func AddInviteScore(platform string, psnId, snid, level, tp int32, num, rate, mo 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 { i.RemoveId(id) logger.Logger.Error("AddInviteScore error ", err) diff --git a/model/player.go b/model/player.go index 8b6d39c..b8636d3 100644 --- a/model/player.go +++ b/model/player.go @@ -2941,3 +2941,31 @@ func (this *PlayerData) GetRoleId() int32 { } 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") +} diff --git a/worldsrv/action_welfare.go b/worldsrv/action_welfare.go index 80a7c1b..b4516f7 100644 --- a/worldsrv/action_welfare.go +++ b/worldsrv/action_welfare.go @@ -440,15 +440,21 @@ func CSBindInvite(s *netlib.Session, packetid int, data interface{}, sid int64) break } } - SaveInviteScore(&model.InviteScore{ - Platform: p.Platform, - SnId: p.SnId, - InviteSnId: inviteSnId, - Tp: common.InviteScoreTypeBind, - Score: cfg.GetBindScore(), - Ts: now.Unix(), - Money: 0, - }) + + if err == nil { + err = model.BindInviteSnId(p.Platform, p.SnId, inviteSnId, msg.Code) + } + if err == nil { + SaveInviteScore(&model.InviteScore{ + Platform: p.Platform, + SnId: p.SnId, + InviteSnId: inviteSnId, + Tp: common.InviteScoreTypeBind, + Score: cfg.GetBindScore(), + Ts: now.Unix(), + Money: 0, + }) + } return nil }), task.CompleteNotifyWrapper(func(i interface{}, t task.Task) { if err != nil { @@ -459,7 +465,7 @@ func CSBindInvite(s *netlib.Session, packetid int, data interface{}, sid int64) p.PCode = msg.GetCode() ret.OpRetCode = welfare.OpResultCode_OPRC_Sucess send() - })).Start() + })).StartByFixExecutor("invite_score") })).Start() return nil }