feat: complete courier e-sign workflow and PDF rendering

This commit is contained in:
limeng 2026-09-03 13:48:18 +08:00
parent 992e5a6da7
commit 7e64d24458
14 changed files with 985 additions and 95 deletions

View File

@ -3,9 +3,13 @@
namespace App\Http\Controllers\Business;
use App\Models\Business\CourierAgreementSignature;
use App\Models\Business\CourierQuoteSignature;
use App\Models\Business\CourierQuoteVersion;
use App\Models\Business\CourierSigningSubject;
use App\Services\Esign\EsignClient;
use App\Support\CourierAgreementSignatureService;
use App\Support\CourierQuoteConfirmation;
use App\Support\CourierQuoteSignatureService;
use App\Utilities\SystemAccess;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\JsonResponse;
@ -20,15 +24,27 @@ class CourierAgreementSignatures extends Controller
{
private const COOPERATION_SECONDARY_ESIGN_ACCOUNT = '18052733960';
public function __construct(private readonly CourierAgreementSignatureService $service)
{
public function __construct(
private readonly CourierAgreementSignatureService $service,
private readonly CourierQuoteSignatureService $quoteSignatureService,
private readonly CourierQuoteConfirmation $quoteConfirmation,
) {
}
public function store(Request $request): RedirectResponse
{
$this->ensureCanManage();
abort_unless(EsignClient::configured(), 422, 'E 签宝沙箱尚未配置 App ID 或 AppSecret。');
abort_unless(Schema::hasTable('business_courier_agreement_signatures'), 503, '协议签署数据表尚未完成迁移,请先执行数据库迁移。');
$requestedType = (string) $request->input('document_type');
if ($requestedType === 'quote-confirmation') {
abort_unless(
Schema::hasTable('business_courier_quote_versions') && Schema::hasTable('business_courier_quote_signatures'),
503,
'报价签署数据表尚未完成迁移,请先执行数据库迁移。',
);
} else {
abort_unless(Schema::hasTable('business_courier_agreement_signatures'), 503, '协议签署数据表尚未完成迁移,请先执行数据库迁移。');
}
if ($request->input('document_type') === 'cooperation-contract') {
// 合作合同统一由我方固定 E 签宝账号完成第二签署方签署。
@ -42,14 +58,39 @@ class CourierAgreementSignatures extends Controller
if ($type === 'authorization' && count($data['authorization_items'] ?? []) === 0) {
throw ValidationException::withMessages(['authorization_items' => '授权委托书至少选择一项授权事项。']);
}
if ($type === 'shared-contract') {
$sharedCouriers = collect($data['shared_courier_names'] ?? [])
->map(static fn ($name): string => trim((string) $name))
->filter()
->unique()
->values()
->all();
if ($sharedCouriers === [] && filled($data['shared_courier_name'] ?? null)) {
$sharedCouriers = [trim((string) $data['shared_courier_name'])];
}
if ($sharedCouriers === []) {
throw ValidationException::withMessages(['shared_courier_names' => '请至少填写一家共用合同的快递公司。']);
}
$data['shared_courier_names'] = $sharedCouriers;
// Keep the first name for old records and integrations that still read the scalar field.
$data['shared_courier_name'] = $sharedCouriers[0];
$data['shared_note'] = trim((string) ($data['shared_note'] ?? '')) ?: null;
}
$this->validateEsignAccount($data['esign_account'], 'esign_account');
if (! empty($data['secondary_esign_account'])) {
$this->validateEsignAccount($data['secondary_esign_account'], 'secondary_esign_account');
}
$data['organization_name'] = $data['signing_subject'];
if ($type === 'quote-confirmation') {
return $this->sendQuoteConfirmation($data);
}
// signing_subject identifies our initiating company. The E-sign
// organization must be the counterparty that receives this request.
$data['organization_name'] = $this->counterpartyOrganizationName($data);
$data['operator_name'] = $data['operator_name'] ?? $data['courier_name'];
$data['operator_account'] = $data['esign_account'];
$data['payload'] = $this->payload($data);
$signature = $this->service->send($data, user_id());
@ -179,6 +220,40 @@ class CourierAgreementSignatures extends Controller
return \Storage::disk('uploads')->download($path, $agreementSignature->business_no . '-' . $suffix . '.pdf', ['Content-Type' => 'application/pdf']);
}
public function synchronizeQuote(CourierQuoteSignature $quoteSignature): RedirectResponse
{
$this->ensureCanManage();
$signature = $this->quoteSignatureService->synchronize($quoteSignature, user_id());
return redirect()
->route('business.pages.show', ['section' => 'courier-payables', 'page' => 'agreement-signing', 'agreement_view' => 'tasks'])
->with('success', "报价确认单状态已同步:{$signature->statusLabel()}。");
}
public function downloadQuote(CourierQuoteSignature $quoteSignature, string $kind): StreamedResponse
{
$this->ensureCanManage();
[$path, $suffix] = match ($kind) {
'source' => [$quoteSignature->source_pdf_path, '报价确认单原文'],
'signed' => [$quoteSignature->signed_pdf_path, '已签署报价确认单'],
'certificate' => [$quoteSignature->certificate_path, '签署完成证书'],
default => abort(404),
};
abort_if(blank($path) || ! \Storage::disk('uploads')->exists($path), 404, '归档文件不存在。');
$versionCode = $quoteSignature->version?->version_code ?: (string) $quoteSignature->quote_version_id;
return \Storage::disk('uploads')->download($path, $versionCode . '-' . $suffix . '.pdf', ['Content-Type' => 'application/pdf']);
}
public function previewQuote(CourierQuoteVersion $quoteVersion): JsonResponse
{
$this->ensureCanManage();
abort_unless($quoteVersion->status === 'approved', 422, '只有已审核报价版本可以生成报价确认单。');
return response()->json($this->quoteConfirmation->data($quoteVersion));
}
private function rules(): array
{
$date = ['required', 'date', 'after_or_equal:today', 'before_or_equal:' . now()->addDays(90)->toDateString()];
@ -187,6 +262,7 @@ class CourierAgreementSignatures extends Controller
'idempotency_key' => ['required', 'string', 'max:80', 'regex:/^[A-Za-z0-9_-]+$/'],
'courier_name' => ['required', 'string', 'max:255'],
'document_type' => ['required', 'in:' . implode(',', array_keys(CourierAgreementSignature::DOCUMENTS))],
'quote_version_id' => ['required_if:document_type,quote-confirmation', 'nullable', 'integer', 'min:1'],
'signing_subject' => ['required', 'string', 'min:2', 'max:255'],
'company_full_name' => ['required', 'string', 'min:2', 'max:255'],
'signing_deadline' => $date,
@ -212,8 +288,11 @@ class CourierAgreementSignatures extends Controller
'changed_company_start_date' => ['required_if:document_type,entity-change', 'date'],
'entity_proof_date' => ['required_if:document_type,entity-change', 'date'],
'contract_partner_name' => ['required_if:document_type,shared-contract', 'string', 'max:255'],
'shared_courier_name' => ['required_if:document_type,shared-contract', 'string', 'max:255'],
'shared_proof_date' => ['required_if:document_type,shared-contract', 'date'],
'shared_courier_names' => ['nullable', 'array', 'min:1'],
'shared_courier_names.*' => ['required', 'string', 'max:255'],
'shared_courier_name' => ['nullable', 'string', 'max:255'],
'shared_proof_date' => ['nullable', 'date'],
'shared_note' => ['nullable', 'string', 'max:2000'],
'cooperation_party_a_name' => ['required_if:document_type,cooperation-contract', 'string', 'max:255'],
'cooperation_party_a_phone' => ['required_if:document_type,cooperation-contract', 'string', 'max:64'],
'cooperation_party_b_name' => ['required_if:document_type,cooperation-contract', 'string', 'max:255'],
@ -243,6 +322,50 @@ class CourierAgreementSignatures extends Controller
return $payload;
}
private function sendQuoteConfirmation(array $data): RedirectResponse
{
$version = CourierQuoteVersion::query()
->where('status', 'approved')
->findOrFail((int) $data['quote_version_id']);
$this->ensureQuoteVersionMatchesCourier($version, $data['courier_name']);
$signature = $this->quoteSignatureService->prepareVersion($version, user_id());
$account = trim((string) $data['esign_account']);
$signature = $this->quoteSignatureService->send($signature, [
'organization_name' => $version->carrier_name,
'operator_name' => trim((string) ($data['operator_name'] ?? '')) ?: $version->carrier_name,
'operator_account' => $account,
'notice_type' => filter_var($account, FILTER_VALIDATE_EMAIL) !== false ? '2' : '1',
'expires_at' => \Illuminate\Support\Carbon::parse($data['signing_deadline'])->endOfDay(),
], user_id());
return redirect()
->route('business.pages.show', ['section' => 'courier-payables', 'page' => 'agreement-signing', 'agreement_view' => 'tasks'])
->with('success', "报价确认单 {$version->version_code} 已推送到 E 签宝,等待快递方签署并自动回传归档。")
->with('quote_signature_id', $signature->id);
}
private function ensureQuoteVersionMatchesCourier(CourierQuoteVersion $version, string $courier): void
{
abort_unless(
trim($version->carrier_name) === trim($courier),
422,
'所选报价版本与快递公司不一致,请重新选择。',
);
}
private function counterpartyOrganizationName(array $data): string
{
return match ($data['document_type']) {
'account-proof' => trim((string) $data['account_proof_account_name']),
'account-change' => trim((string) $data['new_account_name']),
'shared-contract' => trim((string) (($data['shared_courier_names'][0] ?? null) ?: ($data['shared_courier_name'] ?? $data['courier_name']))),
'entity-change' => trim((string) ($data['former_company_name'] ?? $data['courier_name'])),
'authorization' => trim((string) ($data['principal_name'] ?? $data['courier_name'])),
default => trim((string) $data['courier_name']),
};
}
private function ensureCanManage(): void
{
abort_unless(

View File

@ -9,6 +9,8 @@ use App\Business\StoreReceivingAccountTemplate;
use App\Business\StoreReceivingAccountWorkbookImporter;
use App\Models\Banking\MarketingAccountBill;
use App\Models\Business\CourierAgreementSignature;
use App\Models\Business\CourierQuoteSignature;
use App\Models\Business\CourierQuoteVersion;
use App\Models\Business\CourierSigningSubject;
use App\Models\Business\InstallationDetail;
use App\Business\CourierSurchargeQuoteRepository;
@ -285,8 +287,10 @@ class Pages extends Controller
'inventoryData' => $this->inventoryContent($page['slug']),
'rawBoardData' => $this->rawBoardContent($page['slug']),
'agreementTasks' => $this->agreementTasks($page['slug']),
'agreementQuoteSignatures' => $this->agreementQuoteSignatures($page['slug']),
'agreementSubjects' => $this->agreementSubjects($page['slug']),
'agreementCourierAccounts' => $this->agreementCourierAccounts($page['slug']),
'agreementQuoteVersions' => $this->agreementQuoteVersions($page['slug']),
];
}
@ -336,8 +340,10 @@ class Pages extends Controller
'inventoryData' => $page ? $this->inventoryContent($page['slug']) : null,
'rawBoardData' => $page ? $this->rawBoardContent($page['slug']) : null,
'agreementTasks' => $this->agreementTasks($page['slug'] ?? null),
'agreementQuoteSignatures' => $this->agreementQuoteSignatures($page['slug'] ?? null),
'agreementSubjects' => $this->agreementSubjects($page['slug'] ?? null),
'agreementCourierAccounts' => $this->agreementCourierAccounts($page['slug'] ?? null),
'agreementQuoteVersions' => $this->agreementQuoteVersions($page['slug'] ?? null),
];
}
@ -438,6 +444,45 @@ class Pages extends Controller
}
}
protected function agreementQuoteSignatures(?string $page): Collection
{
if ($page !== 'agreement-signing') {
return collect();
}
try {
return CourierQuoteSignature::query()
->with('version')
->latest('id')
->limit(50)
->get();
} catch (QueryException $exception) {
// 报价签署迁移尚未执行时仍允许打开协议签署页。
report($exception);
return collect();
}
}
protected function agreementQuoteVersions(?string $page): Collection
{
if ($page !== 'agreement-signing') {
return collect();
}
try {
return CourierQuoteVersion::query()
->where('status', 'approved')
->orderByDesc('effective_date')
->orderByDesc('id')
->limit(100)
->get();
} catch (QueryException $exception) {
// 报价版本迁移尚未执行时仍允许打开协议签署页,报价确认单会提示暂无可选版本。
report($exception);
return collect();
}
}
protected function resolveContent(string $page, ?string $tab): ?array
{
return match ($page) {

View File

@ -54,6 +54,12 @@ class CourierAgreementSignature extends Model
'name' => '授权委托书',
'file' => '授权委托书(快递).docx',
],
'quote-confirmation' => [
'code' => 'TPL-QUOTE-CONFIRMATION-V1',
'version' => '1',
'name' => '报价确认单',
'file' => '报价确认单(报价版本快照).pdf',
],
];
protected $table = 'business_courier_agreement_signatures';
@ -106,4 +112,18 @@ class CourierAgreementSignature extends Model
{
return self::DOCUMENTS[$this->document_type]['name'] ?? $this->document_type;
}
/**
* The company that initiated the request is kept in the encrypted request
* snapshot. It is separate from organization_name, which is the E-sign
* signing organization for the counterparty.
*/
public function initiatorName(): string
{
$payloadName = trim((string) data_get($this->payload, 'signing_subject', ''));
return $payloadName !== ''
? $payloadName
: (trim((string) $this->company_full_name) ?: '—');
}
}

