feat(admin): 开通线索列表支持按 lead_id 精确筛选
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
@endforeach
|
||||
</select>
|
||||
<input name="keyword" placeholder="关键词:姓名/手机号/邮箱/公司" value="{{ $filters['keyword'] ?? '' }}">
|
||||
<input type="number" name="lead_id" placeholder="线索ID(可选)" value="{{ $filters['lead_id'] ?? '' }}">
|
||||
<div>
|
||||
<button type="submit">应用筛选</button>
|
||||
</div>
|
||||
|
||||
64
tests/Feature/AdminPlatformLeadIndexLeadIdFilterTest.php
Normal file
64
tests/Feature/AdminPlatformLeadIndexLeadIdFilterTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\PlatformLead;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminPlatformLeadIndexLeadIdFilterTest 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_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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user