49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
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,
|
||
}, nil
|
||
}
|