From bd8cf71bf4cd5de9a6115f45eb39b0e9219bd8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Fri, 13 Mar 2026 22:09:04 +0000 Subject: [PATCH] feat: plans index add create order quick link --- resources/views/admin/plans/index.blade.php | 10 ++- .../AdminPlanIndexCreateOrderLinkTest.php | 66 +++++++++++++++++++ 2 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 tests/Feature/AdminPlanIndexCreateOrderLinkTest.php diff --git a/resources/views/admin/plans/index.blade.php b/resources/views/admin/plans/index.blade.php index 79c8b08..5ab8f15 100644 --- a/resources/views/admin/plans/index.blade.php +++ b/resources/views/admin/plans/index.blade.php @@ -176,8 +176,16 @@ @php $editPlanUrl = '/admin/plans/' . $plan->id . '/edit?' . \Illuminate\Support\Arr::query(['back' => $selfWithoutBack]); + $createOrderUrl = '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query([ + 'plan_id' => $plan->id, + 'order_type' => 'new_purchase', + 'back' => $selfWithoutBack, + ]); @endphp - 编辑 +
+ 编辑 + 创建订单 +
@csrf diff --git a/tests/Feature/AdminPlanIndexCreateOrderLinkTest.php b/tests/Feature/AdminPlanIndexCreateOrderLinkTest.php new file mode 100644 index 0000000..0e7ba1d --- /dev/null +++ b/tests/Feature/AdminPlanIndexCreateOrderLinkTest.php @@ -0,0 +1,66 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_plan_index_should_render_create_order_link_with_plan_id_and_back(): void + { + $this->loginAsPlatformAdmin(); + + $plan = Plan::query()->create([ + 'code' => 'plan_create_order_link_test', + 'name' => '套餐创建订单链接测试', + 'billing_cycle' => 'monthly', + 'price' => 99, + 'list_price' => 99, + 'status' => 'active', + 'sort' => 1, + 'published_at' => now(), + ]); + + // 访问列表页时带 back(模拟来自别处),链接 back 应回到 selfWithoutBack(去掉 back) + $currentUrl = '/admin/plans?' . Arr::query([ + 'status' => 'active', + 'billing_cycle' => 'monthly', + 'back' => '/admin', + ]); + + $res = $this->get($currentUrl); + $res->assertOk(); + + $selfWithoutBack = '/admin/plans?' . Arr::query([ + 'status' => 'active', + 'billing_cycle' => 'monthly', + ]); + + $expectedCreateUrl = '/admin/platform-orders/create?' . Arr::query([ + 'plan_id' => $plan->id, + 'order_type' => 'new_purchase', + 'back' => $selfWithoutBack, + ]); + + $res->assertSee($expectedCreateUrl, false); + $res->assertSee('创建订单', false); + + // 防 back 嵌套 + $res->assertDontSee('back%3D', false); + } +}