平台订单详情:关联订阅链接补齐 back 且避免 back 嵌套

This commit is contained in:
萝卜
2026-03-13 19:39:03 +00:00
parent 2feb8055f2
commit d6867d34c0
4 changed files with 287 additions and 5 deletions

View File

@@ -238,10 +238,11 @@
<th>订阅管理</th> <th>订阅管理</th>
<td> <td>
@php @php
$subBack = '/admin/platform-orders/' . $order->id; // 用 orderShowSelf 作为 back已剔除 back query避免嵌套膨胀
$subBack = $orderShowSelf;
$openSubUrl = '/admin/site-subscriptions/' . $order->siteSubscription->id . '?' . \Illuminate\Support\Arr::query(['back' => $subBack]); $openSubUrl = '/admin/site-subscriptions/' . $order->siteSubscription->id . '?' . \Illuminate\Support\Arr::query(['back' => $subBack]);
@endphp @endphp
<a class="link" href="{{ $openSubUrl }}">打开订阅详情</a> <a class="link" href="{!! $openSubUrl !!}">打开订阅详情</a>
<span class="muted"></span> <span class="muted"></span>
@php @php
$openSubSyncableUrl = '/admin/site-subscriptions/' . $order->siteSubscription->id . '?' . \Illuminate\Support\Arr::query([ $openSubSyncableUrl = '/admin/site-subscriptions/' . $order->siteSubscription->id . '?' . \Illuminate\Support\Arr::query([
@@ -249,11 +250,23 @@
'order_sync_status' => 'syncable', 'order_sync_status' => 'syncable',
]) . '#syncable-batch'; ]) . '#syncable-batch';
@endphp @endphp
<a class="muted" href="{{ $openSubSyncableUrl }}">查看可同步订单</a> <a class="muted" href="{!! $openSubSyncableUrl !!}">查看可同步订单</a>
<span class="muted"></span> <span class="muted"></span>
<a class="muted" href="/admin/site-subscriptions?merchant_id={{ $order->siteSubscription->merchant_id }}">同站点订阅</a> @php
$sameMerchantSubsUrl = '/admin/site-subscriptions?' . \Illuminate\Support\Arr::query([
'merchant_id' => $order->siteSubscription->merchant_id,
'back' => $orderShowSelf,
]);
@endphp
<a class="muted" href="{!! $sameMerchantSubsUrl !!}">同站点订阅</a>
<span class="muted"></span> <span class="muted"></span>
<a class="muted" href="/admin/site-subscriptions?plan_id={{ $order->siteSubscription->plan_id }}">同套餐订阅</a> @php
$samePlanSubsUrl = '/admin/site-subscriptions?' . \Illuminate\Support\Arr::query([
'plan_id' => $order->siteSubscription->plan_id,
'back' => $orderShowSelf,
]);
@endphp
<a class="muted" href="{!! $samePlanSubsUrl !!}">同套餐订阅</a>
</td> </td>
</tr> </tr>
<tr><th>状态</th><td>{{ $order->siteSubscription->status }}</td></tr> <tr><th>状态</th><td>{{ $order->siteSubscription->status }}</td></tr>

View File

@@ -0,0 +1,82 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderShowRelatedSubscriptionLinksAreNotEscapedTest 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_related_subscription_links_should_not_render_amp_escaped_query_delimiter(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_related_sub_no_escape_plan',
'name' => '平台订单详情关联订阅链接不转义测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$sub = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'activated',
'source' => 'manual',
'subscription_no' => 'SUB_PO_SHOW_RELATED_NO_ESCAPE_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
'activated_at' => now()->subDay(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'site_subscription_id' => $sub->id,
'order_no' => 'PO_SHOW_RELATED_NO_ESCAPE_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [],
]);
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
// 关键点openSubSyncableUrl 带两个 query 参数,不能被渲染成 &amp;
$res->assertDontSee('order_sync_status=syncable&amp;', false);
$res->assertDontSee('back=%2Fadmin%2Fplatform-orders%2F' . $order->id . '&amp;', false);
}
}

View File

@@ -0,0 +1,105 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Arr;
use Tests\TestCase;
class AdminPlatformOrderShowRelatedSubscriptionLinksContainBackTest 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_related_subscription_links_should_carry_back_to_platform_order_show(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_related_sub_back_plan',
'name' => '平台订单详情关联订阅 back 链接测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$sub = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'activated',
'source' => 'manual',
'subscription_no' => 'SUB_PO_SHOW_RELATED_BACK_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
'activated_at' => now()->subDay(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'site_subscription_id' => $sub->id,
'order_no' => 'PO_SHOW_RELATED_BACK_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [],
]);
$res = $this->get('/admin/platform-orders/' . $order->id);
$res->assertOk();
$back = '/admin/platform-orders/' . $order->id;
$openSubUrl = '/admin/site-subscriptions/' . $sub->id . '?' . Arr::query([
'back' => $back,
]);
$openSubSyncableUrl = '/admin/site-subscriptions/' . $sub->id . '?' . Arr::query([
'back' => $back,
'order_sync_status' => 'syncable',
]) . '#syncable-batch';
$sameMerchantSubsUrl = '/admin/site-subscriptions?' . Arr::query([
'merchant_id' => $merchant->id,
'back' => $back,
]);
$samePlanSubsUrl = '/admin/site-subscriptions?' . Arr::query([
'plan_id' => $plan->id,
'back' => $back,
]);
$res->assertSee($openSubUrl, false);
$res->assertSee($openSubSyncableUrl, false);
$res->assertSee($sameMerchantSubsUrl, false);
$res->assertSee($samePlanSubsUrl, false);
}
}

View File

@@ -0,0 +1,82 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use App\Models\SiteSubscription;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderShowRelatedSubscriptionLinksShouldNotNestBackTest 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_related_subscription_links_back_should_not_contain_nested_back(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_related_sub_no_nested_back_plan',
'name' => '平台订单详情关联订阅 back 不嵌套测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$sub = SiteSubscription::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'status' => 'activated',
'source' => 'manual',
'subscription_no' => 'SUB_PO_SHOW_NO_NEST_0001',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'amount' => 10,
'starts_at' => now()->subDay(),
'ends_at' => now()->addMonth(),
'activated_at' => now()->subDay(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'site_subscription_id' => $sub->id,
'order_no' => 'PO_SHOW_NO_NEST_0001',
'order_type' => 'new_purchase',
'status' => 'pending',
'payment_status' => 'unpaid',
'plan_name' => $plan->name,
'billing_cycle' => $plan->billing_cycle,
'period_months' => 1,
'quantity' => 1,
'payable_amount' => 10,
'paid_amount' => 0,
'placed_at' => now(),
'meta' => [],
]);
// 带 back 访问订单详情页(模拟从列表进入)
$res = $this->get('/admin/platform-orders/' . $order->id . '?back=' . urlencode('/admin/platform-orders?status=pending'));
$res->assertOk();
// 关联订阅的 back 应该回到“订单详情(去掉 back不应出现 back=...back= 的嵌套
$res->assertDontSee('back%3D', false);
}
}