first commit
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user