View File

@ -276,6 +276,21 @@ final class CourierAgreementSignatureService
private function signersFor(CourierAgreementSignature $signature): array
{
$payload = $signature->payload ?? [];
if (in_array($signature->document_type, ['account-proof', 'account-change'], true)) {
$name = $signature->organization_name;
$isOrganization = $this->looksLikeOrganization($name);
return [[
'signer_type' => $isOrganization ? 1 : 0,
'organization_name' => $isOrganization ? $name : null,
'operator_name' => $isOrganization
? ($signature->operator_name ?: $signature->courier_name)
: $name,
'operator_account' => $signature->operator_account,
]];
}
$primary = [
'signer_type' => 1,
'organization_name' => $signature->organization_name,
@ -330,6 +345,11 @@ final class CourierAgreementSignatureService
return [$primary];
}
private function looksLikeOrganization(string $name): bool
{
return preg_match('/公司|有限公司|有限责任|企业|集团|合作社|事务所|中心|厂/u', $name) === 1;
}
private function safeTitle(string $title): string
{
$title = preg_replace('/[^\p{Han}\p{L}\p{N}_ -]/u', '-', $title) ?: '协议签署';

View File

@ -0,0 +1,91 @@
<?php
namespace App\Support;
use App\Models\Business\CourierQuoteVersion;
final class CourierQuoteConfirmation
{
public function data(CourierQuoteVersion $version): array
{
$version->loadMissing(['change.items']);
$values = $this->decodeMatrix($version->values_json);
$nextVersion = CourierQuoteVersion::query()
->where('carrier_name', $version->carrier_name)
->where('quote_type', $version->quote_type)
->where('effective_date', '>', $version->effective_date)
->orderBy('effective_date')
->first();
return [
'version_id' => $version->id,
'version_code' => $version->version_code,
'party_a' => company((int) $version->company_id)?->name ?: '当前公司',
'party_b' => $version->carrier_name,
'carrier_name' => $version->carrier_name,
'quote_type' => $version->quote_type,
'effective_date' => $version->effective_date?->toDateString(),
'expiry_date' => $nextVersion?->effective_date?->copy()->subDay()->toDateString() ?: '长期',
'face_fee' => $this->matrixMetric($values, ['面单费', '面单费用', '面单']),
'bubble_coefficient' => $this->matrixMetric($values, ['计泡系数', '泡系数', '计泡']),
'values' => $values,
'formulas' => $this->decodeMatrix($version->formulas_json),
];
}
private function decodeMatrix(?string $json): array
{
if (blank($json)) {
return [];
}
$decoded = json_decode($json, true);
return is_array($decoded) ? $decoded : [];
}
private function matrixMetric(array $values, array $labels): string
{
foreach ($values as $rowIndex => $row) {
if (! is_array($row)) {
continue;
}
foreach (array_values($row) as $columnIndex => $cell) {
$text = trim((string) $cell);
foreach ($labels as $label) {
if ($text !== $label && ! str_contains($text, $label)) {
continue;
}
$inline = trim((string) preg_replace('/^.*?' . preg_quote($label, '/') . '\\s*[::=]?\\s*/u', '', $text));
if ($inline !== '' && $inline !== $text && $inline !== $label) {
return $inline;
}
$columnValues = [];
foreach (array_slice($values, $rowIndex + 1) as $nextRow) {
$value = is_array($nextRow) ? ($nextRow[$columnIndex] ?? null) : null;
if ($value !== null && trim((string) $value) !== '') {
$columnValues[] = trim((string) $value);
}
}
$columnValues = array_values(array_unique($columnValues));
if (count($columnValues) === 1) {
return $columnValues[0];
}
if (count($columnValues) > 1) {
return '详见报价明细';
}
$adjacent = $row[$columnIndex + 1] ?? null;
if ($adjacent !== null && trim((string) $adjacent) !== '') {
return trim((string) $adjacent);
}
}
}
}
return '按报价明细';
}
}

View File

@ -7,16 +7,22 @@ use RuntimeException;
final class CourierQuotePdf
{
public function __construct(private readonly CourierQuoteConfirmation $confirmation)
{
}
public function render(CourierQuoteVersion $version): string
{
$version->loadMissing(['change.items']);
$values = $this->decodeMatrix($version->values_json);
$formulas = $this->decodeMatrix($version->formulas_json);
$data = $this->confirmation->data($version);
$html = view('business.pdf.courier-quote', [
'version' => $version,
'change' => $version->change,
'values' => $values,
'formulas' => $formulas,
'values' => $data['values'],
'formulas' => $data['formulas'],
'partyA' => $data['party_a'],
'expiryDate' => $data['expiry_date'],
'faceFee' => $data['face_fee'],
'bubbleCoefficient' => $data['bubble_coefficient'],
'generatedAt' => now(),
'fontPath' => str_replace('\\', '/', resource_path('fonts/DroidSansFallback.ttf')),
])->render();
@ -32,15 +38,4 @@ final class CourierQuotePdf
return $bytes;
}
private function decodeMatrix(?string $json): array
{
if (blank($json)) {
return [];
}
$decoded = json_decode($json, true);
return is_array($decoded) ? $decoded : [];
}
}

View File

@ -114,7 +114,7 @@ final class QuoteManagementSnapshot
'row_count' => count($values),
'column_count' => $columnCount,
'formula_count' => $this->formulaCount($formulas),
'status' => '已审核待签署',
'status' => $this->versionLifecycleStatus($version),
'signature_status' => $version->signature_status,
'values' => $values,
'formulas' => $formulas,
@ -135,6 +135,15 @@ final class QuoteManagementSnapshot
}
}
private function versionLifecycleStatus(CourierQuoteVersion $version): string
{
if ($version->signature_status !== '已签署并归档') {
return '待生效(待签章)';
}
return $version->effective_date?->isFuture() ? '待生效' : '生效中';
}
private function normalizeMatrix(mixed $matrix): array
{
if (! is_array($matrix)) {

View File

@ -1,6 +1,9 @@
@php($agreementTasks = $agreementTasks ?? collect())
@php($agreementQuoteSignatures = $agreementQuoteSignatures ?? collect())
@php($agreementSubjects = $agreementSubjects ?? collect())
@php($agreementCourierAccounts = $agreementCourierAccounts ?? [])
@php($agreementQuoteVersions = $agreementQuoteVersions ?? collect())
@php($agreementCourierNames = collect(['新北中通', '新北中通其他', '新德邦快递', '睢宁中通', '武进极兔', '沭阳德邦', '常州圆通其他'])->merge($agreementQuoteVersions->pluck('carrier_name'))->filter()->unique()->values())
@php($agreementCooperationSecondaryEsignAccount = '18052733960')
@php($agreementDefaultSubject = $agreementSubjects->firstWhere('is_default', true) ?: $agreementSubjects->first())
@php($agreementCompanyName = $agreementDefaultSubject?->name ?: company()?->name ?: '当前公司')
@ -504,6 +507,27 @@
font-size: 15px;
}
.agreement-shared-courier-list {
display: grid;
gap: 0.5rem;
}
.agreement-shared-courier-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 0.5rem;
align-items: center;
}
.agreement-shared-courier-row .agreement-icon-button {
flex: 0 0 auto;
}
.agreement-shared-courier-add {
justify-self: start;
margin-top: 0.15rem;
}
.agreement-modal {
position: fixed;
z-index: 1000;
@ -926,6 +950,32 @@
gap: 0.5rem;
}
.agreement-preview-quote-matrix {
max-width: 100%;
margin: 1rem 0;
overflow-x: auto;
}
.agreement-preview-quote-matrix table {
width: 100%;
border-collapse: collapse;
font-size: 0.72rem;
}
.agreement-preview-quote-matrix th,
.agreement-preview-quote-matrix td {
min-width: 4.5rem;
border: 1px solid #E3DED4;
padding: 0.35rem 0.45rem;
text-align: left;
vertical-align: top;
}
.agreement-preview-quote-matrix th {
background: #F3EEE4;
font-weight: 600;
}
.agreement-preview-parties {
display: grid;
gap: 0.45rem;
@ -1133,6 +1183,7 @@
<option value="shared-contract">共用合同证明</option>
<option value="cooperation-contract">合作合同</option>
<option value="authorization">授权委托书</option>
<option value="quote-confirmation">报价确认单</option>
</select>
</div>
<button class="agreement-button" type="button" data-task-reset>
@ -1155,13 +1206,41 @@
</tr>
</thead>
<tbody>
@forelse ($agreementTasks as $task)
@foreach ($agreementQuoteSignatures as $quoteSignature)
@php($quoteVersion = $quoteSignature->version)
<tr>
<td>{{ $quoteVersion?->version_code ?? ('报价版本 #' . $quoteSignature->quote_version_id) }}</td>
<td>{{ $quoteVersion?->carrier_name ?? $quoteSignature->organization_name }}</td>
<td>报价确认单</td>
<td><span class="agreement-status agreement-status--{{ in_array($quoteSignature->status, ['archived', 'completed'], true) ? 'success' : (in_array($quoteSignature->status, ['failed', 'rejected', 'expired', 'revoked'], true) ? 'danger' : 'warning') }}">{{ $quoteSignature->statusLabel() }}</span></td>
<td>{{ $agreementCompanyName }}</td>
<td>{{ optional($quoteSignature->updated_at)->format('Y-m-d H:i') }}</td>
<td class="agreement-table-actions">
@if ($quoteSignature->esign_sign_flow_id && ! in_array($quoteSignature->status, ['archived', 'rejected', 'expired', 'revoked'], true))
<form method="POST" action="{{ route('business.courier-agreement-signatures.quotes.synchronize', $quoteSignature) }}">
@csrf
<button class="agreement-icon-button" type="submit" title="同步E签宝状态"><span class="material-icons-outlined" aria-hidden="true">sync</span></button>
</form>
@endif
@if ($quoteSignature->source_pdf_path)
<a class="agreement-icon-button" href="{{ route('business.courier-agreement-signatures.quotes.download', [$quoteSignature, 'source']) }}" title="下载报价确认单原文"><span class="material-icons-outlined" aria-hidden="true">picture_as_pdf</span></a>
@endif
@if ($quoteSignature->signed_pdf_path)
<a class="agreement-icon-button" href="{{ route('business.courier-agreement-signatures.quotes.download', [$quoteSignature, 'signed']) }}" title="下载已签署报价确认单"><span class="material-icons-outlined" aria-hidden="true">download</span></a>
@endif
@if ($quoteSignature->certificate_path)
<a class="agreement-icon-button" href="{{ route('business.courier-agreement-signatures.quotes.download', [$quoteSignature, 'certificate']) }}" title="下载签署完成证书"><span class="material-icons-outlined" aria-hidden="true">workspace_premium</span></a>
@endif
</td>
</tr>
@endforeach
@foreach ($agreementTasks as $task)
<tr>
<td>{{ $task->business_no }}</td>
<td>{{ $task->courier_name }}</td>
<td>{{ $task->documentLabel() }}</td>
<td><span class="agreement-status agreement-status--{{ in_array($task->status, ['archived', 'completed'], true) ? 'success' : (in_array($task->status, ['failed', 'rejected', 'expired', 'revoked'], true) ? 'danger' : 'warning') }}">{{ $task->statusLabel() }}</span></td>
<td>{{ $task->operator_name ?: '—' }}</td>
<td>{{ $task->initiatorName() }}</td>
<td>{{ optional($task->updated_at)->format('Y-m-d H:i') }}</td>
<td class="agreement-table-actions">
@if ($task->esign_sign_flow_id && ! in_array($task->status, ['archived', 'rejected', 'expired', 'revoked'], true))
@ -1184,7 +1263,8 @@
@endif
</td>
</tr>
@empty
@endforeach
@if ($agreementTasks->isEmpty() && $agreementQuoteSignatures->isEmpty())
<tr class="agreement-empty-row">
<td colspan="7">
<div class="agreement-empty">
@ -1200,7 +1280,7 @@
</div>
</td>
</tr>
@endforelse
@endif
</tbody>
</table>
</div>
@ -1229,7 +1309,7 @@
<label for="agreement-courier">快递公司 <span class="agreement-required" aria-hidden="true">*</span></label>
<select class="agreement-control" id="agreement-courier" name="courier_name" data-courier-select required>
<option value="">请选择</option>
@foreach (['新北中通', '新北中通其他', '新德邦快递', '睢宁中通', '武进极兔', '沭阳德邦', '常州圆通其他'] as $courierName)
@foreach ($agreementCourierNames as $courierName)
<option value="{{ $courierName }}" data-esign-account="{{ $agreementCourierAccounts[$courierName] ?? '' }}">{{ $courierName }}</option>
@endforeach
</select>
@ -1240,9 +1320,10 @@
<option value="account-proof" data-title="收款帐户资料证明" data-name="收款账户证明" data-code="TPL-ACCOUNT-CERT-V2" data-file="收款账户证明文件.doc" data-description="原文件:收款账户证明文件.doc;快递公司盖章" selected>收款账户证明</option>
<option value="account-change" data-title="收款帐户资料变更证明" data-name="收款账户变更" data-code="TPL-ACCOUNT-CHANGE-V1" data-file="收款账户变更证明.doc" data-description="原文件:收款账户变更证明.doc;快递公司盖章">收款账户变更</option>
<option value="entity-change" data-title="公司主体变更证明" data-name="公司主体变更" data-code="TPL-ENTITY-CHANGE-V1" data-file="公司主体变更证明.docx" data-description="原文件:公司主体变更证明.docx;变更前、变更后公司分别签字盖章">公司主体变更</option>
<option value="shared-contract" data-title="证明" data-name="共用合同证明" data-code="TPL-SHARED-CONTRACT-V1" data-file="共用合同证明.docx" data-description="原文件:共用合同证明.docx;法人签字并加盖公司公章">共用合同证明</option>
<option value="shared-contract" data-title="证明" data-name="共用合同证明" data-code="TPL-SHARED-CONTRACT-V1" data-file="共用合同证明.docx" data-description="两家快递共用一份合同、打款资料、签字人及法人均相同,需法人签字+公司盖章">共用合同证明</option>
<option value="cooperation-contract" data-title="服务协议" data-name="合作合同" data-code="TPL-COOPERATION-CONTRACT-V1" data-file="保丟不保损-合同发快递2024.8.doc" data-description="原文件:保丟不保损-合同发快递2024.8.doc;甲乙双方签署盖章">合作合同</option>
<option value="authorization" data-title="授权委托书" data-name="授权委托书" data-code="TPL-AUTHORIZATION-V1" data-file="授权委托书(快递).docx" data-description="原文件:授权委托书(快递).docx;委托方和受托方签署">授权委托书</option>
<option value="quote-confirmation" data-title="报价确认单" data-name="报价确认单" data-code="TPL-QUOTE-CONFIRMATION-V1" data-file="报价确认单(报价版本快照).pdf" data-description="绑定已审核报价版本;快递方单方签署">报价确认单</option>
</select>
</div>
@ -1283,7 +1364,19 @@
</div>
<div class="agreement-field">
<label for="agreement-operator-name">对方签署人姓名</label>
<input class="agreement-control" id="agreement-operator-name" name="operator_name" type="text" placeholder="可选,默认使用快递公司名称" autocomplete="name">
<input class="agreement-control" id="agreement-operator-name" name="operator_name" type="text" placeholder="可选,默认使用对方签署主体名称" autocomplete="name">
</div>
<div class="agreement-field" data-quote-confirmation-field hidden>
<label for="agreement-quote-version">报价版本 <span class="agreement-required" aria-hidden="true">*</span></label>
<select class="agreement-control" id="agreement-quote-version" name="quote_version_id" data-quote-version disabled required>
<option value="">请选择已审核报价版本</option>
@foreach ($agreementQuoteVersions as $quoteVersion)
<option value="{{ $quoteVersion->id }}" data-carrier="{{ $quoteVersion->carrier_name }}" data-quote-type="{{ $quoteVersion->quote_type }}" data-effective-date="{{ $quoteVersion->effective_date?->toDateString() }}" data-preview-url="{{ route('business.courier-agreement-signatures.quotes.preview', $quoteVersion) }}">
{{ $quoteVersion->version_code }} · {{ $quoteVersion->carrier_name }} · {{ $quoteVersion->quote_type }} · {{ $quoteVersion->effective_date?->toDateString() }}
</option>
@endforeach
</select>
<p class="agreement-help">确认单绑定已审核报价版本,生成后保存该版本快照;变价请生成新版本并重新签署。</p>
</div>
<div class="agreement-field" data-secondary-signer-fields hidden>
<label for="agreement-secondary-esign-account">第二签署方E签宝账号 <span class="agreement-required" aria-hidden="true">*</span></label>
@ -1377,16 +1470,26 @@
<div class="agreement-form-grid" data-template-fields="shared-contract" hidden>
<div class="agreement-field">
<label for="agreement-contract-partner">合同合作方 <span class="agreement-required" aria-hidden="true">*</span></label>
<input class="agreement-control" id="agreement-contract-partner" name="contract_partner_name" type="text" value="{{ $agreementCompanyName }}" required>
<label for="agreement-contract-partner">快递公司甲(主体) <span class="agreement-required" aria-hidden="true">*</span></label>
<input class="agreement-control" id="agreement-contract-partner" name="contract_partner_name" type="text" placeholder="与...合作的公司" required>
</div>
<div class="agreement-field">
<label for="agreement-shared-courier">共用合同的快递名称 <span class="agreement-required" aria-hidden="true">*</span></label>
<input class="agreement-control" id="agreement-shared-courier" name="shared_courier_name" type="text" placeholder="填写原文件第二处空白" required>
<div class="agreement-field agreement-field--full">
<label>共用合同的快递公司(可多个) <span class="agreement-required" aria-hidden="true">*</span></label>
<div class="agreement-shared-courier-list" data-shared-courier-list>
<div class="agreement-shared-courier-row">
<input class="agreement-control" name="shared_courier_names[]" type="text" placeholder="第1家快递公司名称" data-shared-courier required>
<button class="agreement-icon-button" type="button" data-shared-courier-remove disabled title="删除共用公司" aria-label="删除共用公司"><span class="material-icons-outlined" aria-hidden="true">delete</span></button>
</div>
</div>
<button class="agreement-inline-button agreement-shared-courier-add" type="button" data-shared-courier-add>
<span class="material-icons-outlined" aria-hidden="true">add</span>
<span>添加共用公司</span>
</button>
<p class="agreement-help">填写与快递公司甲共用同一份合同的快递公司,可添加多个。</p>
</div>
<div class="agreement-field">
<label for="agreement-shared-proof-date">证明日期 <span class="agreement-required" aria-hidden="true">*</span></label>
<input class="agreement-control" id="agreement-shared-proof-date" name="shared_proof_date" type="date" value="{{ now()->toDateString() }}" required>
<div class="agreement-field agreement-field--full">
<label for="agreement-shared-note">备注</label>
<textarea class="agreement-control" id="agreement-shared-note" name="shared_note" placeholder="如:请在3个工作日内完成签章,如有疑问请联系张晓华 138-xxxx-xxxx" data-shared-note></textarea>
</div>
</div>
@ -1472,7 +1575,7 @@
</div>
</section>
<fieldset class="agreement-form-section agreement-archive-fieldset">
<fieldset class="agreement-form-section agreement-archive-fieldset" data-archive-fieldset>
<legend class="agreement-section-heading">回传归档</legend>
<div class="agreement-archive-options">
<label class="agreement-archive-choice"><input type="radio" name="archive_mode" value="auto" checked><span><strong>签署完成后自动归档</strong><span>回传文件直接存入档案中心</span></span></label>
@ -1492,8 +1595,8 @@
<aside class="agreement-preview-pane" aria-label="协议实时预览" data-agreement-preview>
<header class="agreement-preview-header">
<h2 class="agreement-preview-title"><span class="material-icons-outlined" aria-hidden="true">preview</span><span>协议预览</span></h2>
<span class="agreement-preview-meta"><span data-preview-template-code>TPL-ACCOUNT-CERT-V2</span> · 原合同全文</span>
<h2 class="agreement-preview-title"><span class="material-icons-outlined" aria-hidden="true">preview</span><span>文件预览</span></h2>
<span class="agreement-preview-meta"><span data-preview-template-code>TPL-ACCOUNT-CERT-V2</span> · <span data-preview-status-hint>蓝色=已填 红色=待填</span></span>
</header>
<div class="agreement-preview-scroll">
<article class="agreement-preview-paper" data-template-preview="account-proof">
@ -1508,7 +1611,7 @@
<p>请贵公司按照上述汇款资料付款,如因我司提供收款银行帐户资料错误,导致相关款项支付不到位,则由此产生的一切经济纠纷和责任由我司承担。我司承诺若上述收款银行帐户资料发生变化及时书面通知贵公司。给贵公司带来的不便尽请谅解。</p>
<p>以上收款账户的变更,以我司的盖章为有效。</p>
<div class="agreement-preview-signature">
<p><span data-preview-bind="courier">快递公司</span> 公司盖章:</p>
<p><span data-preview-bind="proofSigner">待填写</span>:</p>
<p>日期:<span data-preview-bind="signatureDate">签署后生成</span></p>
</div>
<p class="agreement-preview-page-number">第 1 页 / 共 1 页</p>
@ -1526,7 +1629,7 @@
<p>请贵公司按照上述汇款资料付款,如因我司提供收款银行帐户资料错误,导致相关款项支付不到位,则由此产生的一切经济纠纷和责任由我司承担。我司承诺若上述收款银行帐户资料发生变化及时书面通知贵公司。给贵公司带来的不便尽请谅解。</p>
<p>以上收款账户的变更,以我司的盖章为有效。</p>
<div class="agreement-preview-signature">
<p><span data-preview-bind="courier">快递公司</span> 公司盖章:</p>
<p><span data-preview-bind="changeSigner">待填写</span>:</p>
<p>日期:<span data-preview-bind="signatureDate">签署后生成</span></p>
</div>
<p class="agreement-preview-page-number">第 1 页 / 共 1 页</p>
@ -1548,11 +1651,12 @@
<article class="agreement-preview-paper" data-template-preview="shared-contract" hidden>
<h3>证明</h3>
<p>与 <span class="agreement-preview-value" data-preview-bind="contractPartnerName">待填写</span> 合作的 <span class="agreement-preview-value" data-preview-bind="sharedCourierName">待填写</span> 快递共用同一份合同,打款资料为同一份资料,同一个签字人以及同一个法人!</p>
<p>与 <span class="agreement-preview-value" data-preview-bind="contractPartnerName">待填写</span> 合作的 <span class="agreement-preview-value" data-preview-bind="sharedCourierName">待填写</span> 共同用一份合同,打款资料为同一份资料,同一个签字人以及同一个法人!</p>
<p>特此证明!</p>
<p data-preview-shared-note hidden>备注:<span class="agreement-preview-value" data-preview-bind="sharedNote">待填写</span></p>
<div class="agreement-preview-signature">
<p>法人签字并公司盖章:</p>
<p>日期:<span data-preview-bind="sharedProofDate">待填写</span></p>
<p>日期:签署后生成</p>
</div>
<p class="agreement-preview-page-number">第 1 页 / 共 1 页</p>
</article>
@ -1588,6 +1692,25 @@
</div>
<p class="agreement-preview-page-number">第 1 页 / 共 1 页</p>
</article>
<article class="agreement-preview-paper" data-template-preview="quote-confirmation" hidden>
<h3>报价确认单</h3>
<div class="agreement-preview-account">
<div><span>报价版本:</span><span class="agreement-preview-value" data-preview-bind="quoteVersion">待选择</span></div>
<div><span>快递公司:</span><span class="agreement-preview-value" data-preview-bind="quoteCarrier">待选择</span></div>
<div><span>报价类型:</span><span class="agreement-preview-value" data-preview-bind="quoteType">待选择</span></div>
<div><span>甲方:</span><span class="agreement-preview-value" data-preview-bind="quotePartyA">{{ $agreementCompanyName }}</span></div>
<div><span>乙方:</span><span class="agreement-preview-value" data-preview-bind="quotePartyB">待选择</span></div>
<div><span>生效日期:</span><span class="agreement-preview-value" data-preview-bind="quoteEffectiveDate">待选择</span></div>
<div><span>失效日期:</span><span class="agreement-preview-value" data-preview-bind="quoteExpiryDate">按下一版本确定</span></div>
<div><span>面单费:</span><span class="agreement-preview-value" data-preview-bind="quoteFaceFee">按报价版本</span></div>
<div><span>计泡系数:</span><span class="agreement-preview-value" data-preview-bind="quoteBubbleCoefficient">按报价版本</span></div>
</div>
<p>双方确认以下报价版本作为快递服务结算依据。报价版本一经签署即形成独立留档,后续变价须生成新版本并重新签署。</p>
<div class="agreement-preview-quote-matrix" data-preview-bind="quoteMatrix">请选择报价版本后查看报价明细</div>
<div class="agreement-preview-signature"><p>乙方(快递方)签章:</p><p>日期:签署后生成</p></div>
<p class="agreement-preview-page-number">报价确认单 · 快递方单方签署</p>
</article>
</div>
</aside>
</div>
@ -1595,11 +1718,11 @@
<section class="agreement-panel" id="agreement-panel-templates" role="tabpanel" aria-labelledby="agreement-tab-templates" data-agreement-panel="templates" hidden>
<div class="agreement-template-summary">
<div class="agreement-template-summary__copy">
<div class="agreement-template-summary__copy">
<strong>协议模板清单</strong>
<p>已按6份原始Word文件分别映射字段、正文和签署角色;E签宝模板编号仍需在沙箱创建后绑定。</p>
<p>已按原始协议文件和报价版本快照分别映射字段、正文和签署角色;报价确认单只由快递方签署。</p>
</div>
<span class="agreement-status agreement-status--warning">6份原件已映射</span>
<span class="agreement-status agreement-status--warning">7种文件类型已映射</span>
</div>
<div class="agreement-table-wrap">
@ -1622,6 +1745,7 @@
<tr><td>共用合同证明</td><td>共用合同证明.docx</td><td>本地映射 V1</td><td>合同合作方、共用合同快递、证明日期</td><td>快递公司法人</td><td><span class="agreement-status agreement-status--warning">法人签字并盖章</span></td><td><button class="agreement-icon-button" type="button" disabled title="E签宝模板尚未创建"><span class="material-icons-outlined" aria-hidden="true">settings</span></button></td></tr>
<tr><td>合作合同</td><td>保丟不保损-合同发快递2024.8.doc</td><td>本地映射 V1</td><td>甲乙方名称、甲乙方电话、协议起止日期</td><td>甲方、乙方</td><td><span class="agreement-status agreement-status--warning">双方签字盖章</span></td><td><button class="agreement-icon-button" type="button" disabled title="E签宝模板尚未创建"><span class="material-icons-outlined" aria-hidden="true">settings</span></button></td></tr>
<tr><td>授权委托书</td><td>授权委托书(快递).docx</td><td>本地映射 V1</td><td>委托双方、授权事项、往来方、有效期</td><td>委托方、受托方</td><td><span class="agreement-status agreement-status--warning">双方签署</span></td><td><button class="agreement-icon-button" type="button" disabled title="E签宝模板尚未创建"><span class="material-icons-outlined" aria-hidden="true">settings</span></button></td></tr>
<tr><td>报价确认单</td><td>报价版本快照</td><td>本地映射 V1</td><td>版本号、快递公司、报价类型、有效期、报价明细</td><td>快递公司</td><td><span class="agreement-status agreement-status--warning">快递方签章</span></td><td><button class="agreement-icon-button" type="button" disabled title="E签宝模板尚未创建"><span class="material-icons-outlined" aria-hidden="true">settings</span></button></td></tr>
</tbody>
</table>
</div>
@ -1719,11 +1843,17 @@
var subjectCodeInput = root.querySelector('[data-subject-code]');
var courierSelect = root.querySelector('[data-courier-select]');
var esignAccountInput = root.querySelector('input[name="esign_account"]');
var sharedCourierList = root.querySelector('[data-shared-courier-list]');
var sharedCourierAdd = root.querySelector('[data-shared-courier-add]');
var quoteVersionField = root.querySelector('[data-quote-confirmation-field]');
var quoteVersionSelect = root.querySelector('[data-quote-version]');
var archiveFieldset = root.querySelector('[data-archive-fieldset]');
var subjects = @json($agreementSubjectPayload);
var fallbackSubjectName = @json($agreementCompanyName);
var cooperationSecondaryEsignAccount = @json($agreementCooperationSecondaryEsignAccount);
var secondaryEsignAccountInput = root.querySelector('input[name="secondary_esign_account"]');
var lastSubjectTrigger = null;
var quotePreviewRequest = 0;
function announce(message) {
if (announcer) {
@ -1973,6 +2103,58 @@
return field && field.value.trim() ? field.value.trim() : fallback;
}
function sharedCourierValues() {
if (!sharedCourierList) {
return [];
}
return Array.prototype.slice.call(sharedCourierList.querySelectorAll('[data-shared-courier]'))
.map(function (control) { return control.value.trim(); })
.filter(Boolean);
}
function updateSharedCourierRemoveButtons() {
if (!sharedCourierList) {
return;
}
var rows = sharedCourierList.querySelectorAll('.agreement-shared-courier-row');
rows.forEach(function (row) {
var remove = row.querySelector('[data-shared-courier-remove]');
if (remove) {
remove.disabled = rows.length <= 1;
}
});
}
function addSharedCourier() {
if (!sharedCourierList) {
return;
}
var firstRow = sharedCourierList.querySelector('.agreement-shared-courier-row');
if (!firstRow) {
return;
}
var row = firstRow.cloneNode(true);
var input = row.querySelector('[data-shared-courier]');
var remove = row.querySelector('[data-shared-courier-remove]');
var count = sharedCourierList.querySelectorAll('.agreement-shared-courier-row').length + 1;
if (input) {
input.value = '';
input.placeholder = '第' + count + '家快递公司名称';
input.disabled = false;
}
if (remove) {
remove.disabled = false;
}
sharedCourierList.appendChild(row);
updateSharedCourierRemoveButtons();
input && input.focus();
refreshPreview();
}
function syncEsignAccount() {
if (!courierSelect || !esignAccountInput) {
return;
@ -2020,6 +2202,28 @@
root.querySelectorAll('[data-template-preview]').forEach(function (preview) {
preview.hidden = preview.dataset.templatePreview !== templateType;
});
if (quoteVersionField && quoteVersionSelect) {
var quoteActive = templateType === 'quote-confirmation';
quoteVersionField.hidden = !quoteActive;
quoteVersionSelect.disabled = !quoteActive;
quoteVersionSelect.required = quoteActive;
if (!quoteActive) {
quoteVersionSelect.value = '';
}
if (archiveFieldset) {
var automaticArchive = archiveFieldset.querySelector('input[value="auto"]');
var manualArchive = archiveFieldset.querySelector('input[value="manual"]');
archiveFieldset.querySelector('legend').textContent = quoteActive ? '回传归档(报价确认单固定自动归档)' : '回传归档';
if (quoteActive && automaticArchive) {
automaticArchive.checked = true;
}
if (manualArchive) {
manualArchive.disabled = quoteActive;
}
}
}
}
function setPreviewValue(key, value) {
@ -2034,6 +2238,80 @@
});
}
function quoteVersionOption() {
if (!quoteVersionSelect || !quoteVersionSelect.value) {
return null;
}
return quoteVersionSelect.options[quoteVersionSelect.selectedIndex];
}
function renderQuoteMatrix(values, message) {
var target = root.querySelector('[data-template-preview="quote-confirmation"] [data-preview-bind="quoteMatrix"]');
if (!target) {
return;
}
target.textContent = '';
if (!Array.isArray(values) || values.length === 0) {
target.textContent = message || '该报价版本没有可展示的报价明细';
return;
}
var table = document.createElement('table');
var body = document.createElement('tbody');
values.forEach(function (row, rowIndex) {
var rowElement = document.createElement('tr');
(Array.isArray(row) ? row : [row]).forEach(function (cell) {
var cellElement = document.createElement(rowIndex === 0 ? 'th' : 'td');
cellElement.textContent = cell === null || cell === undefined ? '' : String(cell);
rowElement.appendChild(cellElement);
});
body.appendChild(rowElement);
});
table.appendChild(body);
target.appendChild(table);
}
async function loadQuotePreview() {
var option = quoteVersionOption();
var requestId = ++quotePreviewRequest;
if (!option || !option.dataset.previewUrl) {
renderQuoteMatrix([], '请选择报价版本后查看报价明细');
return;
}
renderQuoteMatrix([], '正在加载完整报价明细…');
try {
var response = await fetch(option.dataset.previewUrl, {
headers: { 'Accept': 'application/json' },
credentials: 'same-origin'
});
var payload = await response.json();
if (!response.ok) {
throw new Error(payload.message || '报价明细加载失败');
}
if (requestId !== quotePreviewRequest) {
return;
}
setPreviewValue('quoteVersion', payload.version_code || '待选择');
setPreviewValue('quoteCarrier', payload.carrier_name || '待选择');
setPreviewValue('quoteType', payload.quote_type || '待选择');
setPreviewValue('quotePartyA', payload.party_a || '待填写');
setPreviewValue('quotePartyB', payload.party_b || payload.carrier_name || '待选择');
setPreviewValue('quoteEffectiveDate', payload.effective_date || '待选择');
setPreviewValue('quoteExpiryDate', payload.expiry_date || '长期');
setPreviewValue('quoteFaceFee', payload.face_fee || '按报价明细');
setPreviewValue('quoteBubbleCoefficient', payload.bubble_coefficient || '按报价明细');
renderQuoteMatrix(payload.values, '该报价版本没有可展示的报价明细');
} catch (error) {
if (requestId === quotePreviewRequest) {
renderQuoteMatrix([], error.message || '报价明细加载失败,请重试');
}
}
}
function authorizationItemNumbers(templateType) {
var items = Array.prototype.slice.call(form.querySelectorAll('[data-authorization-item]'));
var selected = items.filter(function (item) {
@ -2094,6 +2372,8 @@
setPreviewValue('proofAccountName', fieldValue('[name="account_proof_account_name"]', '待填写'));
setPreviewValue('proofBankName', fieldValue('[name="account_proof_bank_name"]', '待填写'));
setPreviewValue('proofBankAccount', fieldValue('[name="account_proof_bank_account"]', '待填写'));
var proofName = fieldValue('[name="account_proof_account_name"]', '待填写');
setPreviewValue('proofSigner', proofName + (/(公司|有限公司|有限责任|企业|集团|合作社|事务所|中心|厂)/.test(proofName) ? ' 公司盖章' : ' 签字'));
}
if (templateType === 'account-change') {
@ -2105,6 +2385,8 @@
setPreviewValue('newAccountName', fieldValue('[name="new_account_name"]', '待填写'));
setPreviewValue('newBankName', fieldValue('[name="new_bank_name"]', '待填写'));
setPreviewValue('newBankAccount', fieldValue('[name="new_bank_account"]', '待填写'));
var changeName = fieldValue('[name="new_account_name"]', '待填写');
setPreviewValue('changeSigner', changeName + (/(公司|有限公司|有限责任|企业|集团|合作社|事务所|中心|厂)/.test(changeName) ? ' 公司盖章' : ' 签字'));
}
if (templateType === 'entity-change') {
@ -2117,8 +2399,13 @@
if (templateType === 'shared-contract') {
setPreviewValue('contractPartnerName', fieldValue('[name="contract_partner_name"]', companyName));
setPreviewValue('sharedCourierName', fieldValue('[name="shared_courier_name"]', courier === '快递公司' ? '待填写' : courier));
setPreviewValue('sharedProofDate', formatDateField('[name="shared_proof_date"]', '待填写'));
setPreviewValue('sharedCourierName', sharedCourierValues().join('、') || '待填写');
var sharedNote = fieldValue('[name="shared_note"]', '');
setPreviewValue('sharedNote', sharedNote || '待填写');
var sharedNotePreview = root.querySelector('[data-preview-shared-note]');
if (sharedNotePreview) {
sharedNotePreview.hidden = !sharedNote;
}
}
if (templateType === 'cooperation-contract') {
@ -2144,6 +2431,16 @@
} else {
authorizationItemNumbers(templateType);
}
if (templateType === 'quote-confirmation') {
var quoteOption = quoteVersionOption();
setPreviewValue('quoteVersion', quoteOption ? quoteOption.textContent.trim().split(' · ')[0] : '待选择');
setPreviewValue('quoteCarrier', quoteOption ? quoteOption.dataset.carrier : courier);
setPreviewValue('quoteType', quoteOption ? quoteOption.dataset.quoteType : '待选择');
setPreviewValue('quotePartyA', companyName);
setPreviewValue('quotePartyB', quoteOption ? quoteOption.dataset.carrier : courier);
setPreviewValue('quoteEffectiveDate', quoteOption ? quoteOption.dataset.effectiveDate : '待选择');
}
}
tabs.forEach(function (tab, index) {
@ -2271,6 +2568,46 @@
});
}
if (sharedCourierAdd) {
sharedCourierAdd.addEventListener('click', addSharedCourier);
}
if (sharedCourierList) {
sharedCourierList.addEventListener('click', function (event) {
var remove = event.target.closest('[data-shared-courier-remove]');
if (!remove || remove.disabled) {
return;
}
var row = remove.closest('.agreement-shared-courier-row');
if (row) {
row.remove();
updateSharedCourierRemoveButtons();
refreshPreview();
}
});
sharedCourierList.addEventListener('input', refreshPreview);
sharedCourierList.addEventListener('change', refreshPreview);
updateSharedCourierRemoveButtons();
}
if (quoteVersionSelect) {
quoteVersionSelect.addEventListener('change', function () {
var option = quoteVersionOption();
if (option && courierSelect && option.dataset.carrier) {
var courierOption = Array.prototype.slice.call(courierSelect.options).find(function (item) {
return item.value === option.dataset.carrier;
});
if (courierOption) {
courierSelect.value = option.dataset.carrier;
syncEsignAccount();
}
}
refreshPreview();
loadQuotePreview();
});
}
if (esignAccountInput) {
esignAccountInput.addEventListener('input', function () {
delete esignAccountInput.dataset.autoFilled;
@ -2283,6 +2620,9 @@
root.querySelector('[data-preview-refresh]').addEventListener('click', function () {
refreshPreview();
if (selectedDocument().value === 'quote-confirmation') {
loadQuotePreview();
}
announce('协议预览已刷新');
});

View File

@ -10,8 +10,8 @@
</div>
@else
<div class="cooperation-parties">
<div><span>甲 方:</span>{{ $payload['cooperation_party_a_name'] ?? '' }}<span class="party-phone">电 话:{{ $payload['cooperation_party_a_phone'] ?? '' }}</span></div>
<div><span>乙 方:</span>{{ $payload['cooperation_party_b_name'] ?? '' }}<span class="party-phone">电 话:{{ $payload['cooperation_party_b_phone'] ?? '' }}</span></div>
<div><span>甲 方:</span>{!! $mixedText($payload['cooperation_party_a_name'] ?? '') !!}<span class="party-phone">电 话:{!! $mixedText($payload['cooperation_party_a_phone'] ?? '') !!}</span></div>
<div><span>乙 方:</span>{!! $mixedText($payload['cooperation_party_b_name'] ?? '') !!}<span class="party-phone">电 话:{!! $mixedText($payload['cooperation_party_b_phone'] ?? '') !!}</span></div>
</div>
@endif
@ -23,9 +23,9 @@
<h4>第二条:协议期限</h4>
<p>2.1 本协议有效期:自
@if ($preview)<span class="agreement-preview-value" data-preview-bind="cooperationStartDate">待填写</span>@else{{ $payload['cooperation_start_date'] ?? '' }}@endif
@if ($preview)<span class="agreement-preview-value" data-preview-bind="cooperationStartDate">待填写</span>@else{!! $mixedText($payload['cooperation_start_date'] ?? '') !!}@endif
至
@if ($preview)<span class="agreement-preview-value" data-preview-bind="cooperationEndDate">待填写</span>@else{{ $payload['cooperation_end_date'] ?? '' }}@endif
@if ($preview)<span class="agreement-preview-value" data-preview-bind="cooperationEndDate">待填写</span>@else{!! $mixedText($payload['cooperation_end_date'] ?? '') !!}@endif
。</p>
<p>2.2 本协议有效期满后,双方若未重新签订协议,则本协议将自动延续至下一年度,延长协议有效期为一年。</p>
@ -133,5 +133,5 @@
<p>签约地:常州市</p>
</div>
@else
<div class="sign"><p>甲 方:{{ $payload['cooperation_party_a_name'] ?? '' }}</p><p>乙 方:{{ $payload['cooperation_party_b_name'] ?? '' }}</p><p>代表人:</p><p>代表人:</p><p>日 期:签署后生成</p><p>日 期:签署后生成</p><p>签约地:常州市</p></div>
<div class="sign"><p>甲 方:{!! $mixedText($payload['cooperation_party_a_name'] ?? '') !!}</p><p>乙 方:{!! $mixedText($payload['cooperation_party_b_name'] ?? '') !!}</p><p>代表人:</p><p>代表人:</p><p>日 期:签署后生成</p><p>日 期:签署后生成</p><p>签约地:常州市</p></div>
@endif

View File

@ -3,8 +3,10 @@
<head>
<meta charset="UTF-8">
<style>
@font-face { font-family: agreement-fallback; src: url('{{ $fontPath }}'); }
body { font-family: agreement-fallback, sans-serif; font-size: 13px; line-height: 1.8; color: #171717; }
@font-face { font-family: agreement-fallback; font-style: normal; font-weight: 400; src: url("file://{{ $fontPath }}") format("truetype"); }
@font-face { font-family: agreement-fallback; font-style: normal; font-weight: 700; src: url("file://{{ $fontPath }}") format("truetype"); }
body { font-family: agreement-fallback, sans-serif; font-size: 13px; font-weight: 400; line-height: 1.8; color: #171717; }
.latin { font-family: "DejaVu Sans", sans-serif; }
h1 { text-align: center; font-size: 20px; margin: 0 0 24px; }
h2 { font-size: 14px; margin: 18px 0 8px; }
h4 { font-size: 14px; margin: 18px 0 8px; }
@ -22,58 +24,81 @@
</style>
</head>
<body>
<div class="meta">业务单号:{{ $signature->business_no }} 模板:{{ $signature->template_code }}</div>
<h1>{{ $title }}</h1>
@php
$mixedText = static function ($value): string {
$parts = preg_split('/([\x20-\x7E]+)/', (string) $value, -1, PREG_SPLIT_DELIM_CAPTURE) ?: [];
return implode('', array_map(static function (string $part): string {
$escaped = e($part);
return preg_match('/^[\x20-\x7E]+$/', $part) === 1
? '<span class="latin">' . $escaped . '</span>'
: $escaped;
}, $parts));
};
@endphp
@php
$sharedCourierNames = array_values(array_filter(array_map(
static fn ($name): string => trim((string) $name),
$payload['shared_courier_names'] ?? [$payload['shared_courier_name'] ?? ''],
)));
$sharedCourierText = implode('、', $sharedCourierNames ?: ['待填写']);
@endphp
<div class="meta">业务单号:{!! $mixedText($signature->business_no) !!} 模板:{!! $mixedText($signature->template_code) !!}</div>
<h1>{!! $mixedText($title) !!}</h1>
@if ($type === 'account-proof')
<p>TO <strong>{{ $payload['company_full_name'] }}</strong>:</p>
<p>基于我公司正规化管理的需要,同时保证广大客户的汇款安全,我司同意自 {{ $payload['account_proof_effective_date'] }} 起我司货款(运费),请汇款至以下账户:</p>
<p><span class="latin">TO</span> <strong>{!! $mixedText($payload['company_full_name']) !!}</strong>:</p>
<p>基于我公司正规化管理的需要,同时保证广大客户的汇款安全,我司同意自 {!! $mixedText($payload['account_proof_effective_date']) !!} 起我司货款(运费),请汇款至以下账户:</p>
<div class="account">
<div>开户名称:{{ $payload['account_proof_account_name'] }}</div>
<div>开户银行:{{ $payload['account_proof_bank_name'] }}</div>
<div>银行帐户:{{ $payload['account_proof_bank_account'] }}</div>
<div>开户名称:{!! $mixedText($payload['account_proof_account_name']) !!}</div>
<div>开户银行:{!! $mixedText($payload['account_proof_bank_name']) !!}</div>
<div>银行帐户:{!! $mixedText($payload['account_proof_bank_account']) !!}</div>
</div>
<p>请贵公司按照上述汇款资料付款,如因我司提供收款银行帐户资料错误,导致相关款项支付不到位,则由此产生的一切经济纠纷和责任由我司承担。我司承诺若上述收款银行帐户资料发生变化及时书面通知贵公司。</p>
<p>以上收款账户的变更,以我司的盖章为有效。</p>
<div class="sign"><p>{{ $payload['courier_name'] }} 公司盖章:</p><p>日期:签署后生成</p></div>
<div class="sign"><p>公司盖章:</p><p>日期:签署后生成</p></div>
@elseif ($type === 'account-change')
<p>TO <strong>{{ $payload['company_full_name'] }}</strong>:</p>
<p>基于我公司正规化管理的需要,同时保证广大客户的汇款安全,我司收款账户将于 {{ $payload['account_change_date'] }} 变更账户,之前相应的账户(收款账户为:{{ $payload['old_account_name'] }},账号:{{ $payload['old_account_number'] }})于 {{ $payload['old_account_stop_date'] }} 停止使用,即日起我司收款的银行帐户进行变更,自 {{ $payload['new_account_effective_date'] }} 起我司与贵司往来款项请汇款至以下新账户,新汇款资料如下:</p>
<p><span class="latin">TO</span> <strong>{!! $mixedText($payload['company_full_name']) !!}</strong>:</p>
<p>基于我公司正规化管理的需要,同时保证广大客户的汇款安全,我司收款账户将于 {!! $mixedText($payload['account_change_date']) !!} 变更账户,之前相应的账户(收款账户为:{!! $mixedText($payload['old_account_name']) !!},账号:{!! $mixedText($payload['old_account_number']) !!})于 {!! $mixedText($payload['old_account_stop_date']) !!} 停止使用,即日起我司收款的银行帐户进行变更,自 {!! $mixedText($payload['new_account_effective_date']) !!} 起我司与贵司往来款项请汇款至以下新账户,新汇款资料如下:</p>
<div class="account">
<div>开户名称:{{ $payload['new_account_name'] }}</div>
<div>开户银行:{{ $payload['new_bank_name'] }}</div>
<div>银行账户:{{ $payload['new_bank_account'] }}</div>
<div>开户名称:{!! $mixedText($payload['new_account_name']) !!}</div>
<div>开户银行:{!! $mixedText($payload['new_bank_name']) !!}</div>
<div>银行账户:{!! $mixedText($payload['new_bank_account']) !!}</div>
</div>
<p>如因我司提供收款银行帐户资料错误导致相关款项支付不到位,由此产生的一切经济纠纷和责任由我司承担。以上收款账户的变更,以我司的盖章为有效。</p>
<div class="sign"><p>{{ $payload['courier_name'] }} 公司盖章:</p><p>日期:签署后生成</p></div>
<div class="sign"><p>公司盖章:</p><p>日期:签署后生成</p></div>
@elseif ($type === 'entity-change')
<p>致 <strong>{{ $payload['company_full_name'] }}</strong>:</p>
<p>我司由于企业名称变更,原公司名称 {{ $payload['former_company_name'] }} 于 {{ $payload['entity_change_date'] }} 变更为 {{ $payload['changed_company_name'] }},自 {{ $payload['changed_company_start_date'] }} 开始,我司将启用变更后的公司与贵公司开展工作,原公司名称停止使用。</p>
<p>致 <strong>{!! $mixedText($payload['company_full_name']) !!}</strong>:</p>
<p>我司由于企业名称变更,原公司名称 {!! $mixedText($payload['former_company_name']) !!} 于 {!! $mixedText($payload['entity_change_date']) !!} 变更为 {!! $mixedText($payload['changed_company_name']) !!},自 {!! $mixedText($payload['changed_company_start_date']) !!} 开始,我司将启用变更后的公司与贵公司开展工作,原公司名称停止使用。</p>
<p>变更后,原公司的各项事宜由变更后的公司继续执行。原公司的结算未付款项,由变更之后的公司提供的收款账户收款。原公司的业务和款项若出现法律上的纠纷,由变更后的公司承担责任。</p>
<p>特此证明!</p>
<div class="sign"><p>变更前公司法人签字盖公章:{{ $payload['former_company_name'] }}</p><p>变更后公司法人签字盖公章:{{ $payload['changed_company_name'] }}</p><p>日期:{{ $payload['entity_proof_date'] }}</p></div>
<div class="sign"><p>变更前公司法人签字盖公章:{!! $mixedText($payload['former_company_name']) !!}</p><p>变更后公司法人签字盖公章:{!! $mixedText($payload['changed_company_name']) !!}</p><p>日期:{!! $mixedText($payload['entity_proof_date']) !!}</p></div>
@elseif ($type === 'shared-contract')
<p>与 {{ $payload['contract_partner_name'] }} 合作的 {{ $payload['shared_courier_name'] }} 快递共用同一份合同,打款资料为同一份资料,同一个签字人以及同一个法人!</p>
<p>与 {!! $mixedText($payload['contract_partner_name'] ?? '') !!} 合作的 {!! $mixedText($sharedCourierText) !!} 共同用一份合同,打款资料为同一份资料,同一个签字人以及同一个法人!</p>
<p>特此证明!</p>
<div class="sign"><p>法人签字并公司盖章:</p><p>日期:{{ $payload['shared_proof_date'] }}</p></div>
@if (filled($payload['shared_note'] ?? null))
<p>备注:{!! $mixedText($payload['shared_note']) !!}</p>
@endif
<div class="sign"><p>法人签字并公司盖章:</p><p>日期:{!! $mixedText($payload['shared_proof_date'] ?? '签署后生成') !!}</p></div>
@elseif ($type === 'cooperation-contract')
@include('business.partials.cooperation-contract', ['mode' => 'pdf', 'payload' => $payload])
@else
<div class="account">
<div>委托方:{{ $payload['principal_name'] }}</div>
<div>身份证号/营业执照号:{{ $payload['principal_id_number'] }}</div>
<div>受托方:{{ $payload['trustee_name'] }}</div>
<div>身份证号/营业执照号:{{ $payload['trustee_id_number'] }}</div>
<div>委托方:{!! $mixedText($payload['principal_name']) !!}</div>
<div>身份证号/营业执照号:{!! $mixedText($payload['principal_id_number']) !!}</div>
<div>受托方:{!! $mixedText($payload['trustee_name']) !!}</div>
<div>身份证号/营业执照号:{!! $mixedText($payload['trustee_id_number']) !!}</div>
</div>
<p>兹委托 {{ $payload['trustee_name'] }} 为我或我司的代理人,全权代表我或我司办理下列第 {{ implode('、', $payload['authorization_items'] ?? []) }} 条事项:</p>
<p>兹委托 {!! $mixedText($payload['trustee_name']) !!} 为我或我司的代理人,全权代表我或我司办理下列第 {!! $mixedText(implode('、', $payload['authorization_items'] ?? [])) !!} 条事项:</p>
<ol class="list">
<li>代表委托方代签与 {{ $payload['bill_counterparty'] }} 的往来业务每月账单。</li>
<li>代表委托方代签与 {{ $payload['loan_counterparty'] }} 借支协议的事项。</li>
<li>代表委托方代签与 {!! $mixedText($payload['bill_counterparty']) !!} 的往来业务每月账单。</li>
<li>代表委托方代签与 {!! $mixedText($payload['loan_counterparty']) !!} 借支协议的事项。</li>
<li>代表委托方代签汇款账号变更的事项。</li>
<li>代表委托方代收 {{ $payload['payment_counterparty'] }} 的往来货款。</li>
<li>代表委托方代收 {!! $mixedText($payload['payment_counterparty']) !!} 的往来货款。</li>
</ol>
<p>委托有效期:从 {{ $payload['authorization_start_date'] }} 至 {{ $payload['authorization_end_date'] }} 止。</p>
<div class="sign"><p>委托方:{{ $payload['principal_name'] }}</p><p>受托方:{{ $payload['trustee_name'] }}</p><p>日期:签署后生成</p></div>
<p>委托有效期:从 {!! $mixedText($payload['authorization_start_date']) !!} 至 {!! $mixedText($payload['authorization_end_date']) !!} 止。</p>
<div class="sign"><p>委托方:{!! $mixedText($payload['principal_name']) !!}</p><p>受托方:{!! $mixedText($payload['trustee_name']) !!}</p><p>日期:签署后生成</p></div>
@endif
</body>
</html>

View File

@ -2,7 +2,7 @@
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>Quote {{ $version->version_code }}</title>
<title>报价确认单 {{ $version->version_code }}</title>
<style>
@font-face { font-family: "Droid Sans Fallback"; font-style: normal; font-weight: 400; src: url("file://{{ $fontPath }}") format("truetype"); }
@page { margin: 18mm 14mm 16mm; }
@ -19,6 +19,10 @@
.meta__item { display: table-cell; border-left: 2px solid #b69455; padding: 2px 9px; }
.meta dt { color: #666; font-size: 8px; }
.meta dd { margin-top: 2px; font-size: 10px; }
.details { width: 100%; margin-top: 12px; border-collapse: collapse; table-layout: fixed; }
.details th, .details td { border: 1px solid #cfcfcf; padding: 5px 7px; vertical-align: middle; }
.details th { width: 11%; background: #eee8db; font-weight: 400; white-space: nowrap; }
.details td { width: 22%; }
.notice { margin-top: 12px; border: 1px solid #c9b27f; background: #faf6ea; padding: 7px 9px; color: #5c451e; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { overflow-wrap: anywhere; border: 1px solid #cfcfcf; padding: 4px 5px; text-align: left; vertical-align: top; }
@ -51,8 +55,8 @@
@endphp
<header class="heading">
<div class="heading__title">
<h1>{!! $mixedText($version->company_name) !!} 报价单</h1>
<p>{!! $mixedText($version->quote_type) !!}</p>
<h1>报价确认单</h1>
<p>{!! $mixedText($version->carrier_name) !!} · {!! $mixedText($version->quote_type) !!}</p>
</div>
<div class="heading__mark">不可覆盖版本:{!! $mixedText($version->version_code) !!}</div>
</header>
@ -64,7 +68,27 @@
<div class="meta__item"><dt>审核日期</dt><dd>{!! $mixedText($change?->approved_at?->format('Y-m-d H:i') ?? $version->created_at?->format('Y-m-d H:i')) !!}</dd></div>
</dl>
<div class="notice">本文件由财务系统根据已审核报价版本自动生成。签署后文件与完成证书将按本版本单独归档;签署状态不代表历史运费补差已经完成。</div>
<table class="details">
<tbody>
<tr>
<th>甲方</th><td>{!! $mixedText($partyA) !!}</td>
<th>乙方</th><td>{!! $mixedText($version->carrier_name) !!}</td>
<th>报价类型</th><td>{!! $mixedText($version->quote_type) !!}</td>
</tr>
<tr>
<th>生效日期</th><td>{!! $mixedText($version->effective_date?->toDateString()) !!}</td>
<th>失效日期</th><td>{!! $mixedText($expiryDate) !!}</td>
<th>报价编号</th><td>{!! $mixedText($version->version_code) !!}</td>
</tr>
<tr>
<th>面单费</th><td>{!! $mixedText($faceFee) !!}</td>
<th>计泡系数</th><td>{!! $mixedText($bubbleCoefficient) !!}</td>
<th>签署要求</th><td>仅乙方(快递方)签章</td>
</tr>
</tbody>
</table>
<div class="notice">本文件由财务系统根据已审核报价版本自动生成。乙方签章后文件与完成证书将按本版本单独归档;后续变价须生成新版本并重新签章,旧确认单不会被覆盖。</div>
@if($change)
<h2>变价说明</h2>
@ -110,7 +134,7 @@
<section class="signature">
<h2>签署确认</h2>
<div class="signature__meta">报价版本:{!! $mixedText($version->version_code) !!} 快递公司:{!! $mixedText($version->carrier_name) !!} 执行日期:{!! $mixedText($version->effective_date?->toDateString()) !!}</div>
<div class="signature__box">快递公司签章<br><br>签署日期:</div>
<div class="signature__box">乙方(快递方)签章:{!! $mixedText($version->carrier_name) !!}<br><br>签署日期:</div>
<div class="document-control">生成时间:{!! $mixedText($generatedAt->format('Y-m-d H:i:s')) !!} · 版本 {!! $mixedText($version->version_code) !!}</div>
</section>
</body>

View File

@ -99,9 +99,12 @@ Route::prefix('workspace/courier-payables/agreement-signatures')
Route::post('subjects', [CourierAgreementSignatures::class, 'storeSubject'])->name('subjects.store');
Route::post('subjects/{subject}/update', [CourierAgreementSignatures::class, 'updateSubject'])->name('subjects.update');
Route::post('subjects/{subject}/default', [CourierAgreementSignatures::class, 'setDefaultSubject'])->name('subjects.default');
Route::get('quote-versions/{quoteVersion}/preview', [CourierAgreementSignatures::class, 'previewQuote'])->name('quotes.preview');
Route::post('{agreementSignature}/synchronize', [CourierAgreementSignatures::class, 'synchronize'])->name('synchronize');
Route::post('{agreementSignature}/archive', [CourierAgreementSignatures::class, 'archive'])->name('archive');
Route::get('{agreementSignature}/files/{kind}', [CourierAgreementSignatures::class, 'download'])->name('download');
Route::post('quote-signatures/{quoteSignature}/synchronize', [CourierAgreementSignatures::class, 'synchronizeQuote'])->name('quotes.synchronize');
Route::get('quote-signatures/{quoteSignature}/files/{kind}', [CourierAgreementSignatures::class, 'downloadQuote'])->name('quotes.download');
});
Route::get('workspace/product-inventory/normal-products/export', 'Business\Pages@exportNormalProducts')

View File

@ -3,6 +3,7 @@
namespace Tests\Feature\Business;
use App\Models\Auth\Permission;
use App\Models\Business\CourierAgreementSignature;
use App\Services\Esign\EsignClient;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Tests\Feature\FeatureTestCase;
@ -61,7 +62,9 @@ class AgreementSigningPageTest extends FeatureTestCase
->assertSeeText('TPL-ACCOUNT-CERT-V2')
->assertSeeText('我方签署主体')
->assertSeeText('公司全称')
->assertSee('name="company_full_name" type="text" value="My Company" data-company-name data-subject-linked-name', false)
->assertSee('name="company_full_name"', false)
->assertSee('data-company-name', false)
->assertSee('data-subject-linked-name', false)
->assertSeeText('签署截止日期')
->assertSeeText('对方E签宝账号')
->assertSeeText('合作合同统一使用我方账号 18052733960')
@ -73,6 +76,43 @@ class AgreementSigningPageTest extends FeatureTestCase
->assertSeeText('收款帐户资料证明');
}
public function testAgreementSigningPageShowsOurCompanyAsInitiator(): void
{
$this->grantWorkspaceAccess();
CourierAgreementSignature::create([
'company_id' => $this->company->id,
'business_no' => 'AGR-INITIATOR-001',
'idempotency_key' => 'initiator-001',
'document_type' => 'account-proof',
'template_code' => 'TPL-ACCOUNT-CERT-V2',
'template_version' => '2',
'source_file_name' => '收款账户证明文件.doc',
'status' => CourierAgreementSignature::STATUS_SIGNING,
'courier_name' => '新北中通',
'company_full_name' => $this->company->name,
'organization_name' => '新北中通',
'operator_name' => '张经理',
'operator_account' => '13800138000',
'payload' => ['signing_subject' => $this->company->name],
'environment' => 'sandbox',
'source_pdf_path' => 'courier-agreements/initiator/source.pdf',
'source_pdf_sha256' => hash('sha256', '%PDF-source'),
'esign_sign_flow_id' => 'flow-initiator-001',
'created_by' => $this->user->id,
'updated_by' => $this->user->id,
]);
$this->loginAs()
->get(route('business.pages.show', [
'section' => 'courier-payables',
'page' => 'agreement-signing',
]))
->assertOk()
->assertSee('<td>' . e($this->company->name) . '</td>', false)
->assertDontSee('<td>张经理</td>', false);
}
public function testAgreementSigningPageMapsEverySourceDocumentToItsOwnFieldsAndPreview(): void
{
$this->grantWorkspaceAccess();
@ -107,12 +147,22 @@ class AgreementSigningPageTest extends FeatureTestCase
->assertSee('data-template-fields="shared-contract"', false)
->assertSee('data-template-preview="shared-contract"', false)
->assertSeeText('合同合作方')
->assertSeeText('共用合同的快递名称')
->assertSeeText('共用同一份合同,打款资料为同一份资料')
->assertSeeText('快递公司甲(主体)')
->assertSeeText('共用合同的快递公司(可多个)')
->assertSee('name="shared_courier_names[]"', false)
->assertSee('data-shared-courier-add', false)
->assertSeeText('添加共用公司')
->assertSeeText('备注')
->assertSeeText('共同用一份合同,打款资料为同一份资料')
->assertSee('data-template-fields="cooperation-contract"', false)
->assertSee('data-template-preview="cooperation-contract"', false)
->assertSee('data-template-preview="quote-confirmation"', false)
->assertSee('data-quote-version', false)
->assertSeeText('报价确认单')
->assertSeeText('绑定已审核报价版本')
->assertSeeText('甲方名称')
->assertSee('name="cooperation_party_a_name" type="text" value="My Company" data-subject-linked-name', false)
->assertSee('name="cooperation_party_a_name"', false)
->assertSee('data-subject-linked-name', false)
->assertSeeText('乙方电话')
->assertSeeText('协议开始日期')
->assertSeeText('协议结束日期')

View File

@ -5,6 +5,9 @@ namespace Tests\Feature\Business;
use App\Jobs\Business\ArchiveCourierAgreementSignature;
use App\Models\Auth\Permission;
use App\Models\Business\CourierAgreementSignature;
use App\Models\Business\CourierQuoteChange;
use App\Models\Business\CourierQuoteSignature;
use App\Models\Business\CourierQuoteVersion;
use Illuminate\Http\Client\Request as ClientRequest;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Queue;
@ -45,9 +48,20 @@ class CourierAgreementSignatureWorkflowTest extends FeatureTestCase
$this->assertSame('TPL-ACCOUNT-CERT-V2', $signature->template_code);
$this->assertSame(CourierAgreementSignature::STATUS_SIGNING, $signature->status);
$this->assertSame('flow-agreement-001', $signature->esign_sign_flow_id);
$this->assertSame('新北中通快递有限公司', $signature->organization_name);
Storage::disk('uploads')->assertExists($signature->source_pdf_path);
$this->assertSame('新北中通快递有限公司', $signature->payload['account_proof_account_name']);
Http::assertSent(function (ClientRequest $request): bool {
if ($request->url() !== 'https://smlopenapi.esign.test/v3/sign-flow/create-by-file') {
return false;
}
return data_get($request->data(), 'signers.0.signerType') === 1
&& data_get($request->data(), 'signers.0.orgSignerInfo.orgName') === '新北中通快递有限公司'
&& data_get($request->data(), 'signers.0.orgSignerInfo.transactorInfo.psnInfo.psnName') === '张经理';
});
$this->loginAs()->post(route('business.courier-agreement-signatures.store'), $payload)->assertRedirect();
Http::assertSentCount(4);
$this->assertSame(1, CourierAgreementSignature::query()->count());
@ -66,6 +80,16 @@ class CourierAgreementSignatureWorkflowTest extends FeatureTestCase
$signature = CourierAgreementSignature::query()->firstOrFail();
$this->assertSame('李四', $signature->payload['account_proof_account_name']);
$this->assertNotSame($this->company->name, $signature->payload['account_proof_account_name']);
Http::assertSent(function (ClientRequest $request): bool {
if ($request->url() !== 'https://smlopenapi.esign.test/v3/sign-flow/create-by-file') {
return false;
}
return data_get($request->data(), 'signers.0.signerType') === 0
&& data_get($request->data(), 'signers.0.psnSignerInfo.psnInfo.psnName') === '李四'
&& data_get($request->data(), 'signers.0.orgSignerInfo') === null;
});
}
public function test_cooperation_contract_maps_party_variables_and_creates_two_signers(): void
@ -116,6 +140,127 @@ class CourierAgreementSignatureWorkflowTest extends FeatureTestCase
});
}
public function test_shared_contract_accepts_multiple_couriers_and_preserves_note_in_pdf(): void
{
$this->fakeEsign();
$this->loginAs()
->post(route('business.courier-agreement-signatures.store'), [
'idempotency_key' => 'shared-contract-multiple-001',
'courier_name' => '新北中通',
'document_type' => 'shared-contract',
'signing_subject' => $this->company->name,
'company_full_name' => $this->company->name,
'signing_deadline' => now()->addDays(7)->toDateString(),
'esign_account' => '13800138000',
'operator_name' => '张经理',
'archive_mode' => 'auto',
'contract_partner_name' => '快递公司甲',
'shared_courier_names' => ['快递公司乙', '快递公司丙'],
'shared_note' => '请在3个工作日内完成签章。',
])
->assertRedirect();
$signature = CourierAgreementSignature::query()->firstOrFail();
$this->assertSame(['快递公司乙', '快递公司丙'], $signature->payload['shared_courier_names']);
$this->assertSame('快递公司乙', $signature->payload['shared_courier_name']);
$this->assertSame('请在3个工作日内完成签章。', $signature->payload['shared_note']);
$pdf = Storage::disk('uploads')->get($signature->source_pdf_path);
$this->assertStringStartsWith('%PDF-', $pdf);
Http::assertSent(function (ClientRequest $request): bool {
if ($request->url() !== 'https://smlopenapi.esign.test/v3/sign-flow/create-by-file') {
return false;
}
return data_get($request->data(), 'signers.0.orgSignerInfo.orgName') === '快递公司乙';
});
}
public function test_quote_confirmation_binds_an_approved_version_and_uses_only_the_courier_signer(): void
{
$this->fakeEsign();
$version = CourierQuoteVersion::create([
'company_id' => $this->company->id,
'version_code' => 'QB-CONF-001',
'source_quote_id' => 'QB-001',
'source_change_id' => CourierQuoteChange::create([
'company_id' => $this->company->id,
'number' => 'BG-CONF-001',
'source_quote_id' => 'QB-001',
'source_sheet_name' => '新北中通报价',
'carrier_name' => '新北中通',
'quote_type' => '标准报价',
'change_type' => '面单调整',
'status' => CourierQuoteChange::STATUS_APPROVED,
'effective_date' => now()->addDay()->toDateString(),
'summary' => '报价确认单测试。',
'created_by' => $this->user->id,
'approved_by' => $this->user->id,
'approved_at' => now(),
])->id,
'sheet_name' => '新北中通报价',
'company_name' => $this->company->name,
'carrier_name' => '新北中通',
'quote_type' => '标准报价',
'effective_date' => now()->addDay()->toDateString(),
'values_json' => json_encode([
['地区', '面单费', '计泡系数'],
['广东省', 6.5, 1.2],
], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR),
'formulas_json' => json_encode([[], []], JSON_THROW_ON_ERROR),
'status' => 'approved',
'signature_status' => '未签署',
'created_by' => $this->user->id,
'approved_by' => $this->user->id,
]);
$this->loginAs()
->get(route('business.courier-agreement-signatures.quotes.preview', $version))
->assertOk()
->assertJsonPath('version_code', 'QB-CONF-001')
->assertJsonPath('carrier_name', '新北中通')
->assertJsonPath('face_fee', '6.5')
->assertJsonPath('bubble_coefficient', '1.2')
->assertJsonPath('values.1.0', '广东省');
$this->loginAs()
->post(route('business.courier-agreement-signatures.store'), [
'idempotency_key' => 'quote-confirmation-001',
'courier_name' => '新北中通',
'document_type' => 'quote-confirmation',
'quote_version_id' => $version->id,
'signing_subject' => $this->company->name,
'company_full_name' => $this->company->name,
'signing_deadline' => now()->addDays(7)->toDateString(),
'esign_account' => '13800138000',
'operator_name' => '李经理',
'archive_mode' => 'auto',
])
->assertRedirect();
$signature = CourierQuoteSignature::query()->firstOrFail();
$this->assertDatabaseCount('business_courier_agreement_signatures', 0);
$this->assertSame($version->id, $signature->quote_version_id);
$this->assertSame(CourierQuoteSignature::STATUS_SIGNING, $signature->status);
$this->assertSame('待签署', $version->fresh()->signature_status);
Storage::disk('uploads')->assertExists($signature->source_pdf_path);
$this->assertStringStartsWith('%PDF-', Storage::disk('uploads')->get($signature->source_pdf_path));
Http::assertSent(function (ClientRequest $request): bool {
if ($request->url() !== 'https://smlopenapi.esign.test/v3/sign-flow/create-by-file') {
return false;
}
$signers = $request->data()['signers'] ?? [];
return count($signers) === 1
&& ($signers[0]['signerType'] ?? null) === 1
&& ($signers[0]['orgSignerInfo']['orgName'] ?? null) === '新北中通'
&& ($signers[0]['orgSignerInfo']['transactorInfo']['psnAccount'] ?? null) === '13800138000';
});
}
public function test_verified_agreement_callback_is_idempotent_and_queues_archive(): void
{
Queue::fake();