78 lines
2.0 KiB
PHP
78 lines
2.0 KiB
PHP
<?php
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
require_once __DIR__ . '/../config/database.php';
|
|
require_once __DIR__ . '/message_text_helper.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
|
http_response_code(405);
|
|
echo json_encode([
|
|
'status' => 'error',
|
|
'message' => 'Method not allowed',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$pdo = getAnalyticsPdo();
|
|
$stmt = $pdo->query("
|
|
SELECT
|
|
id,
|
|
table_id,
|
|
message_type,
|
|
message_text,
|
|
otwierajacy_imie,
|
|
otwierajacy_nazwisko,
|
|
status_kds,
|
|
api_sent,
|
|
created_at,
|
|
updated_at
|
|
FROM guest_action_queue
|
|
WHERE DATE(created_at) = CURDATE()
|
|
ORDER BY created_at DESC
|
|
LIMIT 500
|
|
");
|
|
$rows = $stmt->fetchAll();
|
|
|
|
$pending = 0;
|
|
$waiterCalls = 0;
|
|
$billRequests = 0;
|
|
|
|
foreach ($rows as &$row) {
|
|
$row['id'] = (int) $row['id'];
|
|
$row['status_kds'] = (int) $row['status_kds'];
|
|
$row['api_sent'] = (int) $row['api_sent'];
|
|
$row['message_text'] = normalizeQueueMessageText((string) ($row['message_text'] ?? ''));
|
|
|
|
if ($row['status_kds'] === 0) {
|
|
$pending++;
|
|
}
|
|
if ($row['message_type'] === 'waiter_call') {
|
|
$waiterCalls++;
|
|
} elseif ($row['message_type'] === 'bill_request') {
|
|
$billRequests++;
|
|
}
|
|
}
|
|
unset($row);
|
|
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'date' => date('Y-m-d'),
|
|
'count' => count($rows),
|
|
'summary' => [
|
|
'pending' => $pending,
|
|
'waiter_calls' => $waiterCalls,
|
|
'bill_requests' => $billRequests,
|
|
],
|
|
'polled_at' => date('Y-m-d H:i:s'),
|
|
'poll_interval_seconds' => 15,
|
|
'data' => $rows,
|
|
], JSON_UNESCAPED_UNICODE);
|
|
} catch (Throwable $e) {
|
|
http_response_code(500);
|
|
echo json_encode([
|
|
'status' => 'error',
|
|
'message' => 'Waiter feed fetch failed',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
}
|