好友审核修复

This commit is contained in:
wh_zcy 2022-12-14 19:24:00 +08:00
parent b5954efc8f
commit 5270f706d3
5 changed files with 81 additions and 39 deletions

View File

@ -228,7 +228,7 @@ const ( //Rpc
Rpc_ModuleRtaskSendTask core.Rpc_Key = "Rpc_ModuleRtaskSendTask" //随机任务触发
// friend
Rpc_ModuleFriendUseAssitHero core.Rpc_Key = "Rpc_ModuleFriendUseAssitHero" //使用助战英雄
Rpc_ModuleFriendDB core.Rpc_Key = "Rpc_ModuleFriendDB"
// arena
Rpc_ModuleArenaRaceSettlement core.Rpc_Key = "Rpc_ModuleArenaRaceSettlement" //竞技场比赛结算信息
Rpc_ModuleArenaModifyIntegral core.Rpc_Key = "Rpc_ModuleArenaModifyIntegral" //竞技场修改积分

View File

@ -69,6 +69,9 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
//将目标加入到自己的好友列表中
for _, userId := range agreeIds {
//将目标从申请列表中删除
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
if _, ok := utils.Find(self.FriendIds, userId); !ok {
if self.FriendIds == nil {
self.FriendIds = []string{}
@ -82,6 +85,7 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
code = pb.ErrorCode_FriendTargetNoData
return
}
target.ApplyIds = utils.DeleteString(target.ApplyIds, self.Uid)
if _, ok := utils.Find(target.FriendIds, self.Uid); !ok {
if target.FriendIds == nil {
target.FriendIds = []string{}
@ -106,19 +110,19 @@ func (this *apiComp) Agree(session comm.IUserSession, req *pb.FriendAgreeReq) (c
pushAssistHero(self.Uid, target.Uid, self.AssistHeroId)
}
//将目标从申请列表中删除
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
optNum++
}
//更新
err = this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{
"applyIds": self.ApplyIds,
"friendIds": self.FriendIds,
})
if err != nil {
code = pb.ErrorCode_DBError
return
if optNum > 0 {
//更新
err = this.moduleFriend.modelFriend.Change(self.Uid, map[string]interface{}{
"applyIds": self.ApplyIds,
"friendIds": self.FriendIds,
})
if err != nil {
code = pb.ErrorCode_DBError
return
}
}
// 拥有xx个好友

View File

@ -31,6 +31,13 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
)
uid := session.GetUserId()
//判断是否是自己
if req.FriendId == uid {
code = pb.ErrorCode_FriendNotSelf
return
}
//获取玩家自己好友数据
self = this.moduleFriend.modelFriend.GetFriend(uid)
if self == nil {
@ -38,6 +45,19 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
return
}
globalConf := this.moduleFriend.globalConf
//判断是否超过最大好友数量
if len(self.FriendIds) >= int(globalConf.FriendMaxnum) {
code = pb.ErrorCode_FriendSelfMax
return
}
//判断是否是好友
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = pb.ErrorCode_FriendYet
return
}
//获取好友数据
target = this.moduleFriend.modelFriend.GetFriend(req.FriendId)
if target == nil {
@ -45,15 +65,9 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
return
}
//判断是否是自己
if req.FriendId == uid {
code = pb.ErrorCode_FriendNotSelf
return
}
globalConf := this.moduleFriend.globalConf
//判断是否超过最大好友数量
if len(self.FriendIds) >= int(globalConf.FriendMaxnum) {
code = pb.ErrorCode_FriendSelfMax
//判断自己是否在目标用户的申请列表中
if _, ok := utils.Find(target.ApplyIds, self.Uid); ok {
code = pb.ErrorCode_FriendApplyYet
return
}
@ -63,18 +77,6 @@ func (this *apiComp) Apply(session comm.IUserSession, req *pb.FriendApplyReq) (c
return
}
//判断是否是好友
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
code = pb.ErrorCode_FriendYet
return
}
//判断自己是否在目标用户的申请列表中
if _, ok := utils.Find(target.ApplyIds, self.Uid); ok {
code = pb.ErrorCode_FriendApplyYet
return
}
//判断目标用户是否在黑名单中
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
code = pb.ErrorCode_FriendSelfBlackYet

View File

@ -1,6 +1,7 @@
package friend
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
@ -14,12 +15,13 @@ import (
type ModelFriend struct {
modules.MCompModel
moduleFriend *Friend
}
func (this *ModelFriend) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableFriend
err = this.MCompModel.Init(service, module, comp, options)
this.moduleFriend = module.(*Friend)
return
}
@ -38,14 +40,28 @@ func (this *ModelFriend) Frined_FindCond(nickName string) *pb.DBUser {
//查询好友
func (this *ModelFriend) GetFriend(uid string) *pb.DBFriend {
friend := &pb.DBFriend{Uid: uid}
err := this.Get(uid, friend)
if err != nil {
if err == redis.RedisNil || err == mongo.ErrNoDocuments {
if err := this.Add(uid, friend); err != nil {
return nil
if this.moduleFriend.IsCross() {
err := this.Get(uid, friend)
if err != nil {
if err == redis.RedisNil || err == mongo.ErrNoDocuments {
if err := this.Add(uid, friend); err != nil {
return nil
}
}
log.Error("未获得好友数据", log.Fields{"uid": uid})
}
} else {
friend := &pb.DBFriend{}
if err := this.moduleFriend.service.AcrossClusterRpcCall(
context.Background(),
this.moduleFriend.GetCrossTag(),
comm.Service_Worker,
string(comm.Rpc_ModuleFriendDB),
pb.RPCGeneralReqA1{Param1: uid},
friend); err != nil {
this.moduleFriend.Errorln(err)
}
log.Error("未获得好友数据", log.Fields{"uid": uid})
}
return friend
}

View File

@ -15,10 +15,12 @@ import (
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/lego/sys/redis"
cfg "go_dreamfactory/sys/configure/structs"
"github.com/spf13/cast"
"go.mongodb.org/mongo-driver/mongo"
)
var _ comm.IFriend = (*Friend)(nil)
@ -56,6 +58,7 @@ func (this *Friend) OnInstallComp() {
func (this *Friend) Start() (err error) {
err = this.ModuleBase.Start()
this.service.RegisterFunctionName(string(comm.Rpc_ModuleFriendUseAssitHero), this.RpcUseAssisHero)
this.service.RegisterFunctionName(string(comm.Rpc_ModuleFriendDB), this.RpcFriendDB)
this.globalConf = this.configure.GetGlobalConf()
if this.globalConf == nil {
err = errors.New("global config not found")
@ -109,6 +112,23 @@ func (this *Friend) RpcUseAssisHero(ctx context.Context, req *pb.RPCGeneralReqA2
return nil
}
func (this *Friend) RpcFriendDB(ctx context.Context, req *pb.RPCGeneralReqA1, reply *pb.DBFriend) error {
this.Debug("Rpc_ModuleFriendDB", log.Fields{"req": req})
friend := &pb.DBFriend{Uid: req.Param1}
err := this.modelFriend.Get(req.Param1, friend)
if err != nil {
if err == redis.RedisNil || err == mongo.ErrNoDocuments {
if err := this.modelFriend.Add(req.Param1, friend); err != nil {
return nil
}
} else {
log.Error("未获得好友数据", log.Fields{"uid": req.Param1, "err": err})
}
}
*reply = *friend
return nil
}
// 使用好友助战英雄
// friendId 好友Id
func (this *Friend) UseAssistHero(uid, friendId string) (*pb.DBHero, error) {