refactor(platform-orders): centralize export ledger url builder

This commit is contained in:
萝卜
2026-03-17 11:00:06 +08:00
parent 9f9d522ee1
commit b00ccd6fbd
3 changed files with 13 additions and 15 deletions

View File

@@ -50,6 +50,15 @@ class PlatformOrder extends Model
|| (data_get($this->meta, 'refund_receipts.0.amount') !== null);
}
public function exportLedgerUrl(array $query = []): string
{
// 安全阀download=1 必须显式存在(用于防止预取/误触发)。
// 且为了测试/口径稳定download 固定在 query 的第一位。
$query = ['download' => 1] + $query;
return '/admin/platform-orders/' . $this->id . '/export-ledger?' . \Illuminate\Support\Arr::query($query);
}
public function refundTotal(): float
{
// 优先读扁平字段 refund_summary.total_amount

View File

@@ -1584,11 +1584,8 @@
// 仅当存在支付/退款回执证据时展示(避免列表噪音)。
$hasLedgerEvidenceRow = (bool) ($order->hasLedgerEvidence());
$exportLedgerUrlRow = '/admin/platform-orders/' . $order->id . '/export-ledger?' . \Illuminate\Support\Arr::query([
'download' => 1,
// 列表页导出默认带“订单摘要”,便于离线流转(财务/运营对账)
'include_order_snapshot' => 1,
]);
// 列表页导出默认带“订单摘要”,便于离线流转(财务/运营对账)
$exportLedgerUrlRow = $order->exportLedgerUrl(['include_order_snapshot' => 1]);
@endphp
@if($hasLedgerEvidenceRow)
<div class="mt-6">

View File

@@ -545,17 +545,9 @@
<div class="card mb-20" id="payment-receipts">
<div class="flex-between items-center">
<h3 class="mb-0">支付回执(对账留痕)</h3>
@php
$makeExportLedgerUrl = function (array $query = []) use ($order) {
// download 必须显式为 1导出安全阀且为了测试/口径稳定,固定放在 query 的第一位
$query = ['download' => 1] + $query;
return '/admin/platform-orders/' . $order->id . '/export-ledger?' . \Illuminate\Support\Arr::query($query);
};
@endphp
<div class="actions gap-10">
<a class="btn btn-secondary btn-sm" href="{!! $makeExportLedgerUrl() !!}" target="_blank" rel="noopener">导出对账明细CSV</a>
<a class="btn btn-secondary btn-sm" href="{!! $makeExportLedgerUrl(['include_order_snapshot' => 1]) !!}" target="_blank" rel="noopener">导出含订单摘要CSV</a>
<a class="btn btn-secondary btn-sm" href="{!! $order->exportLedgerUrl() !!}" target="_blank" rel="noopener">导出对账明细CSV</a>
<a class="btn btn-secondary btn-sm" href="{!! $order->exportLedgerUrl(['include_order_snapshot' => 1]) !!}" target="_blank" rel="noopener">导出含订单摘要CSV</a>
</div>
</div>
<p class="muted muted-tight">用于“线下收款/转账/人工核对”的留痕记录(当前阶段先落 meta不引入独立表</p>