feat(админка): состояния платежей и журнала
This commit is contained in:
+54
-19
@@ -856,7 +856,7 @@ document.addEventListener('DOMContentLoaded',function(){applyThemeIcon();applyDe
|
||||
<!-- Платежи ЮKassa (этап 3 публичного запуска) -->
|
||||
<div class="page" id="page-payments">
|
||||
<h2>Платежи</h2>
|
||||
<div class="toolbar"><button type="button" class="btn-sm" onclick="downloadCsv('/api/admin/export/payments.csv?days=30', 'payments.csv')">CSV</button></div>
|
||||
<div class="toolbar"><button type="button" class="btn-sm" onclick="downloadCsv('/api/admin/export/payments.csv?days=30', 'payments.csv')">CSV</button> <span id="payments-updated" class="note" role="status"></span></div>
|
||||
<table id="payments">
|
||||
<tr><th>Время</th><th>Пользователь</th><th>Тариф</th><th class="num">₽</th><th>Статус</th><th>ID ЮKassa</th></tr>
|
||||
</table>
|
||||
@@ -930,6 +930,7 @@ document.addEventListener('DOMContentLoaded',function(){applyThemeIcon();applyDe
|
||||
</select>
|
||||
<button class="btn btn-slim" onclick="loadAudit(0)">Фильтр</button>
|
||||
<button class="btn btn-slim" onclick="downloadAuditCsv()">CSV</button>
|
||||
<span id="audit-updated" class="note" role="status"></span>
|
||||
</div>
|
||||
<table id="audit">
|
||||
<tr><th>Время</th><th>Пользователь</th><th>Действие</th><th>Путь</th><th>Детали</th><th>IP</th><th>Код</th></tr>
|
||||
@@ -2391,12 +2392,19 @@ async function loadFinance() {
|
||||
loadFinance();
|
||||
|
||||
// === Платежи ЮKassa ===
|
||||
const PAY_HEAD = '<tr><th>Время</th><th>Пользователь</th><th>Тариф</th><th class="num">₽</th><th>Статус</th><th>ID ЮKassa</th></tr>';
|
||||
async function loadPayments() {
|
||||
const t = document.getElementById('payments');
|
||||
const upd = document.getElementById('payments-updated');
|
||||
if (!t) return;
|
||||
t.innerHTML = PAY_HEAD + '<tr><td colspan="6" class="dim">Загрузка…</td></tr>';
|
||||
try {
|
||||
const r = await запрос('/api/admin/payments?days=30');
|
||||
const d = await r.json();
|
||||
const t = document.getElementById('payments');
|
||||
t.innerHTML = '<tr><th>Время</th><th>Пользователь</th><th>Тариф</th><th class="num">₽</th><th>Статус</th><th>ID ЮKassa</th></tr>';
|
||||
t.innerHTML = PAY_HEAD;
|
||||
if (!d.payments.length) {
|
||||
t.insertAdjacentHTML('beforeend', '<tr class="row-empty"><td colspan="6">Платежей за 30 дней нет</td></tr>');
|
||||
}
|
||||
for (const p of d.payments) {
|
||||
const tr = document.createElement('tr');
|
||||
// username/product — пользовательские данные → только textContent (не innerHTML)
|
||||
@@ -2405,7 +2413,12 @@ async function loadPayments() {
|
||||
fillCells(tr, cells, [3]);
|
||||
t.appendChild(tr);
|
||||
}
|
||||
} catch (e) {}
|
||||
if (upd) upd.textContent = 'обновлено ' + new Date().toLocaleTimeString('ru-RU', {hour:'2-digit', minute:'2-digit'});
|
||||
} catch (e) {
|
||||
t.innerHTML = PAY_HEAD + '<tr><td colspan="6" class="bad">Не удалось загрузить платежи: '
|
||||
+ esc(e.message || 'сеть') + ' <button type="button" class="btn-sm" onclick="loadPayments()">Повторить</button></td></tr>';
|
||||
if (upd) upd.textContent = 'ошибка загрузки';
|
||||
}
|
||||
}
|
||||
loadPayments();
|
||||
|
||||
@@ -2546,9 +2559,10 @@ function loadInvites() {
|
||||
loadInvites();
|
||||
|
||||
// === Audit Log ===
|
||||
let auditOffset = 0;
|
||||
let auditOffset = 0, auditReq = 0;
|
||||
const AUDIT_LIMIT = 200;
|
||||
|
||||
const AUDIT_HEAD = '<tr><th>Время</th><th>Пользователь</th><th>Действие</th><th>Путь</th><th>Детали</th><th>IP</th><th>Код</th></tr>';
|
||||
async function loadAudit(offset) {
|
||||
auditOffset = offset || 0;
|
||||
const user = document.getElementById('audit-user').value;
|
||||
@@ -2556,22 +2570,43 @@ async function loadAudit(offset) {
|
||||
let url = `/api/admin/audit?limit=${AUDIT_LIMIT}&offset=${auditOffset}`;
|
||||
if (user) url += `&username=${encodeURIComponent(user)}`;
|
||||
if (action) url += `&action=${encodeURIComponent(action)}`;
|
||||
const r = await fetch(url, {headers: H});
|
||||
if (!r.ok) return;
|
||||
const rows = await r.json();
|
||||
const t = document.getElementById('audit');
|
||||
if (auditOffset === 0) t.innerHTML = '<tr><th>Время</th><th>Пользователь</th><th>Действие</th><th>Путь</th><th>Детали</th><th>IP</th><th>Код</th></tr>';
|
||||
for (const row of rows) {
|
||||
const d = new Date(row.timestamp < 1e12 ? row.timestamp*1000 : row.timestamp);
|
||||
const ts = d.toLocaleString('ru-RU',{day:'2-digit',month:'2-digit',year:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit'});
|
||||
const tr = document.createElement('tr');
|
||||
const detail = esc((row.detail||'').slice(0,80));
|
||||
const sc = row.status_code;
|
||||
const scStyle = sc >= 400 ? 'color:var(--danger)' : '';
|
||||
tr.innerHTML = `<td class="time">${ts}</td><td>${esc(row.username||'-')}</td><td><b>${esc(row.action)}</b></td><td class="time">${esc(row.path)}</td><td class="q" title="${esc(row.detail||'')}">${detail}</td><td class="time">${esc(row.ip||'')}</td><td style="${scStyle}">${sc||''}</td>`;
|
||||
t.appendChild(tr);
|
||||
const upd = document.getElementById('audit-updated');
|
||||
const more = document.getElementById('audit-more');
|
||||
const my = ++auditReq;
|
||||
t.querySelectorAll('.row-err').forEach(e => e.remove());
|
||||
if (auditOffset === 0) t.innerHTML = AUDIT_HEAD + '<tr><td colspan="7" class="dim">Загрузка…</td></tr>';
|
||||
if (more) more.disabled = true;
|
||||
try {
|
||||
const r = await запрос(url);
|
||||
const rows = await r.json();
|
||||
if (my !== auditReq) return;
|
||||
if (auditOffset === 0) t.innerHTML = AUDIT_HEAD;
|
||||
for (const row of rows) {
|
||||
const d = new Date(row.timestamp < 1e12 ? row.timestamp*1000 : row.timestamp);
|
||||
const ts = d.toLocaleString('ru-RU',{day:'2-digit',month:'2-digit',year:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit'});
|
||||
const tr = document.createElement('tr');
|
||||
const detail = esc((row.detail||'').slice(0,80));
|
||||
const sc = row.status_code;
|
||||
const scStyle = sc >= 400 ? 'color:var(--danger)' : '';
|
||||
tr.innerHTML = `<td class="time">${ts}</td><td>${esc(row.username||'-')}</td><td><b>${esc(row.action)}</b></td><td class="time">${esc(row.path)}</td><td class="q" title="${esc(row.detail||'')}">${detail}</td><td class="time">${esc(row.ip||'')}</td><td style="${scStyle}">${sc||''}</td>`;
|
||||
t.appendChild(tr);
|
||||
}
|
||||
if (!rows.length && auditOffset === 0) {
|
||||
t.insertAdjacentHTML('beforeend', '<tr class="row-empty"><td colspan="7">Записей нет</td></tr>');
|
||||
}
|
||||
if (upd) upd.textContent = 'обновлено ' + new Date().toLocaleTimeString('ru-RU', {hour:'2-digit', minute:'2-digit'});
|
||||
if (more) { more.disabled = false; more.style.display = rows.length >= AUDIT_LIMIT ? '' : 'none'; }
|
||||
} catch (e) {
|
||||
if (my !== auditReq) return;
|
||||
const errRow = '<tr class="row-err"><td colspan="7" class="bad">Не удалось загрузить журнал: '
|
||||
+ esc(e.message || 'сеть') + ' <button type="button" class="btn-sm" onclick="loadAudit('
|
||||
+ auditOffset + ')">Повторить</button></td></tr>';
|
||||
if (auditOffset === 0) t.innerHTML = AUDIT_HEAD + errRow;
|
||||
else t.insertAdjacentHTML('beforeend', errRow);
|
||||
if (upd) upd.textContent = 'ошибка загрузки';
|
||||
if (more) { more.disabled = false; more.style.display = 'none'; }
|
||||
}
|
||||
document.getElementById('audit-more').style.display = rows.length >= AUDIT_LIMIT ? '' : 'none';
|
||||
}
|
||||
|
||||
// Списки фильтров берём у сервера по ВСЕМУ журналу: прежде они собирались из двухсот
|
||||
|
||||
Reference in New Issue
Block a user