63 lines
1.6 KiB
Go
63 lines
1.6 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 获取好友关系
|
|
func (this *apiComp) GetRelationCheck(session comm.IUserSession, req *pb.FriendGetRelationReq) (errdata *pb.ErrorData) {
|
|
if req.TargetUid == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
this.module.Error("参数错误", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "params", Value: req.String()})
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) GetRelation(session comm.IUserSession, req *pb.FriendGetRelationReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.GetRelationCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
self, err := this.module.modelFriend.GetFriend(session.GetUserId())
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendSelfNoData,
|
|
Title: pb.ErrorCode_FriendSelfNoData.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
target, err := this.module.modelFriend.GetFriend(req.TargetUid)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendTargetNoData,
|
|
Title: pb.ErrorCode_FriendSelfNoData.ToString(),
|
|
}
|
|
return
|
|
}
|
|
var status bool
|
|
|
|
// 已申请目标玩家
|
|
if _, ok := utils.Findx(target.ApplyIds, self.Uid); ok {
|
|
status = true
|
|
}
|
|
|
|
//目标玩家已是好友
|
|
if _, ok := utils.Findx(self.FriendIds, req.TargetUid); ok {
|
|
status = true
|
|
}
|
|
|
|
resp := &pb.FriendGetRelationResp{
|
|
TargetUid: req.TargetUid,
|
|
Status: status,
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), FriendSubTypeRelation, resp)
|
|
return
|
|
}
|