72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// 点赞
|
|
|
|
func (this *apiComp) ZanCheck(session comm.IUserSession, req *pb.FriendZanReq) (code pb.ErrorCode) {
|
|
if req.FriendId == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Zan(session comm.IUserSession, req *pb.FriendZanReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.ZanCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
|
|
var (
|
|
target *pb.DBFriend
|
|
err error
|
|
selfId string
|
|
)
|
|
|
|
selfId = session.GetUserId()
|
|
|
|
target = this.moduleFriend.modelFriend.GetFriend(req.FriendId)
|
|
if target == nil {
|
|
code = pb.ErrorCode_FriendSelfNoData
|
|
return
|
|
}
|
|
|
|
// 不能给自己点赞
|
|
if req.FriendId == selfId {
|
|
code = pb.ErrorCode_FriendZanSelf
|
|
return
|
|
}
|
|
|
|
// 是否已给好友点赞
|
|
if _, ok := utils.Find(target.ZanIds, selfId); ok {
|
|
code = pb.ErrorCode_FriendZaned
|
|
return
|
|
}
|
|
|
|
//设置被点赞玩家
|
|
target.ZanIds = append(target.ZanIds, selfId)
|
|
|
|
if err = this.moduleFriend.modelFriend.Change(target.GetUid(), map[string]interface{}{
|
|
"zanIds": target.ZanIds,
|
|
}); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
rsp := &pb.FriendZanResp{
|
|
Flag: true,
|
|
}
|
|
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeZan, rsp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|