fusenapi/server/home-user-auth/internal/logic/userbasicinfologic.go
2023-06-19 15:52:14 +08:00

54 lines
1.3 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,
IsEmailAdvertisement: *user.IsEmailAdvertisement,
IsOrderStatusPhone: *user.IsOrderStatusPhone,
IsPhoneAdvertisement: *user.IsPhoneAdvertisement,
IsOpenRender: *user.IsOpenRender,
IsLowRendering: *user.IsLowRendering,
IsRemoveBg: *user.IsRemoveBg,
})
}