Expiry governance: nudge renewal requires subscription context

This commit is contained in:
萝卜
2026-03-15 02:23:19 +00:00
parent e66ac765e0
commit 41463407aa
4 changed files with 82 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ class PlatformOrderController extends Controller
// 支持从其它页面(例如订阅详情)带默认值跳转过来,提高运营效率 // 支持从其它页面(例如订阅详情)带默认值跳转过来,提高运营效率
$orderTypeFromQuery = $request->query('order_type'); $orderTypeFromQuery = $request->query('order_type');
$requireSubscription = (string) $request->query('require_subscription', '') === '1';
$defaults = [ $defaults = [
'merchant_id' => (int) $request->query('merchant_id', 0), 'merchant_id' => (int) $request->query('merchant_id', 0),
@@ -59,6 +60,11 @@ class PlatformOrderController extends Controller
$siteSubscription = SiteSubscription::query()->with(['merchant', 'plan'])->find($siteSubscriptionId); $siteSubscription = SiteSubscription::query()->with(['merchant', 'plan'])->find($siteSubscriptionId);
} }
// 治理口径当来源页要求“续费必须绑定订阅”时若未带订阅ID则强制回退为新购避免误导。
if ($requireSubscription && $siteSubscriptionId <= 0) {
$defaults['order_type'] = 'new_purchase';
}
// 续费下单场景:若带了 site_subscription_id但未显式指定 merchant/plan则从订阅上补齐默认值。 // 续费下单场景:若带了 site_subscription_id但未显式指定 merchant/plan则从订阅上补齐默认值。
// 目的:让“从订阅维度跳转到下单页”的链路更稳,不必每次手工二次选择。 // 目的:让“从订阅维度跳转到下单页”的链路更稳,不必每次手工二次选择。
if ($siteSubscription) { if ($siteSubscription) {

View File

@@ -106,6 +106,8 @@
if ($isExpiryView) { if ($isExpiryView) {
$q = [ $q = [
'order_type' => 'renewal', 'order_type' => 'renewal',
// 续费单必须绑定订阅:集合入口也应尽可能引导到订阅维度续费(批量另行建设)。
'require_subscription' => '1',
]; ];
if ((int) ($filters['merchant_id'] ?? 0) > 0) { if ((int) ($filters['merchant_id'] ?? 0) > 0) {
$q['merchant_id'] = (int) $filters['merchant_id']; $q['merchant_id'] = (int) $filters['merchant_id'];
@@ -118,6 +120,7 @@
@endphp @endphp
@if($isExpiryView) @if($isExpiryView)
<a class="btn btn-sm" href="{!! $renewalCtaUrl !!}">创建续费订单(当前集合)</a> <a class="btn btn-sm" href="{!! $renewalCtaUrl !!}">创建续费订单(当前集合)</a>
<span class="muted muted-xs">(建议:进入后按订阅维度续费)</span>
@endif @endif
</div> </div>

View File

@@ -0,0 +1,35 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderCreateRequireSubscriptionFlagShouldDisableRenewalTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->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);
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminSiteSubscriptionIndexExpiryGovernanceRenewalCtaRequireSubscriptionFlagTest extends TestCase
{
use RefreshDatabase;
protected function loginAsPlatformAdmin(): void
{
$this->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);
}
}