feat(platform-orders): 支付回执扁平统计与列表摘要回执总览

This commit is contained in:
萝卜
2026-03-10 17:19:49 +00:00
parent 565a451ca8
commit 5bdcaa561f
3 changed files with 51 additions and 0 deletions

View File

@@ -260,6 +260,21 @@ class PlatformOrderController extends Controller
}
return $sum;
}),
'receipt_orders' => (clone $baseQuery)->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NOT NULL")->count(),
'total_receipt_amount' => (clone $baseQuery)->get()->sum(function ($o) {
// 优先读 meta.payment_summary.total_amount回退汇总 meta.payment_receipts[].amount
$total = (float) (data_get($o->meta, 'payment_summary.total_amount') ?? 0);
if ($total > 0) {
return $total;
}
$receipts = (array) (data_get($o->meta, 'payment_receipts', []) ?? []);
$sum = 0.0;
foreach ($receipts as $r) {
$sum += (float) (data_get($r, 'amount') ?? 0);
}
return $sum;
}),
],
'failedReasonStats' => $failedReasonStats,
]);
@@ -333,6 +348,21 @@ class PlatformOrderController extends Controller
'admin_id' => $admin->id,
];
data_set($meta, 'payment_receipts', $receipts);
// 扁平统计:避免在列表/汇总处频繁遍历支付回执数组(可治理)
$totalPaid = 0.0;
foreach ($receipts as $r) {
$totalPaid += (float) (data_get($r, 'amount') ?? 0);
}
$latest = count($receipts) > 0 ? end($receipts) : null;
data_set($meta, 'payment_summary', [
'count' => count($receipts),
'total_amount' => $totalPaid,
'last_at' => (string) (data_get($latest, 'paid_at') ?? ''),
'last_amount' => (float) (data_get($latest, 'amount') ?? 0),
'last_channel' => (string) (data_get($latest, 'channel') ?? ''),
]);
$order->meta = $meta;
}
@@ -390,6 +420,21 @@ class PlatformOrderController extends Controller
];
data_set($meta, 'payment_receipts', $receipts);
// 扁平统计:避免在列表/汇总处频繁遍历支付回执数组(可治理)
$totalPaid = 0.0;
foreach ($receipts as $r) {
$totalPaid += (float) (data_get($r, 'amount') ?? 0);
}
$latest = count($receipts) > 0 ? end($receipts) : null;
data_set($meta, 'payment_summary', [
'count' => count($receipts),
'total_amount' => $totalPaid,
'last_at' => (string) (data_get($latest, 'paid_at') ?? ''),
'last_amount' => (float) (data_get($latest, 'amount') ?? 0),
'last_channel' => (string) (data_get($latest, 'channel') ?? ''),
]);
$order->meta = $meta;
$order->save();