PlatformOrder create: add jump to subscriptions link when require_subscription

This commit is contained in:
萝卜
2026-03-15 02:41:29 +00:00
parent 3182dd72a0
commit df416da7f8
2 changed files with 65 additions and 0 deletions

View File

@@ -135,6 +135,29 @@
</select>
@if(! $canRenew)
<small class="muted">提示:续费单必须绑定订阅。请从「订阅管理」列表/详情进入“续费下单”系统会自动带入订阅ID。</small>
@php
$jumpQuery = [];
if ((int) ($defaults['merchant_id'] ?? 0) > 0) {
$jumpQuery['merchant_id'] = (int) ($defaults['merchant_id'] ?? 0);
}
if ((int) ($defaults['plan_id'] ?? 0) > 0) {
$jumpQuery['plan_id'] = (int) ($defaults['plan_id'] ?? 0);
}
$jumpBase = '/admin/site-subscriptions';
if (count($jumpQuery) > 0) {
$jumpBase .= '?' . \Illuminate\Support\Arr::query($jumpQuery);
}
$jumpUrl = \App\Support\BackUrl::withBack($jumpBase, \App\Support\BackUrl::selfWithoutBack());
@endphp
@if(($requireSubscription ?? false) && $jumpUrl)
<div class="mt-6 actions">
<a class="btn btn-secondary btn-sm" href="{!! $jumpUrl !!}">去订阅管理选择订阅</a>
</div>
@endif
@endif
</label>

View File

@@ -0,0 +1,42 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformOrderCreateRequireSubscriptionFlagShouldRenderJumpToSubscriptionsLinkTest 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_render_jump_to_subscriptions_link_when_require_subscription_flag_and_no_subscription_context(): void
{
$this->loginAsPlatformAdmin();
$url = '/admin/platform-orders/create?' . Arr::query([
'require_subscription' => 1,
'merchant_id' => 2,
'plan_id' => 3,
]);
$res = $this->get($url);
$res->assertOk();
$res->assertSee('去订阅管理选择订阅', false);
$res->assertSee('/admin/site-subscriptions?merchant_id=2&plan_id=3', false);
// 链接应携带 back
$res->assertSee('back=', false);
}
}