From 3dbea4e070e6e2e9e93c96e8ff73309225e9a279 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=9D=E5=8D=9C?= Date: Sat, 14 Mar 2026 04:29:40 +0000 Subject: [PATCH] =?UTF-8?q?feat(admin):=20=E5=BC=80=E9=80=9A=E7=BA=BF?= =?UTF-8?q?=E7=B4=A2=E5=88=97=E8=A1=A8=E6=94=AF=E6=8C=81=E6=8C=89=20lead?= =?UTF-8?q?=5Fid=20=E7=B2=BE=E7=A1=AE=E7=AD=9B=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/PlatformLeadController.php | 7 ++ .../admin/platform_leads/index.blade.php | 1 + ...AdminPlatformLeadIndexLeadIdFilterTest.php | 64 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/Feature/AdminPlatformLeadIndexLeadIdFilterTest.php diff --git a/app/Http/Controllers/Admin/PlatformLeadController.php b/app/Http/Controllers/Admin/PlatformLeadController.php index 29a356b..a836466 100644 --- a/app/Http/Controllers/Admin/PlatformLeadController.php +++ b/app/Http/Controllers/Admin/PlatformLeadController.php @@ -22,11 +22,18 @@ class PlatformLeadController extends Controller $filters = [ 'status' => trim((string) $request->query('status', '')), 'keyword' => trim((string) $request->query('keyword', '')), + // 精确过滤:线索ID(用于从订单/运营动作回溯到某条线索) + 'lead_id' => trim((string) $request->query('lead_id', '')), ]; $query = PlatformLead::query(); $query->when($filters['status'] !== '', fn (Builder $b) => $b->where('status', $filters['status'])); + + $query->when($filters['lead_id'] !== '' && ctype_digit($filters['lead_id']), function (Builder $b) use ($filters) { + $b->where('id', (int) $filters['lead_id']); + }); + $query->when($filters['keyword'] !== '', function (Builder $b) use ($filters) { $kw = $filters['keyword']; $b->where(function (Builder $q) use ($kw) { diff --git a/resources/views/admin/platform_leads/index.blade.php b/resources/views/admin/platform_leads/index.blade.php index a436e7f..dcdd974 100644 --- a/resources/views/admin/platform_leads/index.blade.php +++ b/resources/views/admin/platform_leads/index.blade.php @@ -63,6 +63,7 @@ @endforeach +
diff --git a/tests/Feature/AdminPlatformLeadIndexLeadIdFilterTest.php b/tests/Feature/AdminPlatformLeadIndexLeadIdFilterTest.php new file mode 100644 index 0000000..60ca03e --- /dev/null +++ b/tests/Feature/AdminPlatformLeadIndexLeadIdFilterTest.php @@ -0,0 +1,64 @@ +seed(); + + $this->post('/admin/login', [ + 'email' => 'platform.admin@demo.local', + 'password' => 'Platform@123456', + ])->assertRedirect('/admin'); + } + + public function test_index_should_render_lead_id_filter_field(): void + { + $this->loginAsPlatformAdmin(); + + $res = $this->get('/admin/platform-leads'); + $res->assertOk(); + $res->assertSee('name="lead_id"', false); + } + + public function test_index_should_filter_by_lead_id(): void + { + $this->loginAsPlatformAdmin(); + + $a = PlatformLead::query()->create([ + 'name' => '线索A', + 'mobile' => '', + 'email' => '', + 'company' => '', + 'source' => 'test', + 'status' => 'new', + 'plan_id' => null, + 'meta' => ['from' => 'test'], + ]); + + PlatformLead::query()->create([ + 'name' => '线索B', + 'mobile' => '', + 'email' => '', + 'company' => '', + 'source' => 'test', + 'status' => 'new', + 'plan_id' => null, + 'meta' => ['from' => 'test'], + ]); + + $res = $this->get('/admin/platform-leads?lead_id=' . $a->id); + $res->assertOk(); + $res->assertSee((string) $a->id); + $res->assertSee('线索A'); + $res->assertDontSee('线索B'); + } +}