diff --git a/resources/views/admin/platform_orders/index.blade.php b/resources/views/admin/platform_orders/index.blade.php index 604e972..7ed37d2 100644 --- a/resources/views/admin/platform_orders/index.blade.php +++ b/resources/views/admin/platform_orders/index.blade.php @@ -873,6 +873,10 @@ if (trim((string) ($filters['site_subscription_id'] ?? '')) !== '') { $createQuery['site_subscription_id'] = (int) ($filters['site_subscription_id'] ?? 0); } + // 线索联动:若当前列表已按 lead_id 锁定,则新建订单也应带上 lead_id,维持闭环追溯 + if (trim((string) ($filters['lead_id'] ?? '')) !== '') { + $createQuery['lead_id'] = (int) ($filters['lead_id'] ?? 0); + } $createOrderUrl = '/admin/platform-orders/create?' . \Illuminate\Support\Arr::query($createQuery); @endphp diff --git a/tests/Feature/AdminPlatformOrderIndexCreateOrderLinkKeepsLeadIdTest.php b/tests/Feature/AdminPlatformOrderIndexCreateOrderLinkKeepsLeadIdTest.php new file mode 100644 index 0000000..6a5c225 --- /dev/null +++ b/tests/Feature/AdminPlatformOrderIndexCreateOrderLinkKeepsLeadIdTest.php @@ -0,0 +1,48 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_index_create_order_link_should_keep_lead_id_when_present_in_filters(): void + { + $this->loginAsPlatformAdmin(); + + $currentUrl = '/admin/platform-orders?' . Arr::query([ + 'lead_id' => 12, + 'payment_status' => 'paid', + 'back' => '/admin/platform-leads', + ]); + + $res = $this->get($currentUrl); + $res->assertOk(); + + $html = (string) $res->getContent(); + preg_match_all('/href="([^"]+)"/', $html, $m); + $hrefs = $m[1] ?? []; + + $createLinks = array_values(array_filter($hrefs, fn ($u) => str_contains($u, '/admin/platform-orders/create?'))); + $this->assertNotEmpty($createLinks, '未找到“新建平台订单”链接'); + + $parts = parse_url($createLinks[0]); + parse_str($parts['query'] ?? '', $q); + + $this->assertSame('12', (string) ($q['lead_id'] ?? '')); + } +}