2026-08-09 10:43:45 +08:00
|
|
|
|
package friend
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
2026-08-10 11:42:45 +08:00
|
|
|
|
"bsm/full/module/social/relation/internal/impl"
|
|
|
|
|
|
"bsm/full/module/social/relation/internal/logic/common"
|
|
|
|
|
|
"bsm/full/module/social/relation/internal/models"
|
|
|
|
|
|
pb "bsm/full/module/social/relation/pb"
|
2026-08-09 10:43:45 +08:00
|
|
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/service"
|
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/utils"
|
|
|
|
|
|
"git.apinb.com/bsm-sdk/core/vars"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// 好友申请Do:确认
|
2026-08-09 20:14:57 +08:00
|
|
|
|
func ApplyDoPass(ctx context.Context, in *pb.ApplyDoPassRequest) (reply *pb.DataStatusReply, err error) {
|
2026-08-09 10:43:45 +08:00
|
|
|
|
auth, err := service.ParseMetaCtx(ctx, nil)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if in.FriendRelationIdentity == "" || in.ApplyIdentity == "" || in.FriendRelationId == 0 {
|
|
|
|
|
|
return nil, errcode.ErrInvalidArgument
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
|
// 通过前先按 identity 查出属于当前调用者(被申请方)的申请记录
|
|
|
|
|
|
var apply models.FriendApply
|
|
|
|
|
|
err = impl.DBService.Where("identity=? and to_identity=?", in.ApplyIdentity, auth.Identity).First(&apply).Error
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
|
return nil, errcode.ErrPermissionDenied
|
|
|
|
|
|
}
|
|
|
|
|
|
// 申请记录里的申请人必须与请求要加为好友的对象一致,否则视为无申请依据
|
|
|
|
|
|
if apply.FromIdentity != in.FriendRelationIdentity {
|
|
|
|
|
|
return nil, errcode.ErrPermissionDenied
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-09 10:43:45 +08:00
|
|
|
|
//写入好友表
|
2026-09-22 21:15:34 +08:00
|
|
|
|
friend := &models.RelationFriend{FriendrelationID: apply.FromID, FriendrelationIdentity: apply.FromIdentity}
|
2026-08-09 10:43:45 +08:00
|
|
|
|
friend.Identity = utils.UUID()
|
|
|
|
|
|
friend.PassportID = auth.ID
|
|
|
|
|
|
friend.PassportIdentity = auth.Identity
|
2026-09-22 21:15:34 +08:00
|
|
|
|
friend.SessionID = common.UniqueSessionID(auth.Identity, apply.FromIdentity)
|
2026-08-09 10:43:45 +08:00
|
|
|
|
|
|
|
|
|
|
err = impl.DBService.Create(&friend).Error
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
|
return nil, errcode.ErrDB
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//EventMQ:向mesh MQ中心发送报文,请求推送消息以及更新Cache.
|
|
|
|
|
|
|
2026-09-22 21:15:34 +08:00
|
|
|
|
err = impl.DBService.Model(models.FriendApply{}).Where("to_identity=? and identity=?", auth.Identity, apply.Identity).UpdateColumn("status", 1).Error
|
2026-08-09 10:43:45 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
printer.Error(err.Error())
|
|
|
|
|
|
return nil, errcode.ErrDB
|
|
|
|
|
|
}
|
2026-08-09 20:14:57 +08:00
|
|
|
|
return &pb.DataStatusReply{
|
2026-08-09 10:43:45 +08:00
|
|
|
|
Data: vars.OK,
|
|
|
|
|
|
Timeseq: time.Now().UnixMilli(),
|
|
|
|
|
|
}, nil
|
|
|
|
|
|
|
|
|
|
|
|
}
|