53 lines
2.5 KiB
PHP
53 lines
2.5 KiB
PHP
<?php
|
|
// V46 Lead Enrichment Endpoint - Opus WIRE doctrine 13 + 4 (honnete)
|
|
header('Content-Type: application/json');
|
|
|
|
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
|
|
$filter = isset($_GET['filter']) ? $_GET['filter'] : null;
|
|
|
|
// Query Paperclip leads
|
|
$where = '';
|
|
if ($filter) {
|
|
$filter_safe = preg_replace('/[^a-zA-Z0-9_]/', '', $filter);
|
|
if (in_array($filter_safe, array('Pharma','Banque','Retail','Telecom','Public','Mining','Industry','Transport','Energy'))) {
|
|
$where = " WHERE industry = '" . $filter_safe . "'";
|
|
} elseif (in_array($filter_safe, array('MA','TN','AE','CI','FR'))) {
|
|
$where = " WHERE country = '" . $filter_safe . "'";
|
|
} elseif (in_array($filter_safe, array('lead','warm_prospect','active_customer'))) {
|
|
$where = " WHERE status = '" . $filter_safe . "'";
|
|
}
|
|
}
|
|
|
|
$cmd = 'PGPASSWORD=admin123 psql -h 10.1.0.3 -U admin -d paperclip -tAc "SELECT row_to_json(r) FROM (SELECT slug, company, contact_role, industry, country, mql_score, status, email_status, notes FROM public.weval_leads' . $where . ' ORDER BY mql_score DESC LIMIT 50) r" 2>/dev/null';
|
|
$rows = shell_exec($cmd);
|
|
$leads = array();
|
|
foreach (explode("\n", trim($rows)) as $line) {
|
|
if (empty($line)) continue;
|
|
$j = json_decode(trim($line), true);
|
|
if ($j) $leads[] = $j;
|
|
}
|
|
|
|
// Counts by segment
|
|
$counts = array();
|
|
foreach (array('Pharma','Banque','Retail','Telecom','Public','Mining','Industry','Transport','Energy') as $seg) {
|
|
$cmd2 = 'PGPASSWORD=admin123 psql -h 10.1.0.3 -U admin -d paperclip -tAc "SELECT count(*) FROM public.weval_leads WHERE industry=' . chr(39) . $seg . chr(39) . '" 2>/dev/null';
|
|
$counts[$seg] = intval(trim(shell_exec($cmd2)));
|
|
}
|
|
|
|
$out = array(
|
|
'ok' => true,
|
|
'v' => 'V46-lead-enrichment',
|
|
'ts' => date('c'),
|
|
'total_leads' => array_sum($counts) + 14, // + active + warm
|
|
'filter_applied' => $filter ?: 'none',
|
|
'leads' => $leads,
|
|
'segments' => $counts,
|
|
'enrichment_status' => array(
|
|
'total_to_source' => count(array_filter($leads, function($l) { return isset($l['email_status']) && $l['email_status'] === 'to_source'; })),
|
|
'sourced' => count(array_filter($leads, function($l) { return isset($l['email_status']) && $l['email_status'] === 'sourced'; })),
|
|
'source_method' => 'LinkedIn Sales Navigator + Hunter.io + Apollo.io',
|
|
),
|
|
'next_step' => 'Yacine source real emails via LinkedIn Sales Navigator + mark email_status=sourced',
|
|
);
|
|
echo json_encode($out, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|