From c78ae0155822a7606e4ef690b1e4d3ca08b3884f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Wed, 18 Mar 2026 01:13:07 +0800 Subject: [PATCH] Dashboard scanline: treat partially_refunded as refundable for refund trace --- resources/views/admin/dashboard.blade.php | 9 ++- ...owRefundTraceWhenPartiallyRefundedTest.php | 68 +++++++++++++++++++ 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 tests/Feature/AdminDashboardRecentPlatformOrdersScanlineShouldShowRefundTraceWhenPartiallyRefundedTest.php diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 94db3f8..4673b59 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -858,8 +858,11 @@ // 运营扫描用的“治理状态摘要”(不替代下方的治理提示入口,只用于快速判断) // 注意:为避免对“未支付订单”造成误导,回执/对账/退款在非 paid/refunded 时显示 "-"。 - $isPaid = ((string) $po->payment_status === 'paid'); - $isRefunded = ((string) $po->payment_status === 'refunded'); + $paymentStatus = (string) ($po->payment_status ?? ''); + $isPaid = ($paymentStatus === 'paid'); + $isRefunded = ($paymentStatus === 'refunded'); + // partially_refunded 属于“已支付但发生退款”的治理集合:扫描行应展示退款轨迹(避免显示 "-" 造成误判)。 + $isPartiallyRefunded = ($paymentStatus === 'partially_refunded'); $receiptStatusText = $isPaid ? ($hasReceiptEvidence ? '有' : '无') : '-'; $reconcileStatusText = ($isPaid && $hasReceiptEvidence) @@ -872,7 +875,7 @@ // - 有退款且一致:"有"(直达 #add-refund-receipt,便于核对退款轨迹) // - 无退款:"无" $hasRefundTrace = ((float) $po->refundTotal()) > 0; - $refundStatusText = ($isPaid || $isRefunded) + $refundStatusText = ($isPaid || $isRefunded || $isPartiallyRefunded) ? ($po->isRefundInconsistent() ? '异常' : ($hasRefundTrace ? '有' : '无')) : '-'; diff --git a/tests/Feature/AdminDashboardRecentPlatformOrdersScanlineShouldShowRefundTraceWhenPartiallyRefundedTest.php b/tests/Feature/AdminDashboardRecentPlatformOrdersScanlineShouldShowRefundTraceWhenPartiallyRefundedTest.php new file mode 100644 index 0000000..09eeb55 --- /dev/null +++ b/tests/Feature/AdminDashboardRecentPlatformOrdersScanlineShouldShowRefundTraceWhenPartiallyRefundedTest.php @@ -0,0 +1,68 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_dashboard_recent_platform_orders_scanline_should_show_refund_trace_when_partially_refunded(): void + { + $this->loginAsPlatformAdmin(); + + // 清理 seed 订单,避免最近订单列表被 seed 污染导致断言不稳定。 + PlatformOrder::query()->delete(); + + $merchantId = (int) Merchant::query()->value('id'); + $platformAdminId = (int) Admin::query()->where('email', 'platform.admin@demo.local')->value('id'); + + PlatformOrder::query()->create([ + 'merchant_id' => $merchantId, + 'plan_id' => null, + 'site_subscription_id' => null, + 'created_by_admin_id' => $platformAdminId ?: null, + 'order_no' => 'PO_DASH_SCANLINE_PARTIAL_REFUND_0001', + 'order_type' => 'new_purchase', + 'status' => 'pending', + 'payment_status' => 'partially_refunded', + 'payable_amount' => 10, + 'paid_amount' => 10, + 'placed_at' => now(), + 'paid_at' => now(), + 'meta' => [ + 'refund_summary' => [ + 'total_amount' => 1, + 'count' => 1, + ], + ], + ]); + + $res = $this->get('/admin'); + $res->assertOk(); + + $res->assertSee('PO_DASH_SCANLINE_PARTIAL_REFUND_0001'); + + // partially_refunded 也应展示退款轨迹(不应为 "-") + $res->assertSee('退款:', false); + $res->assertSee('', false); + + // 并保持最短治理入口:直达 add-refund-receipt + $res->assertSee('#add-refund-receipt', false); + } +}