Preserve platform order list context via back param links

This commit is contained in:
萝卜
2026-03-13 17:23:36 +00:00
parent d080c74f09
commit 8a06237005
4 changed files with 175 additions and 1 deletions

View File

@@ -738,7 +738,7 @@
@forelse($orders as $order)
<tr>
<td>{{ $order->id }}</td>
<td><a href="/admin/platform-orders/{{ $order->id }}">{{ $order->order_no }}</a></td>
<td><a href="/admin/platform-orders/{{ $order->id }}?back={{ urlencode(request()->getRequestUri()) }}">{{ $order->order_no }}</a></td>
<td>
@if($order->merchant)
<a href="{!! request()->fullUrlWithQuery(['merchant_id' => $order->merchant->id, 'page' => null]) !!}" class="link">{{ $order->merchant->name }}</a>

View File

@@ -544,6 +544,16 @@
</div>
<div class="mb-20" style="margin-top:16px;">
@php
$back = (string) request()->query('back', '');
$safeBack = str_starts_with($back, '/') ? $back : '';
@endphp
@if($safeBack)
<a href="{{ $safeBack }}" class="muted"> 返回上一页(保留上下文)</a>
<span class="muted"></span>
@endif
<a href="/admin/platform-orders"> 返回平台订单列表</a>
</div>
@endsection

View File

@@ -0,0 +1,62 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderIndexOrderNoLinkWithBackTest 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_order_no_link_in_index_contains_back_param(): void
{
$this->loginAsPlatformAdmin();
$merchant = \App\Models\Merchant::query()->firstOrFail();
$plan = \App\Models\Plan::query()->create([
'code' => 'po_index_back_plan_01',
'name' => '平台订单列表 back 参数测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = \App\Models\PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_INDEX_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' => [],
]);
// index 页应存在该订单行链接,且链接带 back保留筛选上下文
$res = $this->get('/admin/platform-orders?status=pending');
$res->assertOk();
$expectedBack = urlencode('/admin/platform-orders?status=pending');
$res->assertSee('/admin/platform-orders/' . $order->id . '?back=' . $expectedBack, false);
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace Tests\Feature;
use App\Models\Merchant;
use App\Models\Plan;
use App\Models\PlatformOrder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class AdminPlatformOrderShowBackLinkTest 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_show_page_renders_safe_back_link_when_back_query_present(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_back_link_plan',
'name' => '平台订单详情返回链接测试套餐',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_SHOW_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' => [],
]);
$back = '/admin/platform-orders?status=pending';
$this->get('/admin/platform-orders/' . $order->id . '?back=' . urlencode($back))
->assertOk()
->assertSee('返回上一页(保留上下文)')
->assertSee($back, false);
}
public function test_show_page_does_not_render_back_link_when_back_is_not_relative_path(): void
{
$this->loginAsPlatformAdmin();
$merchant = Merchant::query()->firstOrFail();
$plan = Plan::query()->create([
'code' => 'po_show_back_link_plan2',
'name' => '平台订单详情返回链接测试套餐2',
'billing_cycle' => 'monthly',
'price' => 10,
'list_price' => 10,
'status' => 'active',
'sort' => 10,
'published_at' => now(),
]);
$order = PlatformOrder::query()->create([
'merchant_id' => $merchant->id,
'plan_id' => $plan->id,
'order_no' => 'PO_SHOW_BACK_0002',
'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' => [],
]);
$this->get('/admin/platform-orders/' . $order->id . '?back=https://evil.example.com')
->assertOk()
->assertDontSee('返回上一页(保留上下文)');
}
}