qnc-server-tob/app/main/api/internal/logic/user/detaillogic.go

59 lines
1.7 KiB
Go
Raw Normal View History

2025-01-10 00:09:25 +08:00
package user
import (
"context"
2025-06-09 12:34:52 +08:00
"qnc-server/app/main/api/internal/svc"
"qnc-server/app/main/api/internal/types"
"qnc-server/app/main/model"
2025-04-11 13:10:17 +08:00
"qnc-server/common/ctxdata"
"qnc-server/common/xerr"
"qnc-server/pkg/lzkit/crypto"
2025-04-08 12:49:19 +08:00
"github.com/jinzhu/copier"
"github.com/pkg/errors"
2025-01-10 00:09:25 +08:00
"github.com/zeromicro/go-zero/core/logx"
)
type DetailLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DetailLogic {
return &DetailLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *DetailLogic) Detail() (resp *types.UserInfoResp, err error) {
userID, err := ctxdata.GetUidFromCtx(l.ctx)
if err != nil {
2025-03-07 03:48:59 +08:00
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, %v", err)
2025-01-10 00:09:25 +08:00
}
user, err := l.svcCtx.UserModel.FindOne(l.ctx, userID)
if err != nil {
2025-04-08 15:17:09 +08:00
if errors.Is(err, model.ErrNotFound) {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.USER_NOT_FOUND), "用户信息, 用户不存在, %v", err)
}
2025-03-07 03:48:59 +08:00
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "用户信息, 数据库查询用户信息失败, %v", err)
2025-01-10 00:09:25 +08:00
}
var userInfo types.User
err = copier.Copy(&userInfo, user)
if err != nil {
2025-03-07 03:48:59 +08:00
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, 用户信息结构体复制失败, %v", err)
2025-01-10 00:09:25 +08:00
}
2025-04-26 15:10:01 +08:00
if user.Mobile.Valid {
userInfo.Mobile, err = crypto.DecryptMobile(user.Mobile.String, l.svcCtx.Config.Encrypt.SecretKey)
if err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "用户信息, 解密手机号失败, %v", err)
}
2025-04-08 12:49:19 +08:00
}
2025-01-10 00:09:25 +08:00
return &types.UserInfoResp{
UserInfo: userInfo,
}, nil
}