77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
func (this *ApiComp) Refuse_Check(session comm.IUserSession, req *pb.FriendRefuseReq) (chk map[string]interface{}, code pb.ErrorCode) {
|
|
chk = make(map[string]interface{})
|
|
var err error
|
|
self := &pb.DB_FriendData{UserId: session.GetUserId()}
|
|
|
|
//获取玩家自己好友数据
|
|
err = this.module.model_friend.GetObj(session.GetUserId(), self)
|
|
if self == nil || err != nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
//拒绝的Ids
|
|
refuseIds := []string{}
|
|
for _, friendId := range req.FriendIds {
|
|
if _, ok := utils.Find(self.ApplyIds, friendId); ok {
|
|
refuseIds = append(refuseIds, friendId)
|
|
}
|
|
}
|
|
|
|
chk["self"] = self
|
|
chk["refuseIds"] = refuseIds
|
|
|
|
return
|
|
}
|
|
|
|
//单个/批量拒绝
|
|
func (this *ApiComp) Refuse(session comm.IUserSession, chk map[string]interface{}, req *pb.FriendRefuseReq) (code pb.ErrorCode) {
|
|
//将申请人从申请列表中删除
|
|
var (
|
|
self *pb.DB_FriendData
|
|
rsp *pb.FriendAgreeRsp
|
|
optNum int32
|
|
)
|
|
defer func() {
|
|
if code == pb.ErrorCode_Success {
|
|
rsp = &pb.FriendAgreeRsp{
|
|
Num: optNum,
|
|
}
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), Friend_SubType_Refuse, rsp)
|
|
}()
|
|
|
|
if v, ok := chk["self"]; !ok {
|
|
code = pb.ErrorCode_FriendTargetNoData
|
|
return
|
|
} else {
|
|
self = v.(*pb.DB_FriendData)
|
|
|
|
if v, ok := chk["refuseIds"]; ok {
|
|
//将申请人从申请列表中删除
|
|
for _, userId := range v.([]string) {
|
|
self.ApplyIds = utils.DeleteString(self.ApplyIds, userId)
|
|
optNum++
|
|
}
|
|
//更新
|
|
if optNum > 0 {
|
|
err := this.module.model_friend.SetObj(self.UserId, self, false, true)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
return
|
|
}
|