39235-vm/api/stats.php
2026-03-18 12:17:47 +00:00

17 lines
627 B
PHP

<?php
declare(strict_types=1);
require_once __DIR__ . '/_bootstrap.php';
ensure_schema();
$pdo = db();
$sent = (int)$pdo->query("SELECT COUNT(*) FROM messages WHERE direction = 'out' AND DATE(created_at) = CURDATE()")->fetchColumn();
$received = (int)$pdo->query("SELECT COUNT(*) FROM messages WHERE direction = 'in' AND DATE(created_at) = CURDATE()")->fetchColumn();
$active = (int)$pdo->query("SELECT COUNT(DISTINCT contact_id) FROM messages WHERE created_at >= DATE_SUB(NOW(), INTERVAL 7 DAY)")->fetchColumn();
json_response([
'sent_today' => $sent,
'received_today' => $received,
'active_contacts' => $active,
]);