package logic import ( "context" "errors" "fusenapi/server/home-user-auth/internal/svc" "fusenapi/server/home-user-auth/internal/types" "fusenapi/utils/auth" "fusenapi/utils/basic" "gorm.io/gorm" "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, } } func (l *UserBasicInfoLogic) UserBasicInfo(req *types.Request, userinfo *auth.UserInfo) (resp *basic.Response) { if !userinfo.IsUser() { // 返回未授权 return resp.SetStatus(basic.CodeUnAuth) } m := l.svcCtx.AllModels.FsUser user, err := m.FindUserById(l.ctx, userinfo.UserId) if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user is not exists") } logx.Error(err) return resp.SetStatus(basic.CodeServiceErr) } return resp.SetStatus(basic.CodeOK, types.DataUserBasicInfo{ Type: *user.Type, IsOrderStatusEmail: *user.IsOrderStatusEmail, IsEmailAdvertisement: *user.IsEmailAdvertisement, IsOrderStatusPhone: *user.IsOrderStatusPhone, IsPhoneAdvertisement: *user.IsPhoneAdvertisement, IsOpenRender: *user.IsOpenRender, IsLowRendering: *user.IsLowRendering, IsRemoveBg: *user.IsRemoveBg, }) }