first commit
This commit is contained in:
60
apps/user/internal/logic/auth/loginuserlogic.go
Normal file
60
apps/user/internal/logic/auth/loginuserlogic.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package authlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
jwtx "tianyuan-api/pkg/jwt"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type LoginUserLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewLoginUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginUserLogic {
|
||||
return &LoginUserLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 登录接口
|
||||
func (l *LoginUserLogic) LoginUser(in *user.LoginReq) (*user.LoginResp, error) {
|
||||
if in.Username == "" || in.Password == "" {
|
||||
return nil, errors.New("用户名或密码不能为空")
|
||||
}
|
||||
// 使用 FindOneByUsername 查找用户
|
||||
users, err := l.svcCtx.UserModel.FindOneByUsername(l.ctx, in.Username)
|
||||
if err != nil {
|
||||
return nil, errors.New("用户未注册")
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
if hashPassword(in.Password) != users.Password {
|
||||
return nil, errors.New("密码错误")
|
||||
}
|
||||
|
||||
// 生成 JWT token,调用封装好的函数
|
||||
token, err := jwtx.GenerateJwtToken(users.Id, l.svcCtx.Config.AuthJWT.AccessSecret, l.svcCtx.Config.AuthJWT.AccessExpire)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user.LoginResp{
|
||||
Token: token,
|
||||
}, nil
|
||||
}
|
||||
func hashPassword(password string) string {
|
||||
h := sha256.New()
|
||||
h.Write([]byte(password))
|
||||
return hex.EncodeToString(h.Sum(nil))
|
||||
}
|
||||
62
apps/user/internal/logic/auth/phoneloginuserlogic.go
Normal file
62
apps/user/internal/logic/auth/phoneloginuserlogic.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package authlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
jwtx "tianyuan-api/pkg/jwt"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PhoneLoginUserLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewPhoneLoginUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PhoneLoginUserLogic {
|
||||
return &PhoneLoginUserLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 手机登录接口
|
||||
func (l *PhoneLoginUserLogic) PhoneLoginUser(in *user.PhoneLoginReq) (*user.LoginResp, error) {
|
||||
// 从 Redis 获取验证码
|
||||
savedCode, err := l.svcCtx.Redis.Get(fmt.Sprintf("login:%s", in.Phone))
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.New("验证码已过期")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 验证码不匹配
|
||||
if savedCode != in.Code {
|
||||
return nil, errors.New("验证码不正确")
|
||||
}
|
||||
// 查询用户是否存在,如果不存在则注册新用户
|
||||
users, err := l.svcCtx.UserModel.FindOneByPhone(l.ctx, in.Phone)
|
||||
if errors.Is(err, sqlx.ErrNotFound) {
|
||||
return nil, errors.New("手机号未注册")
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
token, err := jwtx.GenerateJwtToken(users.Id, l.svcCtx.Config.AuthJWT.AccessSecret, l.svcCtx.Config.AuthJWT.AccessExpire)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user.LoginResp{
|
||||
Token: token,
|
||||
}, nil
|
||||
}
|
||||
136
apps/user/internal/logic/auth/registeruserlogic.go
Normal file
136
apps/user/internal/logic/auth/registeruserlogic.go
Normal file
@@ -0,0 +1,136 @@
|
||||
package authlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/redis"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"tianyuan-api/apps/user/internal/model"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type RegisterUserLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewRegisterUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterUserLogic {
|
||||
return &RegisterUserLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 注册接口
|
||||
func (l *RegisterUserLogic) RegisterUser(in *user.RegisterReq) (*user.EmptyResponse, error) {
|
||||
// 检查密码是否一致
|
||||
if in.Password != in.ConfirmPassword {
|
||||
return nil, errors.New("密码不一致")
|
||||
}
|
||||
// 检查密码强度
|
||||
if err := checkPasswordStrength(in.Password); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 校验手机号码
|
||||
err := validatePhoneNumber(in.Phone)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 从 Redis 获取验证码
|
||||
savedCode, err := l.svcCtx.Redis.Get(fmt.Sprintf("register:%s", in.Phone))
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
return nil, errors.New("验证码已过期")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 验证码不匹配
|
||||
if savedCode != in.Code {
|
||||
return nil, errors.New("验证码不正确")
|
||||
}
|
||||
// 检查用户名是否已经存在
|
||||
existingUser, err := l.svcCtx.UserModel.FindOneByUsername(l.ctx, in.Username)
|
||||
if err != nil && err != sqlc.ErrNotFound {
|
||||
// 如果发生其他错误,返回错误
|
||||
return nil, err
|
||||
}
|
||||
if existingUser != nil {
|
||||
// 用户名已经存在,返回错误
|
||||
return nil, errors.New("用户名已存在,请选择其他用户名")
|
||||
}
|
||||
|
||||
// 检查手机号是否已经存在
|
||||
existingPhone, err := l.svcCtx.UserModel.FindOneByPhone(l.ctx, in.Phone)
|
||||
if err != nil && err != sqlc.ErrNotFound {
|
||||
// 如果发生其他错误,返回错误
|
||||
return nil, err
|
||||
}
|
||||
if existingPhone != nil {
|
||||
// 用户名已经存在,返回错误
|
||||
return nil, errors.New("手机号码已存在,请选择其他用户名")
|
||||
}
|
||||
// 加密密码
|
||||
hashedPassword := hashPassword(in.Password)
|
||||
|
||||
// 构建 Users 结构体
|
||||
users := &model.Users{
|
||||
Username: in.Username,
|
||||
Password: hashedPassword,
|
||||
Phone: in.Phone,
|
||||
AuthStatus: "unverified",
|
||||
}
|
||||
|
||||
// 调用 Insert 方法插入用户数据
|
||||
_, err = l.svcCtx.UserModel.Insert(l.ctx, users)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user.EmptyResponse{}, nil
|
||||
}
|
||||
|
||||
// 密码强度检查
|
||||
func checkPasswordStrength(password string) error {
|
||||
// 检查密码长度是否不少于8位
|
||||
if len(password) < 8 {
|
||||
return errors.New("密码长度不能少于8位")
|
||||
}
|
||||
|
||||
// 检查密码是否为简单重复的字符(如"11111111" 或 "aaaaaaaa"等)
|
||||
firstChar := password[0]
|
||||
if strings.Count(password, string(firstChar)) == len(password) {
|
||||
return errors.New("密码不能是重复的字符")
|
||||
}
|
||||
|
||||
// 正则表达式:密码必须包含数字或字母,不能是全符号
|
||||
var passwordRegex = `^[A-Za-z0-9]+$`
|
||||
match, _ := regexp.MatchString(passwordRegex, password)
|
||||
if !match {
|
||||
return errors.New("密码只能包含字母和数字")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// 校验手机号码的函数
|
||||
func validatePhoneNumber(phone string) error {
|
||||
// 定义正则表达式,匹配中国大陆的手机号格式
|
||||
var phoneRegex = `^1[3-9]\d{9}$`
|
||||
|
||||
// 检查手机号是否匹配正则表达式
|
||||
match, _ := regexp.MatchString(phoneRegex, phone)
|
||||
if !match {
|
||||
return errors.New("手机号码格式不正确")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package enterpriselogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"tianyuan-api/apps/user/internal/model"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type CreateEnterpriseAuthLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewCreateEnterpriseAuthLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateEnterpriseAuthLogic {
|
||||
return &CreateEnterpriseAuthLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *CreateEnterpriseAuthLogic) CreateEnterpriseAuth(in *user.EnterpriseAuthReq) (*user.EmptyResponse, error) {
|
||||
|
||||
users, err := l.svcCtx.UserModel.FindOne(l.ctx, in.UserId)
|
||||
if err != nil || users == nil {
|
||||
return nil, errors.New("查询用户错误")
|
||||
}
|
||||
|
||||
if users.AuthStatus == "approved" || users.AuthStatus == "pending" {
|
||||
return nil, errors.New("当前企业认证已审核通过或正在审核中,无法重复认证")
|
||||
}
|
||||
|
||||
// 构建企业认证对象
|
||||
var enterpriseAuth model.EnterpriseAuth
|
||||
enterpriseAuth.UserId = in.UserId
|
||||
enterpriseAuth.EnterpriseName = in.EnterpriseName
|
||||
enterpriseAuth.EnterpriseContact = in.EnterpriseContact
|
||||
enterpriseAuth.AuthStatus = "pending"
|
||||
enterpriseAuth.BusinessLicense = in.BusinessLicense
|
||||
enterpriseAuth.LegalPerson = in.LegalPerson
|
||||
enterpriseAuth.CreditCode = in.CreditCode
|
||||
users.AuthStatus = "pending"
|
||||
// 使用事务更新企业认证和用户认证状态
|
||||
err = l.svcCtx.EnterpriseAuthModel.TransCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
// 插入和更新操作放在事务中
|
||||
if _, err := l.svcCtx.EnterpriseAuthModel.InsertEnterpriseAuthTrans(ctx, &enterpriseAuth, session); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = l.svcCtx.UserModel.UpdateUserTrans(ctx, users, session)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &user.EmptyResponse{}, nil
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package enterpriselogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetPendingEnterpriseLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetPendingEnterpriseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetPendingEnterpriseLogic {
|
||||
return &GetPendingEnterpriseLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 获取待审核企业列表
|
||||
func (l *GetPendingEnterpriseLogic) GetPendingEnterprise() (*user.GetPendingEnterpriseResp, error) {
|
||||
// 调用 Model 层获取待审核企业列表
|
||||
enterprises, total, err := l.svcCtx.EnterpriseAuthModel.FindPendingList(l.ctx, in.Page, in.PageSize)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 构造返回的企业列表
|
||||
var list []*user.EnterpriseItem
|
||||
for _, e := range enterprises {
|
||||
list = append(list, &user.EnterpriseItem{
|
||||
Id: e.Id,
|
||||
EnterpriseName: e.EnterpriseName,
|
||||
CreditCode: e.CreditCode,
|
||||
LegalPerson: e.LegalPerson,
|
||||
EnterpriseContact: e.EnterpriseContact,
|
||||
AuthStatus: e.AuthStatus,
|
||||
BusinessLicense: e.BusinessLicense,
|
||||
CreatedAt: e.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: e.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
})
|
||||
}
|
||||
|
||||
return &user.GetPendingEnterpriseResp{
|
||||
Total: total,
|
||||
List: list,
|
||||
}, nil
|
||||
}
|
||||
91
apps/user/internal/logic/enterprise/reviewenterpriselogic.go
Normal file
91
apps/user/internal/logic/enterprise/reviewenterpriselogic.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package enterpriselogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"tianyuan-api/apps/sentinel/client/secret"
|
||||
"tianyuan-api/apps/user/internal/model"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ReviewEnterpriseLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewReviewEnterpriseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReviewEnterpriseLogic {
|
||||
return &ReviewEnterpriseLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 审核企业
|
||||
func (l *ReviewEnterpriseLogic) ReviewEnterprise(in *user.ReviewEnterpriseReq) (*user.EmptyResponse, error) {
|
||||
enterpriseAuth, err := l.svcCtx.EnterpriseAuthModel.FindOne(l.ctx, in.EnterpriseId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if enterpriseAuth == nil {
|
||||
return nil, errors.New("无ID相关认证")
|
||||
}
|
||||
if enterpriseAuth.AuthStatus != "pending" {
|
||||
return nil, errors.New("该认证不需要审核")
|
||||
}
|
||||
enterpriseAuth.AuthStatus = in.Status
|
||||
err = l.svcCtx.EnterpriseAuthModel.TransCtx(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
// 更新 EnterpriseAuth
|
||||
_, updateAuthErr := l.svcCtx.EnterpriseAuthModel.UpdateEnterpriseAuthTrans(ctx, enterpriseAuth, session)
|
||||
if updateAuthErr != nil {
|
||||
return updateAuthErr
|
||||
}
|
||||
|
||||
// 查询用户信息
|
||||
users, findUserErr := l.svcCtx.UserModel.FindOneTrans(l.ctx, enterpriseAuth.UserId, session)
|
||||
if findUserErr != nil {
|
||||
return findUserErr
|
||||
}
|
||||
users.AuthStatus = in.Status
|
||||
// 更新用户信息
|
||||
_, updateUserErr := l.svcCtx.UserModel.UpdateUserTrans(ctx, users, session)
|
||||
if updateUserErr != nil {
|
||||
return updateUserErr
|
||||
}
|
||||
|
||||
if in.Status == "approved" {
|
||||
//审核通过
|
||||
var enterpriseInfo = model.EnterpriseInfo{
|
||||
UserId: enterpriseAuth.UserId,
|
||||
EnterpriseName: enterpriseAuth.EnterpriseName,
|
||||
EnterpriseContact: enterpriseAuth.EnterpriseContact,
|
||||
CreditCode: enterpriseAuth.CreditCode,
|
||||
LegalPerson: enterpriseAuth.LegalPerson,
|
||||
BusinessLicense: enterpriseAuth.BusinessLicense,
|
||||
}
|
||||
_, insertEnterpriseErr := l.svcCtx.EnterpriseModel.InsertEnterpriseInfoTrans(l.ctx, &enterpriseInfo, session)
|
||||
if insertEnterpriseErr != nil {
|
||||
return insertEnterpriseErr
|
||||
}
|
||||
|
||||
_, createSecretErr := l.svcCtx.SecretRpc.CreateSecret(l.ctx, &secret.CreateSecretRequest{
|
||||
UserId: enterpriseAuth.UserId,
|
||||
})
|
||||
if err != nil {
|
||||
return createSecretErr
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &user.EmptyResponse{}, nil
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package userlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetEnterpriseAuthStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewGetEnterpriseAuthStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetEnterpriseAuthStatusLogic {
|
||||
return &GetEnterpriseAuthStatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetEnterpriseAuthStatusLogic) GetEnterpriseAuthStatus(in *user.GetEnterpriseAuthStatusReq) (*user.GetEnterpriseAuthStatusResp, error) {
|
||||
// 查询企业信息
|
||||
enterprise, err := l.svcCtx.EnterpriseModel.FindOneByUserId(l.ctx, in.UserId)
|
||||
if err != nil {
|
||||
if errors.Is(err, sqlc.ErrNotFound) {
|
||||
return &user.GetEnterpriseAuthStatusResp{
|
||||
IsAuth: false,
|
||||
}, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if enterprise == nil {
|
||||
return &user.GetEnterpriseAuthStatusResp{
|
||||
IsAuth: false,
|
||||
}, nil
|
||||
}
|
||||
return &user.GetEnterpriseAuthStatusResp{
|
||||
IsAuth: true,
|
||||
}, nil
|
||||
}
|
||||
58
apps/user/internal/logic/user/userinfologic.go
Normal file
58
apps/user/internal/logic/user/userinfologic.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package userlogic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"tianyuan-api/apps/user/internal/svc"
|
||||
"tianyuan-api/apps/user/user"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoLogic {
|
||||
return &UserInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
func (l *UserInfoLogic) UserInfo(in *user.UserInfoReq) (*user.UserInfoResp, error) {
|
||||
// 查询用户信息
|
||||
users, err := l.svcCtx.UserModel.FindOne(l.ctx, in.UserId)
|
||||
if err != nil {
|
||||
return nil, errors.New("用户不存在")
|
||||
}
|
||||
|
||||
// 查询企业信息
|
||||
enterprise, err := l.svcCtx.EnterpriseModel.FindOneByUserId(l.ctx, users.Id)
|
||||
if err != nil && !errors.Is(err, sql.ErrNoRows) {
|
||||
return nil, errors.New("failed to query enterprise auth info")
|
||||
}
|
||||
|
||||
if enterprise == nil {
|
||||
return &user.UserInfoResp{
|
||||
Username: users.Username,
|
||||
Phone: users.Phone,
|
||||
EnterpriseAuthStatus: users.AuthStatus,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// 正常返回用户和企业信息
|
||||
return &user.UserInfoResp{
|
||||
Username: users.Username,
|
||||
Phone: users.Phone,
|
||||
EnterpriseAuthStatus: users.AuthStatus,
|
||||
EnterpriseName: enterprise.EnterpriseName,
|
||||
CreditCode: enterprise.CreditCode,
|
||||
LegalPerson: enterprise.LegalPerson,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user