From b3676729eed0e23ff6049d5d939ed72552251d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 11 Mar 2026 00:07:50 +0000 Subject: [PATCH] =?UTF-8?q?feat(platform-orders):=20=E6=91=98=E8=A6=81?= =?UTF-8?q?=E5=8D=A1=E5=A2=9E=E5=8A=A0=E6=9C=89=E9=80=80=E6=AC=BE/?= =?UTF-8?q?=E6=97=A0=E9=80=80=E6=AC=BE=E8=AE=A2=E5=8D=95=E6=95=B0=EF=BC=88?= =?UTF-8?q?=E5=90=AB=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 | 10 ++ .../admin/platform_orders/index.blade.php | 5 + ...dminPlatformOrderRefundSummaryCardTest.php | 93 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderRefundSummaryCardTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index e05dfb5..f04cc9f 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -294,6 +294,16 @@ class PlatformOrderController extends Controller ->whereRaw("JSON_EXTRACT(meta, '$.payment_summary.total_amount') IS NULL") ->whereRaw("JSON_EXTRACT(meta, '$.payment_receipts[0].amount') IS NULL") ->count(), + 'refund_orders' => (clone $baseQuery) + ->where(function (Builder $q) { + $q->whereRaw("JSON_EXTRACT(meta, '$.refund_summary.total_amount') IS NOT NULL") + ->orWhereRaw("JSON_EXTRACT(meta, '$.refund_receipts[0].amount') IS NOT NULL"); + }) + ->count(), + 'no_refund_orders' => (clone $baseQuery) + ->whereRaw("JSON_EXTRACT(meta, '$.refund_summary.total_amount') IS NULL") + ->whereRaw("JSON_EXTRACT(meta, '$.refund_receipts[0].amount') IS NULL") + ->count(), 'total_receipt_amount' => $totalReceiptAmount, // 对账差额:回执总额 - 订单已付总额(当前筛选范围) 'reconciliation_delta' => (float) ($totalReceiptAmount - $totalPaidAmount), diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index 7996f28..33f4065 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -154,6 +154,11 @@
¥{{ number_format((float) ($summaryStats['total_refunded_amount'] ?? 0), 2) }}
基于 meta.refund_summary.total_amount(缺省回退汇总)
+
+

有退款订单 / 无退款订单

+
{{ $summaryStats['refund_orders'] ?? 0 }} / {{ $summaryStats['no_refund_orders'] ?? 0 }}
+
口径:refund_summary.total_amount 存在或 refund_receipts 有记录
+

有回执订单 / 回执总额

{{ $summaryStats['receipt_orders'] ?? 0 }} / ¥{{ number_format((float) ($summaryStats['total_receipt_amount'] ?? 0), 2) }}
diff --git a/tests/Feature/AdminPlatformOrderRefundSummaryCardTest.php b/tests/Feature/AdminPlatformOrderRefundSummaryCardTest.php new file mode 100644 index 0000000..d0a6371 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderRefundSummaryCardTest.php @@ -0,0 +1,93 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_platform_orders_page_shows_refund_orders_summary_card(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'refund_summary_card_test', + 'name' => '退款摘要卡测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 10, + 'list_price' => 10, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + // 有退款:summary + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_CARD_HAS', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => '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_summary' => [ + 'count' => 1, + 'total_amount' => 10.00, + ], + ], + ]); + + // 无退款 + PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_REFUND_CARD_NONE', + 'order_type' => 'new_purchase', + 'status' => 'activated', + 'payment_status' => 'paid', + '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' => [], + ]); + + $this->get('/admin/platform-orders') + ->assertOk() + ->assertSee('有退款订单 / 无退款订单') + ->assertSee('1') + ->assertSee('/') + ->assertSee('1'); + } +}