points-history: concepto/método/estado multiidioma
Los valores de las columnas Concepto/Método/Estado venían en español desde la lib.
Ahora getPointsHistory devuelve CLAVES (conceptKey+args, method 'vote'/'promo',
status 'delivered'/'pending'/'credited') y la página las traduce. Concepto por
servicio ("Rename character: {char}", "Vote on {site}", "Code {code}", "{n} PD");
los pagos heredados sin servicio caen a conceptRaw. Claves nuevas en History.points.
Verificado con la cuenta 15: todas las combinaciones resuelven en es y en.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -89,12 +89,14 @@ export default async function PointsHistoryPage({ params }: { params: Promise<{
|
|||||||
{movements.map((m, i) => (
|
{movements.map((m, i) => (
|
||||||
<tr key={i}>
|
<tr key={i}>
|
||||||
<td>{fmt(m.date)}</td>
|
<td>{fmt(m.date)}</td>
|
||||||
<td>{m.concept}</td>
|
<td>{m.conceptKey ? t(`points.concept.${m.conceptKey}`, m.conceptArgs) : m.conceptRaw}</td>
|
||||||
<td className={methodClass(m.method)}>{m.method}</td>
|
<td className={methodClass(m.method)}>
|
||||||
|
{m.method === 'vote' || m.method === 'promo' ? t(`points.method.${m.method}`) : m.method}
|
||||||
|
</td>
|
||||||
<td className="yellow-info">{m.pd != null ? `+${m.pd}` : '—'}</td>
|
<td className="yellow-info">{m.pd != null ? `+${m.pd}` : '—'}</td>
|
||||||
<td className="purple-info">{m.pv != null ? `+${m.pv}` : '—'}</td>
|
<td className="purple-info">{m.pv != null ? `+${m.pv}` : '—'}</td>
|
||||||
<td>{m.amount != null ? `${m.amount.toFixed(2)} €` : '—'}</td>
|
<td>{m.amount != null ? `${m.amount.toFixed(2)} €` : '—'}</td>
|
||||||
<td>{m.status}</td>
|
<td>{t(`points.status.${m.status}`)}</td>
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -1,15 +1,35 @@
|
|||||||
import type { RowDataPacket } from 'mysql2'
|
import type { RowDataPacket } from 'mysql2'
|
||||||
import { db, DB } from './db'
|
import { db, DB } from './db'
|
||||||
|
|
||||||
/** Un movimiento del historial de PD/PV (pagos, votos, promociones). */
|
/**
|
||||||
|
* Un movimiento del historial de PD/PV. Los textos visibles se devuelven como
|
||||||
|
* CLAVES para que la página los traduzca (i18n): `method`, `status` y el concepto
|
||||||
|
* (`conceptKey` + `conceptArgs`, con `conceptRaw` de reserva para textos libres
|
||||||
|
* heredados que no tienen clave).
|
||||||
|
*/
|
||||||
export interface PointsMovement {
|
export interface PointsMovement {
|
||||||
date: Date
|
date: Date
|
||||||
concept: string
|
conceptKey: string | null // p.ej. 'pd','vote','promo','rename','gold'…
|
||||||
method: 'Stripe' | 'SumUp' | 'Voto' | 'Promoción'
|
conceptArgs: Record<string, string | number>
|
||||||
pd: number | null // PD del movimiento (+), null si no aplica
|
conceptRaw: string // reserva (product_name) cuando conceptKey es null
|
||||||
pv: number | null // PV del movimiento (+), null si no aplica
|
method: 'Stripe' | 'SumUp' | 'vote' | 'promo'
|
||||||
amount: number | null // importe en € (pagos), null si no aplica
|
pd: number | null
|
||||||
status: string
|
pv: number | null
|
||||||
|
amount: number | null // € (pagos), null si no aplica
|
||||||
|
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. */
|
||||||
@@ -46,8 +66,7 @@ function purchasedPD(productName: string, service: string | null, metadata: stri
|
|||||||
* - `home_stripelog`: pagos por **Stripe** (mode test/live) y **SumUp** (mode sumup).
|
* - `home_stripelog`: pagos por **Stripe** (mode test/live) y **SumUp** (mode sumup).
|
||||||
* - `home_votelog` (+ `home_votesite`): PV ganados al votar.
|
* - `home_votelog` (+ `home_votesite`): PV ganados al votar.
|
||||||
* - `home_promoredemption` (+ `home_promocode`): PD/PV canjeados por código.
|
* - `home_promoredemption` (+ `home_promocode`): PD/PV canjeados por código.
|
||||||
* Se ordena por fecha descendente. Cada consulta es tolerante a fallos (devuelve
|
* Ordenado por fecha descendente; cada consulta es tolerante a fallos.
|
||||||
* [] si la tabla no existe) para no romper la página.
|
|
||||||
*/
|
*/
|
||||||
export async function getPointsHistory(accountId: number, limit = 100): Promise<PointsMovement[]> {
|
export async function getPointsHistory(accountId: number, limit = 100): Promise<PointsMovement[]> {
|
||||||
if (!accountId) return []
|
if (!accountId) return []
|
||||||
@@ -56,20 +75,37 @@ export async function getPointsHistory(accountId: number, limit = 100): Promise<
|
|||||||
// 1) Pagos (Stripe + SumUp).
|
// 1) Pagos (Stripe + SumUp).
|
||||||
try {
|
try {
|
||||||
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
const [rows] = await db(DB.default).query<RowDataPacket[]>(
|
||||||
'SELECT product_name, amount, mode, service, metadata, fulfilled, timestamp ' +
|
'SELECT product_name, character_name, amount, mode, service, metadata, fulfilled, timestamp ' +
|
||||||
'FROM home_stripelog WHERE account_id = ? ORDER BY timestamp DESC LIMIT ?',
|
'FROM home_stripelog WHERE account_id = ? ORDER BY timestamp DESC LIMIT ?',
|
||||||
[accountId, limit],
|
[accountId, limit],
|
||||||
)
|
)
|
||||||
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 pd = purchasedPD(productName, service, r.metadata ? String(r.metadata) : null)
|
||||||
|
|
||||||
|
// 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),
|
||||||
concept: String(r.product_name || '—'),
|
conceptKey,
|
||||||
|
conceptArgs,
|
||||||
|
conceptRaw: productName,
|
||||||
method: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
method: r.mode === 'sumup' ? 'SumUp' : 'Stripe',
|
||||||
pd: purchasedPD(String(r.product_name || ''), service, r.metadata ? String(r.metadata) : null),
|
pd,
|
||||||
pv: null,
|
pv: null,
|
||||||
amount: Number(r.amount),
|
amount: Number(r.amount),
|
||||||
status: r.fulfilled ? 'Entregado' : 'Pendiente',
|
status: r.fulfilled ? 'delivered' : 'pending',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -86,12 +122,14 @@ export async function getPointsHistory(accountId: number, limit = 100): Promise<
|
|||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
movements.push({
|
movements.push({
|
||||||
date: new Date(r.created_at),
|
date: new Date(r.created_at),
|
||||||
concept: `Voto en ${r.name}`,
|
conceptKey: 'vote',
|
||||||
method: 'Voto',
|
conceptArgs: { detail: String(r.name || '') },
|
||||||
|
conceptRaw: `Voto en ${r.name}`,
|
||||||
|
method: 'vote',
|
||||||
pd: null,
|
pd: null,
|
||||||
pv: Number(r.points) || 0,
|
pv: Number(r.points) || 0,
|
||||||
amount: null,
|
amount: null,
|
||||||
status: 'Acreditado',
|
status: 'credited',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -108,12 +146,14 @@ export async function getPointsHistory(accountId: number, limit = 100): Promise<
|
|||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
movements.push({
|
movements.push({
|
||||||
date: new Date(r.redeemed_at),
|
date: new Date(r.redeemed_at),
|
||||||
concept: `Código ${r.code}`,
|
conceptKey: 'promo',
|
||||||
method: 'Promoción',
|
conceptArgs: { detail: String(r.code || '') },
|
||||||
|
conceptRaw: `Código ${r.code}`,
|
||||||
|
method: 'promo',
|
||||||
pd: Number(r.pd) > 0 ? Number(r.pd) : null,
|
pd: Number(r.pd) > 0 ? Number(r.pd) : null,
|
||||||
pv: Number(r.pv) > 0 ? Number(r.pv) : null,
|
pv: Number(r.pv) > 0 ? Number(r.pv) : null,
|
||||||
amount: null,
|
amount: null,
|
||||||
status: 'Acreditado',
|
status: 'credited',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
@@ -980,7 +980,30 @@
|
|||||||
"thConcept": "Concept",
|
"thConcept": "Concept",
|
||||||
"thMethod": "Method",
|
"thMethod": "Method",
|
||||||
"thAmount": "Amount",
|
"thAmount": "Amount",
|
||||||
"thStatus": "Status"
|
"thStatus": "Status",
|
||||||
|
"concept": {
|
||||||
|
"pd": "{n} PD",
|
||||||
|
"vote": "Vote on {detail}",
|
||||||
|
"promo": "Code {detail}",
|
||||||
|
"rename": "Rename character: {detail}",
|
||||||
|
"customize": "Customize character: {detail}",
|
||||||
|
"changeRace": "Change race: {detail}",
|
||||||
|
"changeFaction": "Change faction: {detail}",
|
||||||
|
"levelUp": "Level up to 80: {detail}",
|
||||||
|
"gold": "Acquire gold: {detail}",
|
||||||
|
"transfer": "Transfer character: {detail}",
|
||||||
|
"restoreItem": "Restore item: {detail}",
|
||||||
|
"sendGift": "Gift for {detail}"
|
||||||
|
},
|
||||||
|
"method": {
|
||||||
|
"vote": "Vote",
|
||||||
|
"promo": "Promotion"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"delivered": "Delivered",
|
||||||
|
"pending": "Pending",
|
||||||
|
"credited": "Credited"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"trans": {
|
"trans": {
|
||||||
"pageTitle": "Transaction history",
|
"pageTitle": "Transaction history",
|
||||||
|
|||||||
@@ -980,7 +980,30 @@
|
|||||||
"thConcept": "Concepto",
|
"thConcept": "Concepto",
|
||||||
"thMethod": "Método",
|
"thMethod": "Método",
|
||||||
"thAmount": "Importe",
|
"thAmount": "Importe",
|
||||||
"thStatus": "Estado"
|
"thStatus": "Estado",
|
||||||
|
"concept": {
|
||||||
|
"pd": "{n} PD",
|
||||||
|
"vote": "Voto en {detail}",
|
||||||
|
"promo": "Código {detail}",
|
||||||
|
"rename": "Renombrar personaje: {detail}",
|
||||||
|
"customize": "Personalizar personaje: {detail}",
|
||||||
|
"changeRace": "Cambiar raza: {detail}",
|
||||||
|
"changeFaction": "Cambiar facción: {detail}",
|
||||||
|
"levelUp": "Subir a nivel 80: {detail}",
|
||||||
|
"gold": "Adquirir oro: {detail}",
|
||||||
|
"transfer": "Transferir personaje: {detail}",
|
||||||
|
"restoreItem": "Recuperar ítem: {detail}",
|
||||||
|
"sendGift": "Regalo para {detail}"
|
||||||
|
},
|
||||||
|
"method": {
|
||||||
|
"vote": "Voto",
|
||||||
|
"promo": "Promoción"
|
||||||
|
},
|
||||||
|
"status": {
|
||||||
|
"delivered": "Entregado",
|
||||||
|
"pending": "Pendiente",
|
||||||
|
"credited": "Acreditado"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"trans": {
|
"trans": {
|
||||||
"pageTitle": "Historial de transacciones",
|
"pageTitle": "Historial de transacciones",
|
||||||
|
|||||||
Reference in New Issue
Block a user