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
}