平台订单对账明细导出:支持 include_order_snapshot 并加入口
This commit is contained in:
@@ -426,17 +426,39 @@ class PlatformOrderController extends Controller
|
||||
$paymentReceipts = (array) (data_get($order->meta, 'payment_receipts', []) ?? []);
|
||||
$refundReceipts = (array) (data_get($order->meta, 'refund_receipts', []) ?? []);
|
||||
|
||||
$includeOrderSnapshot = (string) $request->query('include_order_snapshot', '') === '1';
|
||||
|
||||
$filename = 'platform_order_' . $order->id . '_ledger_' . now()->format('Ymd_His') . '.csv';
|
||||
|
||||
return response()->streamDownload(function () use ($order, $paymentReceipts, $refundReceipts) {
|
||||
return response()->streamDownload(function () use ($order, $paymentReceipts, $refundReceipts, $includeOrderSnapshot) {
|
||||
$out = fopen('php://output', 'w');
|
||||
|
||||
// UTF-8 BOM,避免 Excel 打开中文乱码
|
||||
fwrite($out, "\xEF\xBB\xBF");
|
||||
|
||||
// 订单摘要(两行)
|
||||
// 订单摘要(基础两行)
|
||||
fputcsv($out, ['order_id', (string) $order->id]);
|
||||
fputcsv($out, ['order_no', (string) $order->order_no]);
|
||||
|
||||
// 可选:导出更多订单快照字段(便于财务/对账留档,不必另截图)
|
||||
if ($includeOrderSnapshot) {
|
||||
fputcsv($out, ['merchant_id', (string) ($order->merchant_id ?? '')]);
|
||||
fputcsv($out, ['merchant_name', (string) ($order->merchant?->name ?? '')]);
|
||||
fputcsv($out, ['plan_id', (string) ($order->plan_id ?? '')]);
|
||||
fputcsv($out, ['plan_name', (string) ($order->plan_name ?? ($order->plan?->name ?? ''))]);
|
||||
fputcsv($out, ['order_type', (string) ($order->order_type ?? '')]);
|
||||
fputcsv($out, ['status', (string) ($order->status ?? '')]);
|
||||
fputcsv($out, ['payment_status', (string) ($order->payment_status ?? '')]);
|
||||
fputcsv($out, ['payable_amount', (string) ($order->payable_amount ?? '')]);
|
||||
fputcsv($out, ['paid_amount', (string) ($order->paid_amount ?? '')]);
|
||||
fputcsv($out, ['placed_at', (string) (optional($order->placed_at)->format('Y-m-d H:i:s') ?? '')]);
|
||||
fputcsv($out, ['paid_at', (string) (optional($order->paid_at)->format('Y-m-d H:i:s') ?? '')]);
|
||||
fputcsv($out, ['activated_at', (string) (optional($order->activated_at)->format('Y-m-d H:i:s') ?? '')]);
|
||||
fputcsv($out, ['refunded_at', (string) (optional($order->refunded_at)->format('Y-m-d H:i:s') ?? '')]);
|
||||
fputcsv($out, ['site_subscription_id', (string) ($order->site_subscription_id ?? '')]);
|
||||
fputcsv($out, ['subscription_no', (string) ($order->siteSubscription?->subscription_no ?? '')]);
|
||||
}
|
||||
|
||||
fputcsv($out, []);
|
||||
|
||||
// 明细表头
|
||||
|
||||
Reference in New Issue
Block a user