96 lines
2.3 KiB
Go
96 lines
2.3 KiB
Go
package member
|
|
|
|
import (
|
|
"biz-member-gateway/internal/domain"
|
|
"biz-member-gateway/internal/svc"
|
|
"biz-member-gateway/internal/types"
|
|
"biz-member-gateway/internal/utils"
|
|
"context"
|
|
|
|
"code.30cm.net/digimon/app-cloudep-member-server/pkg/domain/member"
|
|
memberProto "code.30cm.net/digimon/proto-all/pkg/member"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type InfoLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// NewInfoLogic 取得會員資訊
|
|
func NewInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoLogic {
|
|
return &InfoLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *InfoLogic) Info(req *types.VerifyHeader) (resp *types.UserInfo, err error) {
|
|
info, err := l.svcCtx.MemberRPC.GetUserInfo(l.ctx, &memberProto.GetUserInfoReq{
|
|
Uid: domain.UID(l.ctx),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
accountInfo, err := l.svcCtx.MemberRPC.GetUserAccountInfo(l.ctx, &memberProto.GetUIDByAccountReq{
|
|
Account: domain.Account(l.ctx),
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
alarmType := member.AlarmType(info.Data.AlarmType)
|
|
status := member.Status(info.Data.Status)
|
|
res := &types.UserInfo{
|
|
Platform: member.Platform(accountInfo.Data.Platform).ToString(),
|
|
UID: domain.UID(l.ctx),
|
|
UpdateAt: utils.UnixToRfc3339(info.Data.UpdateTime),
|
|
CreateAt: utils.UnixToRfc3339(info.Data.CreateTime),
|
|
AlarmCategory: alarmType.CodeToString(),
|
|
UserStatus: status.CodeToString(),
|
|
PreferredLanguage: info.Data.Language,
|
|
Currency: info.Data.Currency,
|
|
}
|
|
|
|
if info.Data.AvatarUrl != nil {
|
|
res.AvatarURL = *info.Data.AvatarUrl
|
|
}
|
|
if info.Data.FullName != nil {
|
|
res.FullName = *info.Data.FullName
|
|
}
|
|
if info.Data.NickName != nil {
|
|
res.Nickname = *info.Data.NickName
|
|
}
|
|
|
|
if info.Data.GenderCode != nil {
|
|
gc, err := domain.GenderCodeToString(*info.Data.GenderCode)
|
|
if err != nil {
|
|
gc = "secret"
|
|
}
|
|
res.GenderCode = gc
|
|
}
|
|
|
|
if info.Data.Birthday != nil {
|
|
// RFC 3339
|
|
res.Birthdate = utils.UnixToRfc3339(*info.Data.Birthday)
|
|
}
|
|
|
|
if info.Data.Phone != nil {
|
|
res.PhoneNumber = *info.Data.Phone
|
|
}
|
|
|
|
if info.Data.Address != nil {
|
|
res.Address = *info.Data.Address
|
|
}
|
|
|
|
if info.Data.Email != nil {
|
|
res.Email = *info.Data.Email
|
|
}
|
|
|
|
return res, nil
|
|
}
|