fadd
This commit is contained in:
@@ -3,6 +3,7 @@ package entities
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"hyapi-server/internal/domains/certification/entities/value_objects"
|
||||
@@ -28,14 +29,17 @@ type Certification struct {
|
||||
CompletedAt *time.Time `json:"completed_at,omitempty" comment:"认证完成时间"`
|
||||
ContractFileCreatedAt *time.Time `json:"contract_file_created_at,omitempty" comment:"合同文件生成时间"`
|
||||
|
||||
// === e签宝相关信息 ===
|
||||
// === 签署平台(esign | fadada)===
|
||||
SignPlatform enums.SignPlatform `gorm:"type:varchar(20);index" json:"sign_platform,omitempty" comment:"签署平台: esign|fadada"`
|
||||
|
||||
// === 第三方认证/签署信息(字段名历史兼容,语义为平台无关)===
|
||||
AuthFlowID string `gorm:"type:varchar(500)" json:"auth_flow_id,omitempty" comment:"企业认证流程ID"`
|
||||
AuthURL string `gorm:"type:varchar(500)" json:"auth_url,omitempty" comment:"企业认证链接"`
|
||||
AuthURL string `gorm:"type:text" json:"auth_url,omitempty" comment:"企业认证链接"`
|
||||
ContractCode string `gorm:"type:varchar(100)" json:"contract_code,omitempty" comment:"合同/协议编号"`
|
||||
ContractFileID string `gorm:"type:varchar(500)" json:"contract_file_id,omitempty" comment:"合同文件ID"`
|
||||
EsignFlowID string `gorm:"type:varchar(500)" json:"esign_flow_id,omitempty" comment:"签署流程ID"`
|
||||
ContractURL string `gorm:"type:varchar(500)" json:"contract_url,omitempty" comment:"合同文件访问链接"`
|
||||
ContractSignURL string `gorm:"type:varchar(500)" json:"contract_sign_url,omitempty" comment:"合同签署链接"`
|
||||
EsignFlowID string `gorm:"type:varchar(500)" json:"esign_flow_id,omitempty" comment:"签署流程ID(兼容字段名)"`
|
||||
ContractURL string `gorm:"type:text" json:"contract_url,omitempty" comment:"合同文件访问链接(法大大下载链可能很长)"`
|
||||
ContractSignURL string `gorm:"type:text" json:"contract_sign_url,omitempty" comment:"合同签署链接(短链/长链)"`
|
||||
|
||||
// === 失败信息 ===
|
||||
FailureReason enums.FailureReason `gorm:"type:varchar(100)" json:"failure_reason,omitempty" comment:"失败原因"`
|
||||
@@ -238,8 +242,11 @@ func (c *Certification) RejectEnterpriseInfoReview(actorID, message string) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// 完成企业认证
|
||||
// 完成企业认证(幂等:已是 enterprise_verified 则跳过状态流转,便于中途失败后重试)
|
||||
func (c *Certification) CompleteEnterpriseVerification() error {
|
||||
if c.Status == enums.StatusEnterpriseVerified {
|
||||
return nil
|
||||
}
|
||||
if c.Status != enums.StatusInfoSubmitted {
|
||||
return fmt.Errorf("当前状态 %s 不允许完成企业认证", enums.GetStatusName(c.Status))
|
||||
}
|
||||
@@ -310,8 +317,12 @@ func (c *Certification) ApplyContract(EsignFlowID string, ContractSignURL string
|
||||
if err := c.TransitionTo(enums.StatusContractApplied, enums.ActorTypeUser, c.UserID, "用户申请合同签署"); err != nil {
|
||||
return err
|
||||
}
|
||||
c.EsignFlowID = EsignFlowID
|
||||
c.ContractSignURL = ContractSignURL
|
||||
if EsignFlowID != "" {
|
||||
c.EsignFlowID = EsignFlowID
|
||||
}
|
||||
if ContractSignURL != "" {
|
||||
c.ContractSignURL = ContractSignURL
|
||||
}
|
||||
now := time.Now()
|
||||
c.ContractFileCreatedAt = &now
|
||||
// 添加业务事件
|
||||
@@ -324,6 +335,18 @@ func (c *Certification) ApplyContract(EsignFlowID string, ContractSignURL string
|
||||
return nil
|
||||
}
|
||||
|
||||
// BindSignTask 企业认证完成后预创建签署任务(不改状态;乙方可先免签)
|
||||
func (c *Certification) BindSignTask(esignFlowID, contractSignURL string) {
|
||||
if esignFlowID != "" {
|
||||
c.EsignFlowID = esignFlowID
|
||||
}
|
||||
if contractSignURL != "" {
|
||||
c.ContractSignURL = contractSignURL
|
||||
}
|
||||
now := time.Now()
|
||||
c.ContractFileCreatedAt = &now
|
||||
}
|
||||
|
||||
// AddContractFileID 生成合同文件
|
||||
func (c *Certification) AddContractFileID(contractFileID string, contractURL string) error {
|
||||
c.ContractFileID = contractFileID
|
||||
@@ -500,13 +523,58 @@ func (c *Certification) CompleteCertification() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResolvedSignPlatform 解析签署平台(空则默认 e签宝,兼容历史数据)
|
||||
func (c *Certification) ResolvedSignPlatform() enums.SignPlatform {
|
||||
if enums.IsValidSignPlatform(c.SignPlatform) {
|
||||
return c.SignPlatform
|
||||
}
|
||||
return enums.DefaultSignPlatform()
|
||||
}
|
||||
|
||||
// ResetAfterSignTaskCreateFailed 签署任务未创建却已到 enterprise_verified 时,回退到待选平台
|
||||
func (c *Certification) ResetAfterSignTaskCreateFailed() error {
|
||||
if c.Status != enums.StatusEnterpriseVerified {
|
||||
return fmt.Errorf("当前状态 %s 无需回退", enums.GetStatusName(c.Status))
|
||||
}
|
||||
if strings.TrimSpace(c.EsignFlowID) != "" {
|
||||
return fmt.Errorf("签署任务已存在,不能回退到选平台")
|
||||
}
|
||||
c.Status = enums.StatusInfoPendingReview
|
||||
c.SignPlatform = ""
|
||||
c.AuthURL = ""
|
||||
c.AuthFlowID = ""
|
||||
c.ContractFileID = ""
|
||||
c.ContractURL = ""
|
||||
c.ContractSignURL = ""
|
||||
c.EsignFlowID = ""
|
||||
c.EnterpriseVerifiedAt = nil
|
||||
c.UpdatedAt = time.Now()
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetSignPlatform 设置签署平台(选定后锁定)
|
||||
func (c *Certification) SetSignPlatform(platform enums.SignPlatform) error {
|
||||
if !enums.IsValidSignPlatform(platform) {
|
||||
return fmt.Errorf("无效的签署平台: %s", platform)
|
||||
}
|
||||
if c.SignPlatform != "" && c.SignPlatform != platform {
|
||||
return fmt.Errorf("签署平台已选择为 %s,不可更改", enums.GetSignPlatformName(c.SignPlatform))
|
||||
}
|
||||
c.SignPlatform = platform
|
||||
return nil
|
||||
}
|
||||
|
||||
// ================ 查询方法 ================
|
||||
// GetDataByStatus 根据当前状态获取对应的数据
|
||||
func (c *Certification) GetDataByStatus() map[string]interface{} {
|
||||
data := map[string]interface{}{}
|
||||
if c.SignPlatform != "" {
|
||||
data["sign_platform"] = string(c.SignPlatform)
|
||||
data["sign_platform_name"] = enums.GetSignPlatformName(c.SignPlatform)
|
||||
}
|
||||
switch c.Status {
|
||||
case enums.StatusInfoPendingReview:
|
||||
// 待审核,无额外数据
|
||||
// 待审核/待选平台,额外元数据由应用层补充
|
||||
case enums.StatusInfoSubmitted:
|
||||
data["auth_url"] = c.AuthURL
|
||||
case enums.StatusInfoRejected:
|
||||
@@ -514,11 +582,24 @@ func (c *Certification) GetDataByStatus() map[string]interface{} {
|
||||
data["failure_message"] = c.FailureMessage
|
||||
case enums.StatusEnterpriseVerified:
|
||||
data["ContractURL"] = c.ContractURL
|
||||
data["contract_url"] = c.ContractURL
|
||||
if c.EsignFlowID != "" {
|
||||
data["esign_flow_id"] = c.EsignFlowID
|
||||
data["sign_task_ready"] = true
|
||||
}
|
||||
case enums.StatusContractApplied:
|
||||
data["contract_sign_url"] = c.ContractSignURL
|
||||
data["ContractURL"] = c.ContractURL
|
||||
data["contract_url"] = c.ContractURL
|
||||
if c.EsignFlowID != "" {
|
||||
data["esign_flow_id"] = c.EsignFlowID
|
||||
}
|
||||
case enums.StatusContractSigned:
|
||||
case enums.StatusCompleted:
|
||||
data["completed_at"] = c.CompletedAt
|
||||
if c.ContractURL != "" {
|
||||
data["contract_url"] = c.ContractURL
|
||||
}
|
||||
case enums.StatusContractRejected:
|
||||
data["failure_reason"] = c.FailureReason
|
||||
data["failure_message"] = c.FailureMessage
|
||||
|
||||
@@ -15,7 +15,9 @@ type ContractInfo struct {
|
||||
ContractFileID string `json:"contract_file_id"` // 合同文件ID
|
||||
EsignFlowID string `json:"esign_flow_id"` // e签宝签署流程ID
|
||||
ContractURL string `json:"contract_url"` // 合同文件访问链接
|
||||
ContractSignURL string `json:"contract_sign_url"` // 合同签署链接
|
||||
ContractSignURL string `json:"contract_sign_url"` // 合同签署链接(iframe 长链,可能短期有效)
|
||||
// ContractSignShortURL 短链(法大大不可 iframe;可选)
|
||||
ContractSignShortURL string `json:"contract_sign_short_url,omitempty"`
|
||||
|
||||
// 合同元数据
|
||||
ContractTitle string `json:"contract_title"` // 合同标题
|
||||
|
||||
Reference in New Issue
Block a user