fix: PHP heredoc interpretaba template literals JS como constantes PHP
- Convierte backtick template literals con \${it.id} a concatenación de strings
- Fix query de chatConversations: GROUP BY solo por phone_number, evita duplicados
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
b308de2b3b
commit
14db6fe27f
@@ -675,20 +675,21 @@ async function refreshDrawer() {
|
||||
body.innerHTML = '<div style="text-align:center;color:#a0a8b8;padding:40px 0;font-size:15px">✅ Sin pendientes</div>';
|
||||
return;
|
||||
}
|
||||
body.innerHTML = items.map(it => `
|
||||
<div class="dp-card" id="dp-${it.id}">
|
||||
<div class="dp-top">
|
||||
<span class="dp-phone">${esc(it.phone)}</span>
|
||||
<span class="dp-name">${esc(it.contact_name || '')}</span>
|
||||
<span class="dp-time">${(it.created_at||'').substr(11,5)}</span>
|
||||
</div>
|
||||
<div class="dp-in">↩ ${esc(it.incoming_message || '')}</div>
|
||||
<div class="dp-resp">🤖 ${esc(getPreview(it.bot_response))}</div>
|
||||
<div class="dp-actions">
|
||||
<button class="dp-approve" onclick="pendingAction(${it.id},'approve',this)">✓ Aprobar</button>
|
||||
<button class="dp-reject" onclick="pendingAction(${it.id},'reject',this)">✕ Rechazar</button>
|
||||
</div>
|
||||
</div>`).join('');
|
||||
body.innerHTML = items.map(function(it) {
|
||||
return '<div class="dp-card" id="dp-' + it.id + '">'
|
||||
+ '<div class="dp-top">'
|
||||
+ '<span class="dp-phone">' + esc(it.phone) + '</span>'
|
||||
+ '<span class="dp-name">' + esc(it.contact_name || '') + '</span>'
|
||||
+ '<span class="dp-time">' + (it.created_at||'').substr(11,5) + '</span>'
|
||||
+ '</div>'
|
||||
+ '<div class="dp-in">↩ ' + esc(it.incoming_message || '') + '</div>'
|
||||
+ '<div class="dp-resp">🤖 ' + esc(getPreview(it.bot_response)) + '</div>'
|
||||
+ '<div class="dp-actions">'
|
||||
+ '<button class="dp-approve" onclick="pendingAction(' + it.id + ',\'approve\',this)">✓ Aprobar</button>'
|
||||
+ '<button class="dp-reject" onclick="pendingAction(' + it.id + ',\'reject\',this)">✕ Rechazar</button>'
|
||||
+ '</div>'
|
||||
+ '</div>';
|
||||
}).join('');
|
||||
} catch(e) {
|
||||
body.innerHTML = '<div style="text-align:center;color:#991b1b;padding:20px">Error al cargar</div>';
|
||||
}
|
||||
@@ -1939,12 +1940,14 @@ HTML;
|
||||
$db = db();
|
||||
// Get unique conversations with last message and unread count
|
||||
$rows = $db->query("
|
||||
SELECT c.phone_number, c.contact_name, c.company_id,
|
||||
MAX(c.created_at) as last_time,
|
||||
SELECT c.phone_number,
|
||||
MAX(c.contact_name) as contact_name,
|
||||
MAX(c.company_id) as company_id,
|
||||
MAX(c.created_at) as last_time,
|
||||
(SELECT content FROM conversations c2 WHERE c2.phone_number = c.phone_number ORDER BY c2.id DESC LIMIT 1) as last_message,
|
||||
(SELECT COUNT(*) FROM conversations c3 WHERE c3.phone_number = c.phone_number AND c3.direction = 'inbound' AND c3.id > COALESCE((SELECT MAX(c4.id) FROM conversations c4 WHERE c4.phone_number = c.phone_number AND c4.direction = 'outbound'), 0)) as unread_count
|
||||
FROM conversations c
|
||||
GROUP BY c.phone_number, c.contact_name, c.company_id
|
||||
GROUP BY c.phone_number
|
||||
ORDER BY last_time DESC
|
||||
")->fetchAll();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user