tianyuan-api-server/apps/gateway/internal/logic/user/getuserinfologic.go
2024-10-15 23:58:36 +08:00

50 lines
1.2 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package user
import (
"context"
"errors"
"tianyuan-api/apps/gateway/internal/svc"
"tianyuan-api/apps/gateway/internal/types"
"tianyuan-api/apps/user/user"
"github.com/zeromicro/go-zero/core/logx"
)
type GetUserInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserInfoLogic {
return &GetUserInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetUserInfoLogic) GetUserInfo() (resp *types.UserInfoResp, err error) {
// 从上下文中解析 JWT获取用户ID
userId, ok := l.ctx.Value("userId").(int64)
if !ok {
return nil, errors.New("无法获取 userId")
}
info, err := l.svcCtx.UserRpc.UserInfo(l.ctx, &user.UserInfoReq{UserId: userId})
if err != nil {
return nil, err
}
// 如果查到了企业信息,连带企业信息一起返回
return &types.UserInfoResp{
Username: info.Username,
Phone: info.Phone,
EnterpriseAuthStatus: info.EnterpriseAuthStatus,
EnterpriseName: info.EnterpriseName,
CreditCode: info.CreditCode,
LegalPerson: info.LegalPerson,
Balance: info.Balance,
}, nil
}