110 lines
2.6 KiB
Go
110 lines
2.6 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
func (this *ApiComp) Apply_Check(session comm.IUserSession, req *pb.FriendApplyReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
|
return
|
|
}
|
|
|
|
//好友申请
|
|
func (this *ApiComp) Apply(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendApplyReq) (err error) {
|
|
var (
|
|
code pb.ErrorCode
|
|
self *pb.DB_FriendData
|
|
target *pb.DB_FriendData
|
|
rsp *pb.FriendApplyRsp
|
|
)
|
|
|
|
defer func() {
|
|
utils.TraceFunc(session.GetUserId(), string(this.module.GetType()), Friend_SubType_Apply, req, rsp)
|
|
}()
|
|
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
rsp = &pb.FriendApplyRsp{
|
|
UserId: session.GetUserId(),
|
|
FriendId: req.FriendId,
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_Apply, code, rsp)
|
|
}()
|
|
|
|
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
|
if self == nil || err != nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
err = this.module.model_friend.GetObj(req.FriendId, target)
|
|
if target == nil || err != nil {
|
|
code = pb.ErrorCode_FriendTargetNoData
|
|
return
|
|
}
|
|
|
|
//判断是否是自己
|
|
if req.FriendId == session.GetUserId() {
|
|
code = pb.ErrorCode_FriendNotSelf
|
|
return
|
|
}
|
|
|
|
//判断是否超过最大好友数量
|
|
//TODO 最大数从全局配置中获取
|
|
var max int = 50
|
|
total := len(self.FriendIds)
|
|
if total >= max {
|
|
code = pb.ErrorCode_FriendSelfMax
|
|
return
|
|
}
|
|
|
|
//判断对方是否也超过最大好友数量
|
|
ttotal := len(target.FriendIds)
|
|
if ttotal >= max {
|
|
code = pb.ErrorCode_FriendTargetMax
|
|
return
|
|
}
|
|
|
|
//判断是否是好友
|
|
if _, ok := utils.Find(self.FriendIds, req.FriendId); ok {
|
|
code = pb.ErrorCode_FriendYet
|
|
return
|
|
}
|
|
|
|
//判断自己是否在目标用户的申请列表中
|
|
if _, ok := utils.Find(target.ApplyIds, self.UserId); ok {
|
|
code = pb.ErrorCode_FriendApplyYet
|
|
return
|
|
}
|
|
|
|
//判断目标用户是否在黑名单中
|
|
if _, ok := utils.Find(self.BlackIds, req.FriendId); ok {
|
|
code = pb.ErrorCode_FriendSelfBlackYet
|
|
return
|
|
}
|
|
|
|
//判断是否在对方的黑名单中
|
|
if _, ok := utils.Find(target.BlackIds, self.UserId); ok {
|
|
code = pb.ErrorCode_FriendTargetBlackYet
|
|
return
|
|
}
|
|
|
|
//将自己加入到目标用户的申请列表中
|
|
target.ApplyIds = append(target.ApplyIds, self.UserId)
|
|
err = this.module.model_friend.SetObj(req.FriendId, &pb.DB_FriendData{
|
|
UserId: req.FriendId,
|
|
ApplyIds: target.ApplyIds,
|
|
}, false, true)
|
|
|
|
if err != nil {
|
|
log.Errorf("firend Apply err:%v", err)
|
|
code = pb.ErrorCode_FriendApplyError
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|