From 3182dd72a010ab7f82ba6099a93101a99845e620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sun, 15 Mar 2026 02:36:27 +0000 Subject: [PATCH] PlatformOrder create: require_subscription flag narrows order types --- .../Admin/PlatformOrderController.php | 1 + .../admin/platform_orders/form.blade.php | 12 +++++++ ...bscriptionFlagShouldDisableRenewalTest.php | 7 ++-- ...nFlagShouldOnlyShowNewPurchaseTypeTest.php | 34 +++++++++++++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/Feature/AdminPlatformOrderCreateRequireSubscriptionFlagShouldOnlyShowNewPurchaseTypeTest.php diff --git a/app/Http/Controllers/Admin/PlatformOrderController.php b/app/Http/Controllers/Admin/PlatformOrderController.php index 170a259..251e046 100644 --- a/app/Http/Controllers/Admin/PlatformOrderController.php +++ b/app/Http/Controllers/Admin/PlatformOrderController.php @@ -93,6 +93,7 @@ class PlatformOrderController extends Controller 'siteSubscription' => $siteSubscription, 'billingCycleLabels' => $this->billingCycleLabels(), 'orderTypeLabels' => $this->orderTypeLabels(), + 'requireSubscription' => $requireSubscription, 'defaults' => $defaults, ]); } diff --git a/resources/views/admin/platform_orders/form.blade.php b/resources/views/admin/platform_orders/form.blade.php index ec1c7b6..ebdc7bc 100644 --- a/resources/views/admin/platform_orders/form.blade.php +++ b/resources/views/admin/platform_orders/form.blade.php @@ -107,13 +107,25 @@ @php $canRenew = ((int) ($defaults['site_subscription_id'] ?? 0) > 0) && (($siteSubscription ?? null) && ($siteSubscription->id ?? 0)); $selectedOrderType = (string) old('order_type', $defaults['order_type'] ?? 'new_purchase'); + // 治理口径:续费必须绑定订阅。若当前页面未绑定订阅,则不允许选中 renewal(避免提交后才报错)。 if (! $canRenew && $selectedOrderType === 'renewal') { $selectedOrderType = 'new_purchase'; } + + // 更强治理:若来源页声明 require_subscription=1,且当前未绑定订阅,则不展示 upgrade/downgrade 等类型,避免误用。 + $requireSub = (bool) ($requireSubscription ?? false); + $allowedTypes = array_keys($orderTypeLabels ?? []); + if ($requireSub && ! $canRenew) { + $allowedTypes = ['new_purchase']; + } @endphp