import type { Metadata } from "next"; import Link from "next/link"; import { cookies } from "next/headers"; import { Coins, Flame, Gift, Layers } from "lucide-react"; import { fetchAdminEconomyStats } from "@/lib/api"; import { authCookieHeader } from "@/lib/cookies"; import { getMeCached } from "@/lib/serverData"; import { isAdminOrAbove } from "@/lib/roles"; import { postTypeLabel } from "@/lib/postMeta"; import { pointReasonLabel } from "@/lib/points"; import { formatRelative } from "@/lib/format"; import Forbidden from "../Forbidden"; export const metadata: Metadata = { title: "积分看板", }; const fmt = (n: number) => n.toLocaleString("zh-CN"); export default async function AdminEconomyPage() { const cookie = authCookieHeader(await cookies()); const me = await getMeCached(cookie || undefined); if (!me.user || !isAdminOrAbove(me.user.role)) { return ; } let stats: Awaited> | null = null; try { stats = await fetchAdminEconomyStats(cookie); } catch { stats = null; } if (!stats) { return (

暂时无法加载积分数据

); } const cards = [ { label: "用户余额合计", value: fmt(stats.total_balance), icon: , hint: "全站可用积分之和", }, { label: "今日签到", value: fmt(stats.checkin_today), icon: , hint: "今日已签到人数", }, { label: "托管中悬赏", value: `${fmt(stats.open_bounties)} / ${fmt(stats.escrowed_points)}`, icon: , hint: "未结算帖数 / 托管积分", }, { label: "流水条数", value: fmt(stats.ledger_count), icon: , hint: "历史入账出账记录", }, ]; const typeEntries = Object.entries(stats.posts_by_type || {}).sort( (a, b) => b[1] - a[1] ); return (

积分与类型帖看板

观察全站积分流通、悬赏托管与帖子类型分布

{cards.map((c) => (
{c.icon} {c.label}

{c.value}

{c.hint}

))}
帖子类型分布
{typeEntries.length === 0 ? (

暂无数据

) : (
    {typeEntries.map(([t, n]) => (
  • {postTypeLabel(t)} {fmt(n)}
  • ))}
)}
最近流水
{(stats.recent_ledger || []).length === 0 ? (

暂无流水

) : (
    {stats.recent_ledger.map((it) => (
  • {pointReasonLabel(it.reason)} {it.note ? ` · ${it.note}` : ""}

    {formatRelative(it.created_at)}

    = 0 ? "var(--accent)" : "var(--danger)" }} > {it.delta >= 0 ? `+${it.delta}` : it.delta}
  • ))}
)}

用户可在{" "} /points {" "} 查看个人流水。

); }