feat(platform-orders): 列表摘要增加退款总览并引入 refund_summary 扁平统计
This commit is contained in:
@@ -244,6 +244,22 @@ class PlatformOrderController extends Controller
|
||||
|
||||
return $q->count();
|
||||
})(),
|
||||
'partially_refunded_orders' => (clone $baseQuery)->where('payment_status', 'partially_refunded')->count(),
|
||||
'refunded_orders' => (clone $baseQuery)->where('payment_status', 'refunded')->count(),
|
||||
'total_refunded_amount' => (clone $baseQuery)->get()->sum(function ($o) {
|
||||
// 优先读 meta.refund_summary.total_amount,回退汇总 meta.refund_receipts[].amount
|
||||
$total = (float) (data_get($o->meta, 'refund_summary.total_amount') ?? 0);
|
||||
if ($total > 0) {
|
||||
return $total;
|
||||
}
|
||||
|
||||
$refunds = (array) (data_get($o->meta, 'refund_receipts', []) ?? []);
|
||||
$sum = 0.0;
|
||||
foreach ($refunds as $r) {
|
||||
$sum += (float) (data_get($r, 'amount') ?? 0);
|
||||
}
|
||||
return $sum;
|
||||
}),
|
||||
],
|
||||
'failedReasonStats' => $failedReasonStats,
|
||||
]);
|
||||
@@ -409,13 +425,22 @@ class PlatformOrderController extends Controller
|
||||
|
||||
data_set($meta, 'refund_receipts', $refunds);
|
||||
|
||||
// 扁平统计:避免在列表/汇总处频繁遍历退款数组(可治理)
|
||||
$totalRefunded = 0.0;
|
||||
foreach ($refunds as $r) {
|
||||
$totalRefunded += (float) (data_get($r, 'amount') ?? 0);
|
||||
}
|
||||
$latestRefund = count($refunds) > 0 ? end($refunds) : null;
|
||||
data_set($meta, 'refund_summary', [
|
||||
'count' => count($refunds),
|
||||
'total_amount' => $totalRefunded,
|
||||
'last_at' => (string) (data_get($latestRefund, 'refunded_at') ?? ''),
|
||||
'last_amount' => (float) (data_get($latestRefund, 'amount') ?? 0),
|
||||
'last_channel' => (string) (data_get($latestRefund, 'channel') ?? ''),
|
||||
]);
|
||||
|
||||
// 可治理辅助:自动推进退款标记(仅当订单本身已支付,且退款金额>0 时)
|
||||
if ($order->payment_status === 'paid' && (float) $data['amount'] > 0) {
|
||||
$totalRefunded = 0.0;
|
||||
foreach ($refunds as $r) {
|
||||
$totalRefunded += (float) (data_get($r, 'amount') ?? 0);
|
||||
}
|
||||
|
||||
$paidAmount = (float) ($order->paid_amount ?? 0);
|
||||
|
||||
// 退款总额 >= 已付金额 => 视为已退款;否则视为部分退款
|
||||
|
||||
Reference in New Issue
Block a user