fusenapi/server/home-user-auth/internal/logic/userbasicinfologic.go

53 lines
1.3 KiB
Go
Raw Normal View History

2023-06-01 10:35:09 +00:00
package logic
import (
"context"
2023-06-08 02:51:56 +00:00
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
2023-06-05 09:56:55 +00:00
"fusenapi/utils/auth"
"fusenapi/utils/basic"
2023-06-01 10:35:09 +00:00
"github.com/zeromicro/go-zero/core/logx"
)
type UserBasicInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserBasicInfoLogic {
return &UserBasicInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
2023-06-12 10:08:34 +00:00
func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) {
2023-06-15 08:08:43 +00:00
if !userinfo.IsUser() {
// 返回未授权
return resp.SetStatus(basic.CodeUnAuth)
2023-06-05 09:56:55 +00:00
}
2023-06-15 08:08:43 +00:00
2023-06-21 06:26:29 +00:00
m := l.svcCtx.AllModels.FsUser
2023-06-15 08:08:43 +00:00
user, err := m.FindUserById(l.ctx, userinfo.UserId)
2023-06-05 09:56:55 +00:00
if err != nil {
logx.Error(err)
2023-06-15 08:08:43 +00:00
return resp.SetStatus(basic.CodeServiceErr)
2023-06-05 09:56:55 +00:00
}
2023-06-15 08:08:43 +00:00
return resp.SetStatus(basic.CodeOK, types.DataUserBasicInfo{
Type: *user.Type,
2023-06-19 07:52:14 +00:00
IsOrderStatusEmail: *user.IsOrderStatusEmail,
IsEmailAdvertisement: *user.IsEmailAdvertisement,
IsOrderStatusPhone: *user.IsOrderStatusPhone,
IsPhoneAdvertisement: *user.IsPhoneAdvertisement,
IsOpenRender: *user.IsOpenRender,
IsLowRendering: *user.IsLowRendering,
IsRemoveBg: *user.IsRemoveBg,
2023-06-15 08:08:43 +00:00
})
2023-06-01 10:35:09 +00:00
}