fix: 修复打手详情响应字段

This commit is contained in:
zetaloop
2026-04-25 08:30:30 +08:00
parent d686a7a32c
commit 848827482f
3 changed files with 96 additions and 9 deletions
@@ -5,13 +5,16 @@ package player
import (
"context"
"encoding/json"
"errors"
"juwan-backend/app/player/rpc/playerservice"
"strconv"
"time"
"juwan-backend/app/player/api/internal/svc"
"juwan-backend/app/player/api/internal/types"
"juwan-backend/app/player/rpc/playerservice"
"juwan-backend/app/users/rpc/usercenter"
"github.com/jinzhu/copier"
"github.com/zeromicro/go-zero/core/logx"
)
@@ -31,18 +34,83 @@ func NewGetPlayerLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPlay
}
func (l *GetPlayerLogic) GetPlayer(req *types.GetPlayerReq) (resp *types.PlayerProfile, err error) {
player, err := l.svcCtx.PlayerRpc.GetPlayersById(l.ctx, &playerservice.GetPlayersByIdReq{
playerResp, err := l.svcCtx.PlayerRpc.GetPlayersById(l.ctx, &playerservice.GetPlayersByIdReq{
Id: req.Id,
})
if err != nil {
logx.Errorf("GetPlayerLogic.GetPlayers err: %v", err)
return nil, errors.New("failed to get player details")
}
resp = &types.PlayerProfile{}
err = copier.Copy(resp, &player)
if err != nil {
logx.Errorf("copier.Copy err: %v", err)
return nil, errors.New("copier.Copy err")
player := playerResp.GetPlayers()
if player == nil {
return nil, errors.New("player not found")
}
resp = &types.PlayerProfile{
Id: player.Id,
Rating: player.Rating,
TotalOrders: player.TotalOrders,
Status: player.Status,
Gender: player.Gender,
Services: []types.PlayerService{},
Tags: append([]string{}, player.Tags...),
}
games := make([]string, 0, len(player.Games))
for _, gameID := range player.Games {
games = append(games, strconv.FormatInt(gameID, 10))
}
resp.Games = games
if player.ShopId != 0 {
resp.ShopId = strconv.FormatInt(player.ShopId, 10)
}
usersResp, err := l.svcCtx.UserRpc.GetUsersByIds(l.ctx, &usercenter.GetUsersByIdsReq{Ids: []int64{player.UserId}})
if err != nil {
return nil, err
}
if len(usersResp.Users) > 0 {
u := usersResp.Users[0]
verificationStatus := map[string]string{}
if u.VerificationStatus != "" {
_ = json.Unmarshal([]byte(u.VerificationStatus), &verificationStatus)
}
resp.User = types.UserProfile{
Id: strconv.FormatInt(u.Id, 10),
Username: u.Username,
Nickname: u.Nickname,
Avatar: u.Avatar,
Role: u.CurrentRole,
VerifiedRoles: append([]string{}, u.VerifiedRoles...),
VerificationStatus: verificationStatus,
Phone: u.Phone,
Bio: u.Bio,
CreatedAt: time.Unix(u.CreatedAt, 0).Format(time.DateTime),
}
}
svcResp, svcErr := l.svcCtx.PlayerRpc.SearchPlayerServices(l.ctx, &playerservice.SearchPlayerServicesReq{
PlayerId: player.Id,
Limit: 100,
})
if svcErr != nil {
logx.Errorf("GetPlayer SearchPlayerServices player=%d err: %v", player.Id, svcErr)
} else {
for _, s := range svcResp.PlayerServices {
resp.Services = append(resp.Services, types.PlayerService{
Id: s.Id,
PlayerId: s.PlayerId,
GameId: s.GameId,
Title: s.Title,
Description: s.Description,
Price: s.Price,
Unit: s.Unit,
RankRange: s.RankRange,
Availability: s.Availability,
})
}
}
return
}
@@ -36,6 +36,7 @@ func (l *GetPlayersByIdLogic) GetPlayersById(in *pb.GetPlayersByIdReq) (*pb.GetP
Id: player.ID,
UserId: player.UserID,
Status: player.Status,
Gender: player.Gender,
Rating: player.Rating.InexactFloat64(),
TotalOrders: int64(player.TotalOrders),
CompletedOrders: int64(player.CompletedOrders),
+19 -1
View File
@@ -791,7 +791,12 @@ def phase6_player(s: Session, game_id):
report(f"GET /players/{player_id}", code, body)
report_check(
f"GET /players/{player_id} returns initialized online player",
code == 200 and same_id(body.get("id"), player_id) and body.get("status") == "online",
code == 200
and same_id(body.get("id"), player_id)
and body.get("status") == "online"
and body.get("gender") is True
and as_int((body.get("user") or {}).get("id")) > 0
and isinstance(body.get("services"), list),
body,
)
@@ -860,6 +865,19 @@ def phase6_player(s: Session, game_id):
body,
)
code, body, _ = s.get(f"{GATEWAY}/api/v1/players/{player_id}")
report(f"GET /players/{player_id} (after service update)", code, body)
service = find_item_by_id(body.get("services") or [], service_id)
report_check(
f"GET /players/{player_id} includes updated service",
code == 200
and body.get("gender") is True
and bool(service)
and service.get("title") == "Updated Service"
and as_decimal(service.get("price")) == Decimal("60"),
body,
)
if player_id:
code, body, _ = s.get(f"{GATEWAY}/api/v1/players/{player_id}/services")
report(f"GET /players/{player_id}/services", code, body)