59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
func (this *apiComp) QiecuoCheck(session comm.IUserSession, req *pb.FriendQiecuoReq) (code pb.ErrorCode) {
|
|
if req.TargetUid == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Qiecuo(session comm.IUserSession, req *pb.FriendQiecuoReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.QiecuoCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
//目标是否在线
|
|
if !this.moduleFriend.ModuleUser.IsOnline(req.TargetUid) {
|
|
code = pb.ErrorCode_UserOffline
|
|
return
|
|
}
|
|
|
|
//校验目标是否已正在切磋
|
|
if targetQr := this.moduleFriend.ModelFriendQiecuo.getQiecuo(req.TargetUid); targetQr != nil {
|
|
code = pb.ErrorCode_FriendQiecuoTargetPk
|
|
return
|
|
}
|
|
|
|
qr, err := this.moduleFriend.ModelFriendQiecuo.createQiecuoRecord(session.GetUserId(), req.TargetUid)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
//判断是否切磋中
|
|
if qr.MatchId != "" {
|
|
code = pb.ErrorCode_FriendQiecuoing
|
|
return
|
|
}
|
|
|
|
resp := &pb.FriendQiecuoResp{
|
|
TargetUid: req.TargetUid,
|
|
Uid: session.GetUserId(),
|
|
}
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeQiecuo, resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
this.moduleFriend.SendMsgToUser(string(this.moduleFriend.GetType()), "qiecuonotify",
|
|
&pb.FriendQiecuonotifyPush{Uid: session.GetUserId(), NotifyType: 1}, req.TargetUid)
|
|
|
|
return
|
|
}
|