From 5bdcaa561f993d1dc4f1ececccd92066b333dc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Tue, 10 Mar 2026 17:19:49 +0000 Subject: [PATCH] =?UTF-8?q?feat(platform-orders):=20=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=9B=9E=E6=89=A7=E6=89=81=E5=B9=B3=E7=BB=9F=E8=AE=A1=E4=B8=8E?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=91=98=E8=A6=81=E5=9B=9E=E6=89=A7=E6=80=BB?= =?UTF-8?q?=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 45 +++++++++++++++++++ .../admin/platform_orders/index.blade.php | 5 +++ tests/Feature/AdminPlatformOrderTest.php | 1 + 3 files changed, 51 insertions(+) diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index af36161..e485d42 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -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(); diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index 2f7f4f3..ede68a0 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -130,6 +130,11 @@
¥{{ number_format((float) ($summaryStats['total_refunded_amount'] ?? 0), 2) }}
基于 meta.refund_summary.total_amount(缺省回退汇总)
+
+

有回执订单 / 回执总额

+
{{ $summaryStats['receipt_orders'] ?? 0 }} / ¥{{ number_format((float) ($summaryStats['total_receipt_amount'] ?? 0), 2) }}
+
基于 meta.payment_summary.total_amount(缺省回退汇总)
+

同步失败原因 TOP5

@php $failedReasonStats = $failedReasonStats ?? []; @endphp diff --git a/tests/Feature/AdminPlatformOrderTest.php b/tests/Feature/AdminPlatformOrderTest.php index 94bca0f..e25d7c2 100644 --- a/tests/Feature/AdminPlatformOrderTest.php +++ b/tests/Feature/AdminPlatformOrderTest.php @@ -39,6 +39,7 @@ class AdminPlatformOrderTest extends TestCase ->assertSee('近24小时批量同步') ->assertSee('部分退款 / 已退款') ->assertSee('退款总额') + ->assertSee('有回执订单 / 回执总额') ->assertSee('快捷筛选') ->assertSee('待支付') ->assertSee('待生效')