From 9bd19474e1d3e245b916bfb56717366d0863e5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sun, 15 Mar 2026 07:46:45 +0000 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E7=BB=AD=E8=B4=B9=E7=BC=BA?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E6=97=B6=20BMPA=20=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E8=A1=A5=E9=BD=90=E5=8E=BB=E8=AE=A2=E9=98=85=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=9F=A5=E6=89=BE=E8=AE=A2=E9=98=85=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/platform_orders/show.blade.php | 14 ++++ ...LinkWhenRenewalMissingSubscriptionTest.php | 76 +++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 tests/Feature/AdminPlatformOrderShowBmpaGovernanceBlockShouldIncludeFindSubscriptionLinkWhenRenewalMissingSubscriptionTest.php diff --git a/resources/views/admin/platform_orders/show.blade.php b/resources/views/admin/platform_orders/show.blade.php index b741f3a..a4ae746 100644 --- a/resources/views/admin/platform_orders/show.blade.php +++ b/resources/views/admin/platform_orders/show.blade.php @@ -209,6 +209,16 @@ $markPaidBlockedByMissingSubscriptionOnRenewal = ((string) ($order->order_type ?? '') === 'renewal') && ((int) ($order->site_subscription_id ?? 0) <= 0); + // 治理引导:续费缺订阅时提供“去订阅管理查找订阅”入口(回到当前订单详情自身) + $missingSubscriptionHelpUrl = ''; + if ($markPaidBlockedByMissingSubscriptionOnRenewal) { + $missingSubscriptionHelpUrl = \App\Support\BackUrl::withBack('/admin/site-subscriptions?' . \Illuminate\Support\Arr::query([ + 'merchant_id' => (int) ($order->merchant_id ?? 0) ?: null, + 'plan_id' => (int) ($order->plan_id ?? 0) ?: null, + 'page' => null, + ]), $orderShowSelf); + } + $tol = (float) config('saasshop.amounts.tolerance', 0.01); $tolCents = (int) round($tol * 100); $tolCents = max(1, $tolCents); @@ -238,6 +248,10 @@ 原因:当前订单类型为「续费」,但未绑定订阅(site_subscription_id 为空)。 请先补齐订阅关联后再处理。 + @if($missingSubscriptionHelpUrl !== '') + + 去订阅管理查找订阅 + @endif @endif @if($markPaidBlockedByReceiptMismatch) diff --git a/tests/Feature/AdminPlatformOrderShowBmpaGovernanceBlockShouldIncludeFindSubscriptionLinkWhenRenewalMissingSubscriptionTest.php b/tests/Feature/AdminPlatformOrderShowBmpaGovernanceBlockShouldIncludeFindSubscriptionLinkWhenRenewalMissingSubscriptionTest.php new file mode 100644 index 0000000..3abac2b --- /dev/null +++ b/tests/Feature/AdminPlatformOrderShowBmpaGovernanceBlockShouldIncludeFindSubscriptionLinkWhenRenewalMissingSubscriptionTest.php @@ -0,0 +1,76 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_show_bmpa_governance_block_should_include_find_subscription_link_when_renewal_missing_subscription(): void + { + $this->loginAsPlatformAdmin(); + + $merchant = Merchant::query()->firstOrFail(); + $plan = Plan::query()->create([ + 'code' => 'po_show_bmpa_find_sub_renewal_no_sub_plan', + 'name' => '订单详情 BMPA 治理引导(续费无订阅)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 30, + 'list_price' => 30, + 'status' => 'active', + 'sort' => 10, + 'published_at' => now(), + ]); + + $order = PlatformOrder::query()->create([ + 'merchant_id' => $merchant->id, + 'plan_id' => $plan->id, + 'order_no' => 'PO_SHOW_BMPA_FIND_SUB_RENEW_NO_SUB_0001', + 'order_type' => 'renewal', + 'status' => 'pending', + 'payment_status' => 'unpaid', + 'plan_name' => $plan->name, + 'billing_cycle' => $plan->billing_cycle, + 'period_months' => 1, + 'quantity' => 1, + 'payable_amount' => 30, + 'paid_amount' => 0, + 'placed_at' => now(), + 'meta' => [], + ]); + + $res = $this->get('/admin/platform-orders/' . $order->id); + $res->assertOk(); + + $res->assertSee('BMPA 治理提示', false); + $res->assertSee('去订阅管理查找订阅', false); + + // 链接应包含 merchant_id/plan_id,并携带 back 回到当前订单详情 + $matched = preg_match('/]+href="([^"]+)"[^>]*>\s*去订阅管理查找订阅\s*<\/a>/u', (string) $res->getContent(), $m); + $this->assertSame(1, $matched, '未找到 BMPA 治理提示中的「去订阅管理查找订阅」链接'); + + $url = $m[1] ?? ''; + $parts = parse_url($url); + parse_str($parts['query'] ?? '', $q); + + $this->assertSame((string) $merchant->id, (string) ($q['merchant_id'] ?? '')); + $this->assertSame((string) $plan->id, (string) ($q['plan_id'] ?? '')); + $this->assertSame('/admin/platform-orders/' . $order->id, (string) ($q['back'] ?? '')); + } +}