first commit
This commit is contained in:
@@ -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