75 lines
2.6 KiB
PHP
75 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Business;
|
|
|
|
use App\Abstracts\Model;
|
|
use App\Support\EsignErrorMessage;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class CourierQuoteSignature extends Model
|
|
{
|
|
public const STATUS_PREPARED = 'prepared';
|
|
public const STATUS_SENDING = 'sending';
|
|
public const STATUS_SIGNING = 'signing';
|
|
public const STATUS_COMPLETED = 'completed';
|
|
public const STATUS_ARCHIVED = 'archived';
|
|
public const STATUS_REVOKED = 'revoked';
|
|
public const STATUS_EXPIRED = 'expired';
|
|
public const STATUS_REJECTED = 'rejected';
|
|
public const STATUS_FAILED = 'failed';
|
|
|
|
protected $table = 'business_courier_quote_signatures';
|
|
|
|
protected $fillable = [
|
|
'company_id', 'quote_version_id', 'provider', 'environment', 'status', 'organization_name',
|
|
'operator_name', 'operator_account', 'notice_types', 'expires_at', 'source_pdf_path',
|
|
'source_pdf_sha256', 'source_pdf_generated_at', 'esign_file_id', 'esign_sign_flow_id',
|
|
'remote_status', 'signed_pdf_path', 'signed_pdf_sha256', 'certificate_path',
|
|
'certificate_sha256', 'sent_at', 'completed_at', 'archived_at', 'last_synced_at',
|
|
'last_error', 'callback_payload_hash', 'created_by', 'updated_by',
|
|
];
|
|
|
|
protected $casts = [
|
|
'company_id' => 'integer',
|
|
'quote_version_id' => 'integer',
|
|
'expires_at' => 'datetime',
|
|
'source_pdf_generated_at' => 'datetime',
|
|
'sent_at' => 'datetime',
|
|
'completed_at' => 'datetime',
|
|
'archived_at' => 'datetime',
|
|
'last_synced_at' => 'datetime',
|
|
];
|
|
|
|
public function version(): BelongsTo
|
|
{
|
|
return $this->belongsTo(CourierQuoteVersion::class, 'quote_version_id');
|
|
}
|
|
|
|
public function statusLabel(): string
|
|
{
|
|
return match ($this->status) {
|
|
self::STATUS_PREPARED => '待推送',
|
|
self::STATUS_SENDING => '推送中',
|
|
self::STATUS_SIGNING => '待签署',
|
|
self::STATUS_COMPLETED => '签署完成,待归档',
|
|
self::STATUS_ARCHIVED => '已签署并归档',
|
|
self::STATUS_REVOKED => '已撤销',
|
|
self::STATUS_EXPIRED => '已过期',
|
|
self::STATUS_REJECTED => '已拒签',
|
|
self::STATUS_FAILED => '处理失败',
|
|
default => $this->status,
|
|
};
|
|
}
|
|
|
|
public function canSend(): bool
|
|
{
|
|
return in_array($this->status, [self::STATUS_PREPARED, self::STATUS_FAILED], true)
|
|
&& blank($this->esign_sign_flow_id);
|
|
}
|
|
|
|
public function lastErrorSummary(): ?string
|
|
{
|
|
return EsignErrorMessage::sanitize($this->last_error);
|
|
}
|
|
}
|