From 151a20e63035cf10b775307155b7caa2c2d15c60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Mon, 16 Mar 2026 11:31:25 +0800 Subject: [PATCH] refactor(plans): hide create order action when plan not active --- resources/views/admin/plans/index.blade.php | 21 ++------ ...derLinkShouldHideWhenPlanNotActiveTest.php | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+), 16 deletions(-) create mode 100644 tests/Feature/AdminPlanIndexCreateOrderLinkShouldHideWhenPlanNotActiveTest.php diff --git a/resources/views/admin/plans/index.blade.php b/resources/views/admin/plans/index.blade.php index 1a01404..a0e8dbe 100644 --- a/resources/views/admin/plans/index.blade.php +++ b/resources/views/admin/plans/index.blade.php @@ -151,45 +151,30 @@
{{ $summaryStats['active_plans'] ?? 0 }}
-
- 查看停用套餐 -

月付套餐

-

年付套餐

-

已发布套餐

-

未发布套餐

-

关联订阅总量

@@ -281,7 +266,11 @@ @endphp
编辑 - 创建订单 + @if((string) ($plan->status ?? '') === 'active') + 创建订单 + @else + 未启用:不建议下单 + @endif 续费缺订阅
diff --git a/tests/Feature/AdminPlanIndexCreateOrderLinkShouldHideWhenPlanNotActiveTest.php b/tests/Feature/AdminPlanIndexCreateOrderLinkShouldHideWhenPlanNotActiveTest.php new file mode 100644 index 0000000..bd0162b --- /dev/null +++ b/tests/Feature/AdminPlanIndexCreateOrderLinkShouldHideWhenPlanNotActiveTest.php @@ -0,0 +1,48 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_plan_index_should_not_render_create_order_link_when_plan_not_active(): void + { + $this->loginAsPlatformAdmin(); + + $plan = Plan::query()->create([ + 'code' => 'plan_index_hide_create_order_when_not_active', + 'name' => '套餐页隐藏创建订单(未启用)测试套餐', + 'billing_cycle' => 'monthly', + 'price' => 99, + 'list_price' => 99, + // 非 active + 'status' => 'draft', + 'sort' => 1, + 'published_at' => null, + ]); + + $res = $this->get('/admin/plans'); + $res->assertOk(); + + $html = (string) $res->getContent(); + + // 该套餐行内不应出现“创建订单”入口(避免对未启用套餐误下单) + $this->assertStringNotContainsString('/admin/platform-orders/create?plan_id=' . $plan->id, $html); + $this->assertStringContainsString('未启用:不建议下单', $html); + } +}