diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index bef1d96..170a259 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -31,6 +31,7 @@ class PlatformOrderController extends Controller // 支持从其它页面(例如订阅详情)带默认值跳转过来,提高运营效率 $orderTypeFromQuery = $request->query('order_type'); + $requireSubscription = (string) $request->query('require_subscription', '') === '1'; $defaults = [ 'merchant_id' => (int) $request->query('merchant_id', 0), @@ -59,6 +60,11 @@ class PlatformOrderController extends Controller $siteSubscription = SiteSubscription::query()->with(['merchant', 'plan'])->find($siteSubscriptionId); } + // 治理口径:当来源页要求“续费必须绑定订阅”时,若未带订阅ID,则强制回退为新购,避免误导。 + if ($requireSubscription && $siteSubscriptionId <= 0) { + $defaults['order_type'] = 'new_purchase'; + } + // 续费下单场景:若带了 site_subscription_id,但未显式指定 merchant/plan,则从订阅上补齐默认值。 // 目的:让“从订阅维度跳转到下单页”的链路更稳,不必每次手工二次选择。 if ($siteSubscription) { diff --git a/resources/views/admin/site_subscriptions/index.blade.php b/resources/views/admin/site_subscriptions/index.blade.php index 283b632..f5bf8f6 100644 --- a/resources/views/admin/site_subscriptions/index.blade.php +++ b/resources/views/admin/site_subscriptions/index.blade.php @@ -106,6 +106,8 @@ if ($isExpiryView) { $q = [ 'order_type' => 'renewal', + // 续费单必须绑定订阅:集合入口也应尽可能引导到订阅维度续费(批量另行建设)。 + 'require_subscription' => '1', ]; if ((int) ($filters['merchant_id'] ?? 0) > 0) { $q['merchant_id'] = (int) $filters['merchant_id']; @@ -118,6 +120,7 @@ @endphp @if($isExpiryView) 创建续费订单(当前集合) + (建议:进入后按订阅维度续费) @endif diff --git a/tests/Feature/AdminPlatformOrderCreateRequireSubscriptionFlagShouldDisableRenewalTest.php b/tests/Feature/AdminPlatformOrderCreateRequireSubscriptionFlagShouldDisableRenewalTest.php new file mode 100644 index 0000000..8feb42b --- /dev/null +++ b/tests/Feature/AdminPlatformOrderCreateRequireSubscriptionFlagShouldDisableRenewalTest.php @@ -0,0 +1,35 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_create_should_not_allow_renewal_default_when_require_subscription_flag_and_subscription_missing(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->get('/admin/platform-orders/create?require_subscription=1&order_type=renewal'); + $res->assertOk(); + + // 续费选项应禁用 + $res->assertSee('value="renewal" disabled', false); + + // 不应出现 renewal 被选中(避免误导) + $res->assertDontSee('value="renewal" selected', false); + } +} diff --git a/tests/Feature/AdminSiteSubscriptionIndexExpiryGovernanceRenewalCtaRequireSubscriptionFlagTest.php b/tests/Feature/AdminSiteSubscriptionIndexExpiryGovernanceRenewalCtaRequireSubscriptionFlagTest.php new file mode 100644 index 0000000..6b1a1b6 --- /dev/null +++ b/tests/Feature/AdminSiteSubscriptionIndexExpiryGovernanceRenewalCtaRequireSubscriptionFlagTest.php @@ -0,0 +1,38 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_expiry_view_renewal_cta_should_carry_require_subscription_flag(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->get('/admin/site-subscriptions?' . Arr::query([ + 'expiry' => 'expiring_7d', + 'merchant_id' => 2, + 'plan_id' => 3, + ])); + + $res->assertOk(); + + $res->assertSee('创建续费订单(当前集合)', false); + $res->assertSee('require_subscription=1', false); + } +}