fix: 店铺邀请改为查找打手身份

This commit is contained in:
zetaloop
2026-04-04 07:04:29 +08:00
parent 7dc088eadf
commit 93679d2ff3
5 changed files with 43 additions and 6 deletions
@@ -6,6 +6,7 @@ package shop
import (
"context"
"errors"
"juwan-backend/app/player/rpc/playerservice"
"juwan-backend/app/shop/api/internal/svc"
"juwan-backend/app/shop/api/internal/types"
"juwan-backend/app/shop/rpc/pb"
@@ -13,6 +14,8 @@ import (
"time"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type AcceptInvitationLogic struct {
@@ -35,6 +38,18 @@ func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq)
if err != nil {
return nil, err
}
playerResp, err := l.svcCtx.PlayerRpc.GetPlayerByUserId(l.ctx, &playerservice.SearchPlayersReq{UserId: &userId})
if err != nil {
st, _ := status.FromError(err)
if st.Code() == codes.NotFound {
return nil, errors.New("bad request: invitation not found or not owned by user")
}
return nil, err
}
player := playerResp.GetPlayers()
if player == nil {
return nil, errors.New("bad request: invitation not found or not owned by user")
}
invitation, err := l.svcCtx.ShopRpc.GetShopInvitationsById(l.ctx, &pb.GetShopInvitationsByIdReq{Id: req.Id})
if err != nil {
return nil, err
@@ -42,14 +57,14 @@ func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq)
if invitation.ShopInvitations == nil {
return nil, errors.New("invitation not found")
}
if invitation.ShopInvitations.PlayerId != userId {
if invitation.ShopInvitations.PlayerId != player.Id {
return nil, errors.New("bad request: invitation not found or not owned by user")
}
i, err := l.svcCtx.ShopRpc.UpdateShopInvitations(l.ctx, &pb.UpdateShopInvitationsReq{
Id: req.Id,
ShopId: invitation.ShopInvitations.ShopId,
PlayerId: userId,
PlayerId: player.Id,
Status: "accepted",
InvitedBy: invitation.ShopInvitations.InvitedBy,
CreatedAt: invitation.ShopInvitations.CreatedAt,
@@ -60,7 +75,7 @@ func (l *AcceptInvitationLogic) AcceptInvitation(req *types.AcceptInvitationReq)
}
_, err = l.svcCtx.ShopRpc.AddShopPlayers(l.ctx, &pb.AddShopPlayersReq{
ShopId: i.ShopInvitations.ShopId,
PlayerId: userId,
PlayerId: player.Id,
IsPrimary: false,
JoinedAt: time.Now().Unix(),
LeftAt: 0,
@@ -8,12 +8,15 @@ import (
"errors"
"time"
"juwan-backend/app/player/rpc/playerservice"
"juwan-backend/app/shop/api/internal/svc"
"juwan-backend/app/shop/api/internal/types"
"juwan-backend/app/shop/rpc/pb"
"juwan-backend/common/utils/contextj"
"github.com/zeromicro/go-zero/core/logx"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
type RejectInvitationLogic struct {
@@ -36,6 +39,18 @@ func (l *RejectInvitationLogic) RejectInvitation(req *types.AcceptInvitationReq)
if err != nil {
return nil, err
}
playerResp, err := l.svcCtx.PlayerRpc.GetPlayerByUserId(l.ctx, &playerservice.SearchPlayersReq{UserId: &userID})
if err != nil {
st, _ := status.FromError(err)
if st.Code() == codes.NotFound {
return nil, contextj.ERRILLEGALUSER
}
return nil, err
}
player := playerResp.GetPlayers()
if player == nil {
return nil, contextj.ERRILLEGALUSER
}
invitation, err := l.svcCtx.ShopRpc.GetShopInvitationsById(l.ctx, &pb.GetShopInvitationsByIdReq{Id: req.Id})
if err != nil {
@@ -44,7 +59,7 @@ func (l *RejectInvitationLogic) RejectInvitation(req *types.AcceptInvitationReq)
if invitation.ShopInvitations == nil {
return nil, errors.New("invitation not found")
}
if invitation.ShopInvitations.PlayerId != userID {
if invitation.ShopInvitations.PlayerId != player.Id {
return nil, contextj.ERRILLEGALUSER
}