fusenapi/server/home-user-auth/internal/logic/userbasicinfologic.go
2023-06-16 10:58:43 +08:00

54 lines
1.4 KiB
Go

package logic
import (
"context"
"fusenapi/model/gmodel"
"fusenapi/server/home-user-auth/internal/svc"
"fusenapi/server/home-user-auth/internal/types"
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"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 := gmodel.NewFsUserModel(l.svcCtx.MysqlConn)
user, err := m.FindUserById(l.ctx, userinfo.UserId)
if err != nil {
logx.Error(err)
return resp.SetStatus(basic.CodeServiceErr)
}
return resp.SetStatus(basic.CodeOK, types.DataUserBasicInfo{
Type: *user.Type,
IsOrderStatusEmail: *user.IsOrderStatusEmail > 0,
IsEmailAdvertisement: *user.IsEmailAdvertisement > 0,
IsOrderStatusPhone: *user.IsOrderStatusPhone > 0,
IsPhoneAdvertisement: *user.IsPhoneAdvertisement > 0,
IsOpenRender: *user.IsOpenRender > 0,
IsLowRendering: *user.IsLowRendering > 0,
IsRemoveBg: *user.IsRemoveBg > 0,
})
}