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
|
||||
}
|
||||
Reference in New Issue
Block a user