feat(пополнение): кнопка и окно суммы в чате, ссылка на /stats, колонки и возврат в админке

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
anor
2026-10-28 14:57:27 +10:00
co-authored by Claude Opus 5.5
parent 289ce1ff1e
commit a157d9151c
4 changed files with 195 additions and 16 deletions
+55 -7
View File
@@ -564,6 +564,12 @@ document.addEventListener('DOMContentLoaded',function(){applyThemeIcon();applyDe
<input id="bs-price" type="text" style="width:120px" placeholder="15000"></label>
<label class="field">Коэффициент цены (наценка), ×<br>
<input id="bs-markup" type="text" style="width:80px" placeholder="1,5"></label>
<label class="field">Пополнение онлайн: от, ₽<br>
<input id="bs-topup-min" type="text" style="width:80px" placeholder="300"></label>
<label class="field">до, ₽<br>
<input id="bs-topup-max" type="text" style="width:90px" placeholder="20000"></label>
<label class="field">Суммы-кнопки, ₽ через запятую<br>
<input id="bs-topup-presets" type="text" style="width:170px" placeholder="500,1000,3000,5000"></label>
<button class="btn" onclick="saveBillingSettings()">Сохранить</button>
<span id="bs-note" class="note"></span>
</div>
@@ -806,8 +812,9 @@ document.addEventListener('DOMContentLoaded',function(){applyThemeIcon();applyDe
<div class="page" id="page-payments">
<h2>Платежи</h2>
<table id="payments">
<tr><th>Время</th><th>Пользователь</th><th>Тариф</th><th class="num">₽</th><th>Статус</th><th>ID ЮKassa</th></tr>
<tr><th>Время</th><th>Пользователь</th><th>Что</th><th class="num">₽</th><th>Платёжка</th><th>Номер у платёжки</th><th>Статус</th><th class="num">Зачислено</th><th class="num">Возвращено</th><th class="num">Можно вернуть</th><th></th></tr>
</table>
<p class="note">Возврат делается в кабинете платёжки — там же аннулируйте чек. Потом нажмите «Возврат проведён» и впишите ту же сумму: запись на счёт человека придёт сама.</p>
</div>
<!-- Метрики: четыре сигнала работы службы и продуктовая воронка -->
@@ -2037,6 +2044,11 @@ async function loadBillingSettings() {
document.getElementById('bs-plan').value = d.zai_plan || '';
document.getElementById('bs-price').value = d.zai_plan_price_rub_year || '';
document.getElementById('bs-markup').value = d.price_markup || '';
if (d.topup) {
document.getElementById('bs-topup-min').value = d.topup.min;
document.getElementById('bs-topup-max').value = d.topup.max;
document.getElementById('bs-topup-presets').value = d.topup.presets.join(',');
}
const rub4 = v => v.toFixed(4).replace('.', ',') + ' ₽';
// Причины независимы: курс нужен дипсику, план и цена подписки — зайке. Одна общая
// фраза на все случаи отправляла оператора чинить не то поле (поймал Хозяин 09.09.2026).
@@ -2060,7 +2072,10 @@ async function saveBillingSettings() {
const body = {usd_rub_rate: document.getElementById('bs-rate').value.trim(),
zai_plan: document.getElementById('bs-plan').value,
zai_plan_price_rub_year: document.getElementById('bs-price').value.trim(),
price_markup: document.getElementById('bs-markup').value.trim()};
price_markup: document.getElementById('bs-markup').value.trim(),
topup_min_rub: document.getElementById('bs-topup-min').value.trim(),
topup_max_rub: document.getElementById('bs-topup-max').value.trim(),
topup_presets: document.getElementById('bs-topup-presets').value.trim()};
// Пустое поле не отправляем: ручка меняет только присланное.
for (const k of Object.keys(body)) if (body[k] === '') delete body[k];
if (!Object.keys(body).length) { alert('Нечего сохранять'); return; }
@@ -2201,23 +2216,56 @@ async function loadFinance() {
}
loadFinance();
// === Платежи ЮKassa ===
// === Платежи: старые ЮKassa и пополнения онлайн ===
const PAY_STATUS = {new: 'создан', pending: 'ждёт оплаты', succeeded: 'оплачен', canceled: 'не оплачен',
failed: 'не создан', unapplied: 'оплачен, НЕ зачислен', refunded: 'возвращён'};
async function loadPayments() {
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 = '<tr><th>Время</th><th>Пользователь</th><th>Что</th><th class="num">₽</th><th>Платёжка</th>'
+ '<th>Номер у платёжки</th><th>Статус</th><th class="num">Зачислено</th><th class="num">Возвращено</th>'
+ '<th class="num">Можно вернуть</th><th></th></tr>';
const money = v => (v === null || v === undefined) ? '—' : Number(v).toLocaleString('ru-RU', {maximumFractionDigits: 2});
for (const p of d.payments) {
const tr = document.createElement('tr');
const topup = p.kind === 'topup';
const credited = topup && ['succeeded', 'refunded'].includes(p.status) ? p.amount_rub : 0;
// username/product — пользовательские данные → только textContent (не innerHTML)
const cells = [new Date(p.ts * 1000).toLocaleString('ru-RU'), p.username, p.product,
p.amount_rub, p.status, p.yk_payment_id || '—'];
fillCells(tr, cells, [3]);
const cells = [new Date(p.ts * 1000).toLocaleString('ru-RU'), p.username,
topup ? 'пополнение' : p.product, money(p.amount_rub), p.provider,
p.provider_id || '—', PAY_STATUS[p.status] || p.status,
topup ? money(credited) : '—', money(p.refunded_rub),
topup ? money(p.refundable_rub) : '—'];
fillCells(tr, cells, [3, 7, 8, 9]);
const td = document.createElement('td');
if (topup && p.status === 'succeeded') {
const btn = document.createElement('button');
btn.className = 'btn';
btn.textContent = 'Возврат проведён';
btn.onclick = () => topupRefund(p);
td.appendChild(btn);
}
tr.appendChild(td);
t.appendChild(tr);
}
} catch (e) {}
}
async function topupRefund(p) {
const left = p.amount_rub - p.refunded_rub;
const amount = prompt('Сколько вернули человеку ' + p.username + ' в кабинете платёжки, ₽?\n'
+ 'Остаток платежа ' + left.toLocaleString('ru-RU') + ' ₽; не потрачено со счёта '
+ Number(p.refundable_rub).toLocaleString('ru-RU') + ' ₽. Аннулируйте чек там же.',
String(p.refundable_rub || left));
if (amount === null || !amount.trim()) return;
const r = await fetch('/api/admin/topups/' + p.id + '/refund', {method: 'POST',
headers: {...H, 'Content-Type': 'application/json'}, body: JSON.stringify({amount: amount.trim()})});
let d = {};
try { d = await r.json(); } catch (e) {}
if (!r.ok) { alert(d.detail || ('Ответ сервера ' + r.status)); return; }
loadPayments();
}
loadPayments();
// === Files (admin) ===