trans-history: concepto multiidioma (helper de concepto compartido)
Extrae la lógica de concepto traducible a lib/tx-concept.ts (buildConcept + purchasedPD + SERVICE_CONCEPT) y la reutilizan points-history y trans-history. La columna Concepto de trans-history ahora se traduce (reusa History.points.concept.*) en vez de mostrar el product_name en español. Corrige también la sombra de variable en PlatformBox (map t -> tx). Verificado con la cuenta 15. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -73,22 +73,22 @@ async function PlatformBox({
|
|||||||
<th>{t('trans.thCreatedAt')}</th>
|
<th>{t('trans.thCreatedAt')}</th>
|
||||||
<th>{t('trans.thAmount')}</th>
|
<th>{t('trans.thAmount')}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{txs.map((t) => (
|
{txs.map((tx) => (
|
||||||
<tr key={t.id}>
|
<tr key={tx.id}>
|
||||||
<td className="long-td">
|
<td className="long-td">
|
||||||
<span>{t.id}</span>
|
<span>{tx.id}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<StatusBadge status={t.status} />
|
<StatusBadge status={tx.status} />
|
||||||
</td>
|
</td>
|
||||||
<td className="responsive-td">
|
<td className="responsive-td">
|
||||||
<span>{t.concept}</span>
|
<span>{tx.conceptKey ? t(`points.concept.${tx.conceptKey}`, tx.conceptArgs) : tx.conceptRaw}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span>{fmt(t.createdAt)}</span>
|
<span>{fmt(tx.createdAt)}</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span>{t.amount.toFixed(2)} €</span>
|
<span>{tx.amount.toFixed(2)} €</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { RowDataPacket } from 'mysql2'
|
import type { RowDataPacket } from 'mysql2'
|
||||||
import { db, DB } from './db'
|
import { db, DB } from './db'
|
||||||
|
import { buildConcept, purchasedPD } from './tx-concept'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Un movimiento del historial de PD/PV. Los textos visibles se devuelven como
|
* Un movimiento del historial de PD/PV. Los textos visibles se devuelven como
|
||||||
@@ -19,19 +20,6 @@ export interface PointsMovement {
|
|||||||
status: 'delivered' | 'pending' | 'credited'
|
status: 'delivered' | 'pending' | 'credited'
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Slug de servicio (home_stripelog.service) -> clave de concepto traducible. */
|
|
||||||
const SERVICE_CONCEPT: Record<string, string> = {
|
|
||||||
rename: 'rename',
|
|
||||||
customize: 'customize',
|
|
||||||
'change-race': 'changeRace',
|
|
||||||
'change-faction': 'changeFaction',
|
|
||||||
'level-up': 'levelUp',
|
|
||||||
gold: 'gold',
|
|
||||||
transfer: 'transfer',
|
|
||||||
'restore-item': 'restoreItem',
|
|
||||||
'send-gift': 'sendGift',
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Saldos actuales de PD y PV de una cuenta de juego. */
|
/** Saldos actuales de PD y PV de una cuenta de juego. */
|
||||||
export async function getPointsBalances(accountId: number): Promise<{ dp: number; pv: number }> {
|
export async function getPointsBalances(accountId: number): Promise<{ dp: number; pv: number }> {
|
||||||
if (!accountId) return { dp: 0, pv: 0 }
|
if (!accountId) return { dp: 0, pv: 0 }
|
||||||
@@ -46,21 +34,6 @@ export async function getPointsBalances(accountId: number): Promise<{ dp: number
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** PD acreditados por un pago (si es una compra de PD), o null si es un servicio/ítem. */
|
|
||||||
function purchasedPD(productName: string, service: string | null, metadata: string | null): number | null {
|
|
||||||
const m = /(\d+)\s*PD\b/i.exec(productName || '')
|
|
||||||
if (m) return Number(m[1])
|
|
||||||
if (service === 'dpoints') {
|
|
||||||
try {
|
|
||||||
const p = metadata ? JSON.parse(metadata).points : null
|
|
||||||
return p ? Number(p) : null
|
|
||||||
} catch {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Historial unificado de PD/PV de una cuenta, combinando las fuentes reales:
|
* Historial unificado de PD/PV de una cuenta, combinando las fuentes reales:
|
||||||
* - `home_stripelog`: pagos por **Stripe** (mode test/live) y **SumUp** (mode sumup).
|
* - `home_stripelog`: pagos por **Stripe** (mode test/live) y **SumUp** (mode sumup).
|
||||||
@@ -82,27 +55,15 @@ export async function getPointsHistory(accountId: number, limit = 100): Promise<
|
|||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
const service = r.service ? String(r.service) : null
|
const service = r.service ? String(r.service) : null
|
||||||
const productName = String(r.product_name || '—')
|
const productName = String(r.product_name || '—')
|
||||||
const pd = purchasedPD(productName, service, r.metadata ? String(r.metadata) : null)
|
const metadata = r.metadata ? String(r.metadata) : null
|
||||||
|
const c = buildConcept(productName, service, String(r.character_name || ''), metadata)
|
||||||
// Concepto traducible: compra de PD -> "{n} PD"; servicio conocido ->
|
|
||||||
// "{etiqueta}: {personaje}"; en otro caso, texto libre heredado.
|
|
||||||
let conceptKey: string | null = null
|
|
||||||
let conceptArgs: Record<string, string | number> = {}
|
|
||||||
if (pd != null && (service === 'dpoints' || service === null)) {
|
|
||||||
conceptKey = 'pd'
|
|
||||||
conceptArgs = { n: pd }
|
|
||||||
} else if (service && SERVICE_CONCEPT[service]) {
|
|
||||||
conceptKey = SERVICE_CONCEPT[service]
|
|
||||||
conceptArgs = { detail: String(r.character_name || '') }
|
|
||||||
}
|
|
||||||
|
|
||||||
movements.push({
|
movements.push({
|
||||||
date: new Date(r.timestamp),
|
date: new Date(r.timestamp),
|
||||||
conceptKey,
|
conceptKey: c.conceptKey,
|
||||||
conceptArgs,
|
conceptArgs: c.conceptArgs,
|
||||||
conceptRaw: productName,
|
conceptRaw: c.conceptRaw,
|
||||||
method: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
method: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
||||||
pd,
|
pd: purchasedPD(productName, service, metadata),
|
||||||
pv: null,
|
pv: null,
|
||||||
amount: Number(r.amount),
|
amount: Number(r.amount),
|
||||||
status: r.fulfilled ? 'delivered' : 'pending',
|
status: r.fulfilled ? 'delivered' : 'pending',
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { RowDataPacket } from 'mysql2'
|
import type { RowDataPacket } from 'mysql2'
|
||||||
import { db, DB } from './db'
|
import { db, DB } from './db'
|
||||||
|
import { buildConcept } from './tx-concept'
|
||||||
|
|
||||||
/** Una transacción de pago (Stripe o SumUp) registrada en home_stripelog. */
|
/** Una transacción de pago (Stripe o SumUp) registrada en home_stripelog. */
|
||||||
export interface PaymentTx {
|
export interface PaymentTx {
|
||||||
@@ -8,7 +9,10 @@ export interface PaymentTx {
|
|||||||
status: 'PAID' | 'PENDING'
|
status: 'PAID' | 'PENDING'
|
||||||
createdAt: Date
|
createdAt: Date
|
||||||
amount: number // importe en €
|
amount: number // importe en €
|
||||||
concept: string
|
// Concepto traducible (clave + args) con reserva de texto libre.
|
||||||
|
conceptKey: string | null
|
||||||
|
conceptArgs: Record<string, string | number>
|
||||||
|
conceptRaw: string
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,18 +24,28 @@ export async function getPaymentTransactions(accountId: number, limit = 200): Pr
|
|||||||
if (!accountId) return []
|
if (!accountId) return []
|
||||||
try {
|
try {
|
||||||
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
||||||
"SELECT session_id, product_name, amount, mode, fulfilled, timestamp FROM home_stripelog " +
|
'SELECT session_id, product_name, character_name, amount, mode, service, metadata, fulfilled, timestamp FROM home_stripelog ' +
|
||||||
"WHERE account_id = ? AND mode IN ('sumup', 'test', 'live') ORDER BY timestamp DESC LIMIT ?",
|
"WHERE account_id = ? AND mode IN ('sumup', 'test', 'live') ORDER BY timestamp DESC LIMIT ?",
|
||||||
[accountId, limit],
|
[accountId, limit],
|
||||||
)
|
)
|
||||||
return rows.map((r) => ({
|
return rows.map((r) => {
|
||||||
id: String(r.session_id || ''),
|
const c = buildConcept(
|
||||||
platform: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
String(r.product_name || '—'),
|
||||||
status: r.fulfilled ? 'PAID' : 'PENDING',
|
r.service ? String(r.service) : null,
|
||||||
createdAt: new Date(r.timestamp),
|
String(r.character_name || ''),
|
||||||
amount: Number(r.amount),
|
r.metadata ? String(r.metadata) : null,
|
||||||
concept: String(r.product_name || '—'),
|
)
|
||||||
}))
|
return {
|
||||||
|
id: String(r.session_id || ''),
|
||||||
|
platform: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
||||||
|
status: r.fulfilled ? 'PAID' : 'PENDING',
|
||||||
|
createdAt: new Date(r.timestamp),
|
||||||
|
amount: Number(r.amount),
|
||||||
|
conceptKey: c.conceptKey,
|
||||||
|
conceptArgs: c.conceptArgs,
|
||||||
|
conceptRaw: c.conceptRaw,
|
||||||
|
}
|
||||||
|
})
|
||||||
} catch {
|
} catch {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
// Concepto traducible de una transacción de home_stripelog, compartido por los
|
||||||
|
// historiales de PD/PV y de transacciones. Devuelve una CLAVE (+ argumentos) que
|
||||||
|
// la página traduce; `conceptRaw` es la reserva para pagos heredados sin servicio.
|
||||||
|
|
||||||
|
/** Slug de servicio (home_stripelog.service) -> clave de concepto (History.points.concept.*). */
|
||||||
|
export const SERVICE_CONCEPT: Record<string, string> = {
|
||||||
|
rename: 'rename',
|
||||||
|
customize: 'customize',
|
||||||
|
'change-race': 'changeRace',
|
||||||
|
'change-faction': 'changeFaction',
|
||||||
|
'level-up': 'levelUp',
|
||||||
|
gold: 'gold',
|
||||||
|
transfer: 'transfer',
|
||||||
|
'restore-item': 'restoreItem',
|
||||||
|
'send-gift': 'sendGift',
|
||||||
|
}
|
||||||
|
|
||||||
|
/** PD acreditados por un pago (si es una compra de PD), o null si es un servicio/ítem. */
|
||||||
|
export function purchasedPD(productName: string, service: string | null, metadata: string | null): number | null {
|
||||||
|
const m = /(\d+)\s*PD\b/i.exec(productName || '')
|
||||||
|
if (m) return Number(m[1])
|
||||||
|
if (service === 'dpoints') {
|
||||||
|
try {
|
||||||
|
const p = metadata ? JSON.parse(metadata).points : null
|
||||||
|
return p ? Number(p) : null
|
||||||
|
} catch {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Concept {
|
||||||
|
conceptKey: string | null
|
||||||
|
conceptArgs: Record<string, string | number>
|
||||||
|
conceptRaw: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Concepto de una fila de home_stripelog: compra de PD -> "{n} PD"; servicio
|
||||||
|
* conocido -> "{etiqueta}: {personaje}"; en otro caso, texto libre heredado.
|
||||||
|
*/
|
||||||
|
export function buildConcept(
|
||||||
|
productName: string,
|
||||||
|
service: string | null,
|
||||||
|
characterName: string,
|
||||||
|
metadata: string | null,
|
||||||
|
): Concept {
|
||||||
|
const raw = productName || '—'
|
||||||
|
const pd = purchasedPD(raw, service, metadata)
|
||||||
|
if (pd != null && (service === 'dpoints' || service === null)) {
|
||||||
|
return { conceptKey: 'pd', conceptArgs: { n: pd }, conceptRaw: raw }
|
||||||
|
}
|
||||||
|
if (service && SERVICE_CONCEPT[service]) {
|
||||||
|
return { conceptKey: SERVICE_CONCEPT[service], conceptArgs: { detail: characterName }, conceptRaw: raw }
|
||||||
|
}
|
||||||
|
return { conceptKey: null, conceptArgs: {}, conceptRaw: raw }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user