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