61 lines
4.0 KiB
PHP
Executable File
61 lines
4.0 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
header('Access-Control-Allow-Origin: *');
|
|
$db = new PDO("pgsql:host=localhost;dbname=adx_system","admin","admin123");
|
|
$action = $_GET['action'] ?? 'list';
|
|
|
|
if ($action === 'preview') {
|
|
$id = intval($_GET['id'] ?? 0);
|
|
$row = $db->query("SELECT * FROM admin.unified_send_log_new WHERE id=$id")->fetch(PDO::FETCH_ASSOC);
|
|
if ($row) {
|
|
$oid = intval($row['offer_id'] ?? 0);
|
|
$cid = intval($row['creative_id'] ?? 0);
|
|
// Get creative - try exact offer_id first, then creative_id
|
|
$cr = $db->query("SELECT value FROM affiliate.creatives WHERE offer_id=$oid AND status='Activated' ORDER BY RANDOM() LIMIT 1")->fetch(PDO::FETCH_ASSOC);
|
|
if (!$cr && $cid > 0) {
|
|
$cr = $db->query("SELECT value FROM affiliate.creatives WHERE id=$cid")->fetch(PDO::FETCH_ASSOC);
|
|
}
|
|
// Get offer URL - from log or from links table
|
|
$offerUrl = $row['offer_url_used'] ?? '';
|
|
if (!$offerUrl) {
|
|
$link = $db->query("SELECT value FROM affiliate.links WHERE offer_id=$oid AND type='preview' AND value LIKE 'http%' LIMIT 1")->fetch(PDO::FETCH_ASSOC);
|
|
$offerUrl = $link['value'] ?? '';
|
|
}
|
|
$row['offer_url_used'] = $offerUrl;
|
|
$t = "https://wevup.app";
|
|
$clickUrl = "$t/click.php?url=" . base64_encode($offerUrl) . "&oid=$oid&e=test";
|
|
$row['click_url'] = $clickUrl;
|
|
if ($cr && $cr['value']) {
|
|
$html = base64_decode($cr['value']);
|
|
$html = str_replace(['[url]','[open]','[unsub]'], [$clickUrl,'#','#'], $html);
|
|
$row['html_preview'] = $html;
|
|
}
|
|
}
|
|
echo json_encode($row ?: ['error'=>'not found']); exit;
|
|
}
|
|
if ($action === 'creative') {
|
|
echo json_encode($db->query("SELECT c.id,c.name,c.offer_id,length(c.value) as html_size,o.name as offer_name,o.countries FROM affiliate.creatives c JOIN affiliate.offers o ON o.id=c.offer_id WHERE c.status='Activated' ORDER BY c.offer_id")->fetchAll(PDO::FETCH_ASSOC)); exit;
|
|
}
|
|
if ($action === 'creative_html') {
|
|
$cid = intval($_GET['cid'] ?? 0);
|
|
$r = $db->query("SELECT value FROM affiliate.creatives WHERE id=$cid")->fetch(PDO::FETCH_ASSOC);
|
|
header('Content-Type: text/html; charset=UTF-8');
|
|
echo $r ? str_replace(['[url]','[open]','[unsub]'],['#','#','#'],base64_decode($r['value'])) : "Not found"; exit;
|
|
}
|
|
if ($action === 'methods') {
|
|
echo json_encode([
|
|
'providers'=>$db->query("SELECT provider,count(*) as total,sum(case when status='active' then 1 else 0 end) as active FROM admin.email_send_accounts GROUP BY provider ORDER BY total DESC")->fetchAll(PDO::FETCH_ASSOC),
|
|
'brain_methods'=>$db->query("SELECT send_method,count(*) as configs FROM admin.brain_configs WHERE is_active=true GROUP BY send_method ORDER BY configs DESC")->fetchAll(PDO::FETCH_ASSOC)
|
|
]); exit;
|
|
}
|
|
$limit=min(intval($_GET['limit']??100),500); $offset=intval($_GET['offset']??0);
|
|
$search=$_GET['search']??''; $filter=$_GET['filter']??'all';
|
|
$w="1=1";
|
|
if($filter==='warmup')$w.=" AND send_method='bcg_warmup'";
|
|
if($filter==='brain')$w.=" AND send_method!='bcg_warmup'";
|
|
if($search){$s=addslashes($search);$w.=" AND (subject ILIKE '%$s%' OR to_email ILIKE '%$s%' OR offer_name ILIKE '%$s%' OR from_email ILIKE '%$s%')";}
|
|
$rows=$db->query("SELECT * FROM admin.unified_send_log_new WHERE $w ORDER BY created_at DESC LIMIT $limit OFFSET $offset")->fetchAll(PDO::FETCH_ASSOC);
|
|
$total=$db->query("SELECT count(*) FROM admin.unified_send_log_new WHERE $w")->fetchColumn();
|
|
$stats=$db->query("SELECT send_method,count(*) as cnt,sum(case when status='sent' then 1 else 0 end) as ok,sum(case when status!='sent' then 1 else 0 end) as fail FROM admin.unified_send_log_new GROUP BY send_method")->fetchAll(PDO::FETCH_ASSOC);
|
|
echo json_encode(['total'=>$total,'stats'=>$stats,'offers_used'=>$db->query("SELECT count(DISTINCT offer_id) FROM admin.unified_send_log_new")->fetchColumn(),'creatives_count'=>$db->query("SELECT count(*) FROM affiliate.creatives WHERE status='Activated'")->fetchColumn(),'sends'=>$rows]);
|