145 lines
3.3 KiB
Go
145 lines
3.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/golang/protobuf/proto"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type ModifyMemberInfoLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 更新會員詳細資訊
|
|
func NewModifyMemberInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ModifyMemberInfoLogic {
|
|
return &ModifyMemberInfoLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *ModifyMemberInfoLogic) ModifyMemberInfo(req *types.BindingUserInfoReq) (*types.UserInfo, error) {
|
|
update := &memberProto.UpdateUserInfoReq{
|
|
Uid: domain.UID(l.ctx),
|
|
}
|
|
if req.Nickname != "" {
|
|
update.NickName = proto.String(req.Nickname)
|
|
}
|
|
|
|
if req.PreferredLanguage != "" {
|
|
update.Language = proto.String(req.PreferredLanguage)
|
|
}
|
|
|
|
if req.Currency != "" {
|
|
update.Currency = proto.String(req.Currency)
|
|
}
|
|
|
|
if req.AvatarURL != "" {
|
|
update.Avatar = proto.String(req.AvatarURL)
|
|
}
|
|
|
|
if req.FullName != "" {
|
|
update.FullName = proto.String(req.FullName)
|
|
}
|
|
|
|
if req.GenderCode != "" {
|
|
gc, err := domain.StringToGenderCode(req.GenderCode)
|
|
if err != nil {
|
|
gc = 0
|
|
}
|
|
update.Gender = proto.Int64(gc)
|
|
}
|
|
|
|
if req.Birthday != "" {
|
|
unix, err := utils.Rfc3339ToUnix(req.Birthday)
|
|
if err == nil {
|
|
update.Birthdate = proto.Int64(unix)
|
|
}
|
|
}
|
|
|
|
if req.Address != "" {
|
|
update.Address = proto.String(req.Address)
|
|
}
|
|
|
|
_, err := l.svcCtx.MemberRPC.UpdateUserInfo(l.ctx, update)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 再次取得資訊
|
|
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
|
|
}
|