Files
sam-api/app/Models/ESign/EsignSigner.php
김보곤 6958be1fd8 feat:E-Sign 전자계약 서명 솔루션 백엔드 구현
- 마이그레이션 4개 (esign_contracts, esign_signers, esign_sign_fields, esign_audit_logs)
- 모델 4개 (EsignContract, EsignSigner, EsignSignField, EsignAuditLog)
- 서비스 4개 (EsignContractService, EsignSignService, EsignPdfService, EsignAuditService)
- 컨트롤러 2개 (EsignContractController, EsignSignController)
- FormRequest 4개 (ContractStore, FieldConfigure, SignSubmit, SignReject)
- Mail 1개 (EsignRequestMail + 이메일 템플릿)
- API 라우트 (인증 계약 관리 + 토큰 기반 서명 프로세스)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 07:02:39 +09:00

105 lines
2.4 KiB
PHP

<?php
namespace App\Models\ESign;
use App\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class EsignSigner extends Model
{
use BelongsToTenant;
protected $table = 'esign_signers';
// 역할 상수
public const ROLE_CREATOR = 'creator';
public const ROLE_COUNTERPART = 'counterpart';
// 상태 상수
public const STATUS_WAITING = 'waiting';
public const STATUS_NOTIFIED = 'notified';
public const STATUS_AUTHENTICATED = 'authenticated';
public const STATUS_SIGNED = 'signed';
public const STATUS_REJECTED = 'rejected';
public const STATUSES = [
self::STATUS_WAITING,
self::STATUS_NOTIFIED,
self::STATUS_AUTHENTICATED,
self::STATUS_SIGNED,
self::STATUS_REJECTED,
];
protected $fillable = [
'tenant_id',
'contract_id',
'role',
'sign_order',
'name',
'email',
'phone',
'access_token',
'token_expires_at',
'otp_code',
'otp_expires_at',
'otp_attempts',
'auth_verified_at',
'signature_image_path',
'signed_at',
'consent_agreed_at',
'sign_ip_address',
'sign_user_agent',
'status',
'rejected_reason',
];
protected $casts = [
'sign_order' => 'integer',
'otp_attempts' => 'integer',
'token_expires_at' => 'datetime',
'otp_expires_at' => 'datetime',
'auth_verified_at' => 'datetime',
'signed_at' => 'datetime',
'consent_agreed_at' => 'datetime',
];
protected $hidden = [
'access_token',
'otp_code',
];
// === Relations ===
public function contract(): BelongsTo
{
return $this->belongsTo(EsignContract::class, 'contract_id');
}
public function signFields(): HasMany
{
return $this->hasMany(EsignSignField::class, 'signer_id');
}
// === Helpers ===
public function isVerified(): bool
{
return $this->auth_verified_at !== null;
}
public function hasSigned(): bool
{
return $this->signed_at !== null;
}
public function canSign(): bool
{
return $this->isVerified()
&& ! $this->hasSigned()
&& $this->status !== self::STATUS_REJECTED
&& $this->contract->canSign();
}
}