From 80b218bbfb95f2e4c4c89cbbe733186a8c0bba23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 11 Mar 2026 00:27:58 +0000 Subject: [PATCH] =?UTF-8?q?feat(platform-orders):=20=E5=88=97=E8=A1=A8/?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E9=80=80=E6=AC=BE=E7=BB=9F=E8=AE=A1=E4=BC=98?= =?UTF-8?q?=E5=85=88=E8=AF=BB=20refund=5Fsummary=EF=BC=88=E5=90=AB?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformOrderController.php | 12 +++- .../admin/platform_orders/index.blade.php | 14 ++-- ...atformOrderRefundSummaryRowColumnsTest.php | 72 +++++++++++++++++++ 3 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 tests/Feature/AdminPlatformOrderRefundSummaryRowColumnsTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index f04cc9f..1be1376 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -682,8 +682,9 @@ class PlatformOrderController extends Controller $latestReceipt = $receiptCount > 0 ? end($receipts) : null; $refunds = (array) (data_get($order->meta, 'refund_receipts', []) ?? []); - $refundCount = count($refunds); - $latestRefund = $refundCount > 0 ? end($refunds) : null; + $refundSummaryCount = data_get($order->meta, 'refund_summary.count'); + $refundCount = $refundSummaryCount !== null ? (int) $refundSummaryCount : count($refunds); + $latestRefund = count($refunds) > 0 ? end($refunds) : null; $row = [ $order->id, @@ -715,7 +716,12 @@ class PlatformOrderController extends Controller (string) (data_get($latestRefund, 'refunded_at') ?? ''), (float) (data_get($latestRefund, 'amount') ?? 0), (string) (data_get($latestRefund, 'channel') ?? ''), - (function () use ($refunds) { + (function () use ($order, $refunds) { + $summaryTotal = data_get($order->meta, 'refund_summary.total_amount'); + if ($summaryTotal !== null) { + return (float) $summaryTotal; + } + $total = 0.0; foreach ($refunds as $r) { $total += (float) (data_get($r, 'amount') ?? 0); diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index 92f926c..3bee9f3 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -585,7 +585,8 @@ @php $refunds = (array) (data_get($order->meta, 'refund_receipts', []) ?? []); - $refundCount = count($refunds); + $refundSummaryCount = data_get($order->meta, 'refund_summary.count'); + $refundCount = $refundSummaryCount !== null ? (int) $refundSummaryCount : count($refunds); @endphp @if($refundCount > 0) {{ $refundCount }} @@ -595,9 +596,14 @@ @php - $refundTotal = 0.0; - foreach ($refunds as $r) { - $refundTotal += (float) (data_get($r, 'amount') ?? 0); + $refundSummaryTotal = data_get($order->meta, 'refund_summary.total_amount'); + if ($refundSummaryTotal !== null) { + $refundTotal = (float) $refundSummaryTotal; + } else { + $refundTotal = 0.0; + foreach ($refunds as $r) { + $refundTotal += (float) (data_get($r, 'amount') ?? 0); + } } @endphp @if($refundTotal > 0) diff --git a/tests/Feature/AdminPlatformOrderRefundSummaryRowColumnsTest.php b/tests/Feature/AdminPlatformOrderRefundSummaryRowColumnsTest.php new file mode 100644 index 0000000..ec8c2e9 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderRefundSummaryRowColumnsTest.php @@ -0,0 +1,72 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_platform_orders_row_refund_count_and_total_prefer_refund_summary(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'refund_row_summary_test', + 'name' => '退款行级摘要测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_ROW_SUMMARY_0001', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'partially_refunded', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'paid_at' => now(), + 'activated_at' => now(), + 'meta' => [ + // 故意不给 refund_receipts,验证列表能从 refund_summary 读到 + 'refund_summary' => [ + 'count' => 2, + 'total_amount' => 3.50, + ], + ], + ]); + + $this->get('/admin/platform-orders') + ->assertOk() + ->assertSee('PO_REFUND_ROW_SUMMARY_0001') + ->assertSee('2') + ->assertSee('¥3.50'); + } +}