2023-06-01 10:35:09 +00:00
|
|
|
package logic
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-07-11 09:08:19 +00:00
|
|
|
"errors"
|
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-09-26 05:23:49 +00:00
|
|
|
|
2023-07-11 09:08:19 +00:00
|
|
|
"gorm.io/gorm"
|
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 {
|
2023-07-11 09:08:19 +00:00
|
|
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
return resp.SetStatusWithMessage(basic.CodeDbRecordNotFoundErr, "user is not exists")
|
|
|
|
}
|
2023-06-05 09:56:55 +00:00
|
|
|
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{
|
2023-09-26 05:23:49 +00:00
|
|
|
Type: *user.Type,
|
|
|
|
// 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
|
|
|
}
|