feat: 添加管理员钱包相关API和更新模块结构

This commit is contained in:
2026-05-09 15:22:27 +08:00
parent 38d40f3a8b
commit 4ace3151e6
14 changed files with 930 additions and 59 deletions

65
src/api/admin-wallet.ts Normal file
View File

@@ -0,0 +1,65 @@
import { adminRequest } from "@/lib/admin-http";
import { API_V1_PREFIX } from "./paths";
import type {
AdminPlayerWalletsData,
AdminTransferOrderListData,
AdminWalletTxnListData,
} from "@/types/api/admin-wallet";
const A = `${API_V1_PREFIX}/admin`;
export type TransferOrderListQuery = {
page?: number;
per_page?: number;
player_id?: number;
/** 模糊site_player_id / username */
player_account?: string;
transfer_no?: string;
external_ref_no?: string;
created_from?: string;
created_to?: string;
status?: string;
abnormal?: boolean;
};
export async function getAdminTransferOrders(
q: TransferOrderListQuery = {},
): Promise<AdminTransferOrderListData> {
return adminRequest.get<AdminTransferOrderListData>(
`${A}/wallet/transfer-orders`,
{ params: q },
);
}
export type WalletTransactionListQuery = {
page?: number;
per_page?: number;
player_id?: number;
player_account?: string;
txn_no?: string;
external_ref_no?: string;
created_from?: string;
created_to?: string;
biz_type?: string;
status?: string;
abnormal?: boolean;
};
export async function getAdminWalletTransactions(
q: WalletTransactionListQuery = {},
): Promise<AdminWalletTxnListData> {
return adminRequest.get<AdminWalletTxnListData>(
`${A}/wallet/transactions`,
{ params: q },
);
}
export async function getAdminPlayerWallets(
playerId: number,
): Promise<AdminPlayerWalletsData> {
return adminRequest.get<AdminPlayerWalletsData>(
`${A}/players/${playerId}/wallets`,
);
}

View File

@@ -1,6 +1,11 @@
export { API_V1_PREFIX } from "@/api/paths";
export { getAdminCaptcha, postAdminLogin } from "@/api/admin-auth";
export { getAdminPing } from "@/api/admin-ping";
export {
getAdminPlayerWallets,
getAdminTransferOrders,
getAdminWalletTransactions,
} from "@/api/admin-wallet";
export type {
AdminAuthCaptchaResponse,
AdminAuthLoginRequest,

View File

@@ -8,10 +8,7 @@ export const metadata: Metadata = {
export default function AdminDrawsPage() {
return (
<ModuleScaffold
title={drawsModuleMeta.title}
description={drawsModuleMeta.description}
>
<ModuleScaffold>
<p className="text-sm text-zinc-500 dark:text-zinc-400">
{" "}
<code className="rounded bg-zinc-100 px-1 py-0.5 font-mono text-xs dark:bg-zinc-800">

View File

@@ -1,6 +1,5 @@
import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { getAdminPing } from "@/api";
import { dashboardModuleMeta } from "@/modules/dashboard/meta";
import type { Metadata } from "next";
export const metadata: Metadata = {
@@ -12,10 +11,7 @@ export default async function AdminDashboardPage() {
const apiReady = process.env.NEXT_PUBLIC_LOTTERY_API_BASE_URL?.trim() !== "";
return (
<ModuleScaffold
title={dashboardModuleMeta.title}
description={dashboardModuleMeta.description}
>
<ModuleScaffold>
<div className="grid gap-4 sm:grid-cols-2">
<div className="rounded-xl border border-black/10 bg-white p-5 shadow-sm dark:border-white/10 dark:bg-zinc-900">
<h2 className="text-xs font-semibold uppercase tracking-wide text-zinc-500 dark:text-zinc-400">

View File

@@ -8,10 +8,7 @@ export const metadata: Metadata = {
export default function AdminPlayersPage() {
return (
<ModuleScaffold
title={playersModuleMeta.title}
description={playersModuleMeta.description}
>
<ModuleScaffold>
<p className="text-sm text-zinc-500 dark:text-zinc-400">
{" "}
<code className="rounded bg-zinc-100 px-1 py-0.5 font-mono text-xs dark:bg-zinc-800">

View File

@@ -8,10 +8,7 @@ export const metadata: Metadata = {
export default function AdminRiskPage() {
return (
<ModuleScaffold
title={riskModuleMeta.title}
description={riskModuleMeta.description}
>
<ModuleScaffold>
<p className="text-sm text-zinc-500 dark:text-zinc-400">
{" "}
<code className="rounded bg-zinc-100 px-1 py-0.5 font-mono text-xs dark:bg-zinc-800">

View File

@@ -8,10 +8,7 @@ export const metadata: Metadata = {
export default function AdminSettingsPage() {
return (
<ModuleScaffold
title={settingsModuleMeta.title}
description={settingsModuleMeta.description}
>
<ModuleScaffold>
<p className="text-sm text-zinc-500 dark:text-zinc-400">
{" "}
<code className="rounded bg-zinc-100 px-1 py-0.5 font-mono text-xs dark:bg-zinc-800">

View File

@@ -8,10 +8,7 @@ export const metadata: Metadata = {
export default function AdminTicketsPage() {
return (
<ModuleScaffold
title={ticketsModuleMeta.title}
description={ticketsModuleMeta.description}
>
<ModuleScaffold>
<p className="text-sm text-zinc-500 dark:text-zinc-400">
{" "}
<code className="rounded bg-zinc-100 px-1 py-0.5 font-mono text-xs dark:bg-zinc-800">

View File

@@ -1,5 +1,6 @@
import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { walletModuleMeta } from "@/modules/wallet/meta";
import { WalletConsole } from "@/modules/wallet/wallet-console";
import type { Metadata } from "next";
export const metadata: Metadata = {
@@ -8,17 +9,8 @@ export const metadata: Metadata = {
export default function AdminWalletPage() {
return (
<ModuleScaffold
title={walletModuleMeta.title}
description={walletModuleMeta.description}
>
<p className="text-sm text-zinc-500 dark:text-zinc-400">
{" "}
<code className="rounded bg-zinc-100 px-1 py-0.5 font-mono text-xs dark:bg-zinc-800">
src/modules/wallet
</code>{" "}
</p>
<ModuleScaffold className="w-full max-w-none">
<WalletConsole />
</ModuleScaffold>
);
}

View File

@@ -3,29 +3,11 @@ import type { ReactNode } from "react";
import { cn } from "@/lib/utils";
type ModuleScaffoldProps = {
title: string;
description: string;
children?: ReactNode;
className?: string;
};
export function ModuleScaffold({
title,
description,
children,
className,
}: ModuleScaffoldProps) {
return (
<div className={cn("mx-auto max-w-5xl", className)}>
<header className="border-b border-black/10 pb-6 dark:border-white/10">
<h1 className="text-2xl font-semibold tracking-tight text-foreground">
{title}
</h1>
<p className="mt-2 max-w-2xl text-sm leading-6 text-zinc-600 dark:text-zinc-400">
{description}
</p>
</header>
{children !== undefined ? <div className="mt-10">{children}</div> : null}
</div>
);
/** 内容区容器;模块标题由侧栏导航体现,此处不再重复大标题与说明。 */
export function ModuleScaffold({ children, className }: ModuleScaffoldProps) {
return <div className={cn("mx-auto max-w-5xl", className)}>{children}</div>;
}

View File

@@ -1,5 +1,5 @@
export const walletModuleMeta = {
segment: "wallet",
title: "钱包",
description: "资金流水、充值提现审核(占位)。",
title: "钱包流水与对账",
description:""
} as const;

View File

@@ -0,0 +1,754 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { Copy } from "lucide-react";
import { toast } from "sonner";
import {
getAdminPlayerWallets,
getAdminTransferOrders,
getAdminWalletTransactions,
} from "@/api/admin-wallet";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { LotteryApiBizError } from "@/types/api/errors";
import type {
AdminPlayerWalletsData,
AdminTransferOrderListData,
AdminWalletTxnListData,
} from "@/types/api/admin-wallet";
function formatMinorUnits(minor: number, currencyCode: string): string {
const major = minor / 100;
return `${major.toFixed(2)} ${currencyCode}`;
}
function formatTs(iso: string | null | undefined): string {
if (!iso) return "—";
return iso.replace("T", " ").slice(0, 19);
}
/** 长单号/流水号:单行截断;点击复制全文,悬停可看全文 */
function CellMonoId({
value,
empty = "—",
copyHint,
}: {
value: string | null | undefined;
empty?: string;
/** 用于 toast / 无障碍:如「流水号」「主站流水号」 */
copyHint?: string;
}): React.ReactElement {
if (value == null || value === "") {
return <span className="text-muted-foreground">{empty}</span>;
}
const copy = async (e: React.MouseEvent): Promise<void> => {
e.stopPropagation();
try {
await navigator.clipboard.writeText(value);
toast.success(
copyHint
? `${copyHint}已复制到剪贴板`
: "已复制到剪贴板",
);
} catch {
toast.error("复制失败,请检查浏览器权限或手动选择文本");
}
};
return (
<button
type="button"
className="group inline-flex min-w-0 w-full max-w-full items-center gap-1 rounded-md border border-transparent px-0.5 py-0.5 text-left font-mono text-xs transition-colors hover:border-border hover:bg-muted/60"
title={`${value}\n点击复制`}
aria-label={copyHint ? `复制${copyHint}` : "复制到剪贴板"}
onClick={(e) => void copy(e)}
>
<span className="min-w-0 flex-1 truncate">{value}</span>
<Copy
className="size-3.5 shrink-0 text-muted-foreground opacity-60 group-hover:opacity-100"
aria-hidden
/>
</button>
);
}
function statusBadgeVariant(
status: string,
): "default" | "secondary" | "destructive" | "outline" {
if (status === "success" || status === "posted") return "secondary";
if (status === "failed") return "destructive";
if (status === "pending_reconcile") return "outline";
return "default";
}
type TransferFilters = {
playerId: string;
playerAccount: string;
transferNo: string;
externalRefNo: string;
createdFrom: string;
createdTo: string;
statusCsv: string;
abnormalOnly: boolean;
};
const emptyTransferFilters: TransferFilters = {
playerId: "",
playerAccount: "",
transferNo: "",
externalRefNo: "",
createdFrom: "",
createdTo: "",
statusCsv: "",
abnormalOnly: false,
};
type TxnFilters = {
playerId: string;
playerAccount: string;
txnNo: string;
externalRefNo: string;
bizType: string;
statusCsv: string;
createdFrom: string;
createdTo: string;
abnormalOnly: boolean;
};
const emptyTxnFilters: TxnFilters = {
playerId: "",
playerAccount: "",
txnNo: "",
externalRefNo: "",
bizType: "",
statusCsv: "",
createdFrom: "",
createdTo: "",
abnormalOnly: false,
};
export function WalletConsole(): React.ReactElement {
return (
<Tabs defaultValue="txns" className="w-full">
<TabsList variant="line" className="mb-6 w-full justify-start">
<TabsTrigger value="txns"></TabsTrigger>
<TabsTrigger value="orders"></TabsTrigger>
<TabsTrigger value="player"></TabsTrigger>
</TabsList>
<TabsContent value="orders">
<TransferOrdersPanel />
</TabsContent>
<TabsContent value="txns">
<WalletTxnsPanel />
</TabsContent>
<TabsContent value="player">
<PlayerWalletPanel />
</TabsContent>
</Tabs>
);
}
function TransferOrdersPanel(): React.ReactElement {
const [data, setData] = useState<AdminTransferOrderListData | null>(null);
const [loading, setLoading] = useState(true);
const [err, setErr] = useState<string | null>(null);
const [page, setPage] = useState(1);
const [draft, setDraft] = useState<TransferFilters>(emptyTransferFilters);
const [applied, setApplied] = useState<TransferFilters>(emptyTransferFilters);
const load = useCallback(async () => {
setLoading(true);
setErr(null);
try {
const player_id =
applied.playerId.trim() === "" ? undefined : Number(applied.playerId);
const d = await getAdminTransferOrders({
page,
per_page: 20,
abnormal: applied.abnormalOnly || undefined,
player_id:
player_id !== undefined && !Number.isNaN(player_id) && player_id > 0
? player_id
: undefined,
player_account: applied.playerAccount.trim() || undefined,
transfer_no: applied.transferNo.trim() || undefined,
external_ref_no: applied.externalRefNo.trim() || undefined,
created_from: applied.createdFrom.trim() || undefined,
created_to: applied.createdTo.trim() || undefined,
status: applied.statusCsv.trim() || undefined,
});
setData(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "加载失败");
setData(null);
} finally {
setLoading(false);
}
}, [page, applied]);
useEffect(() => {
void load();
}, [load]);
const runSearch = () => {
setApplied({ ...draft });
setPage(1);
};
return (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
§5.11 {" "}
<code className="rounded bg-muted px-1">player_id</code> ID
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<div className="grid gap-1.5">
<Label htmlFor="to-transfer-no"></Label>
<Input
id="to-transfer-no"
placeholder="模糊"
value={draft.transferNo}
onChange={(e) => setDraft((d) => ({ ...d, transferNo: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="to-ext"></Label>
<Input
id="to-ext"
placeholder="模糊"
value={draft.externalRefNo}
onChange={(e) => setDraft((d) => ({ ...d, externalRefNo: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="to-account"></Label>
<Input
id="to-account"
placeholder="site_player_id / 用户名"
value={draft.playerAccount}
onChange={(e) => setDraft((d) => ({ ...d, playerAccount: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="to-player"> ID</Label>
<Input
id="to-player"
inputMode="numeric"
placeholder="可选,优先于账号"
value={draft.playerId}
onChange={(e) => setDraft((d) => ({ ...d, playerId: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="to-from"></Label>
<Input
id="to-from"
type="date"
value={draft.createdFrom}
onChange={(e) => setDraft((d) => ({ ...d, createdFrom: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="to-to"></Label>
<Input
id="to-to"
type="date"
value={draft.createdTo}
onChange={(e) => setDraft((d) => ({ ...d, createdTo: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="to-status"></Label>
<Input
id="to-status"
placeholder="逗号分隔,如 pending_reconcile,failed"
value={draft.statusCsv}
onChange={(e) => setDraft((d) => ({ ...d, statusCsv: e.target.value }))}
/>
</div>
<div className="flex flex-col justify-end gap-2 sm:col-span-2 lg:col-span-1">
<span className="text-sm font-medium leading-none"></span>
<label className="flex min-h-9 cursor-pointer items-center gap-2 text-sm">
<Checkbox
checked={draft.abnormalOnly}
onCheckedChange={(v) =>
setDraft((d) => ({ ...d, abnormalOnly: v === true }))
}
/>
</label>
</div>
</div>
<div className="flex flex-wrap gap-2">
<Button type="button" size="sm" onClick={() => runSearch()}>
</Button>
<Button type="button" size="sm" variant="secondary" onClick={() => void load()}>
</Button>
</div>
{err ? <p className="text-sm text-red-600 dark:text-red-400">{err}</p> : null}
{loading && !data ? (
<p className="text-sm text-muted-foreground"></p>
) : null}
{data ? (
<>
<div className="rounded-md border">
<Table className="table-fixed">
<TableHeader>
<TableRow>
<TableHead className="min-w-0 max-w-[14rem]"></TableHead>
<TableHead className="min-w-0 max-w-[12rem]"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="w-14"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="w-24"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data.items.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-muted-foreground">
</TableCell>
</TableRow>
) : (
data.items.map((row) => (
<TableRow key={row.id}>
<TableCell className="min-w-0 max-w-[14rem] align-top whitespace-normal">
<CellMonoId value={row.transfer_no} copyHint="本地单号" />
</TableCell>
<TableCell className="min-w-0 max-w-[12rem] align-top whitespace-normal">
<CellMonoId value={row.external_ref_no} copyHint="主站流水号" />
</TableCell>
<TableCell className="text-xs">
#{row.player_id}
<br />
<span className="text-muted-foreground">
{row.site_player_id ?? row.username ?? "—"}
</span>
</TableCell>
<TableCell>{row.direction}</TableCell>
<TableCell className="tabular-nums">
{formatMinorUnits(row.amount, row.currency_code)}
</TableCell>
<TableCell>
<Badge variant={statusBadgeVariant(row.status)}>{row.status}</Badge>
</TableCell>
<TableCell className="whitespace-nowrap text-xs text-muted-foreground">
{formatTs(row.created_at)}
</TableCell>
<TableCell className="whitespace-nowrap text-xs text-muted-foreground">
{formatTs(row.finished_at)}
</TableCell>
<TableCell className="text-xs text-muted-foreground"></TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="flex flex-col gap-3 border-t border-border pt-4 sm:flex-row sm:items-center sm:justify-between">
<p className="text-xs text-muted-foreground">
{data.total} · {data.page} /{" "}
{Math.max(1, Math.ceil(data.total / data.per_page))}
</p>
<div className="flex flex-wrap justify-end gap-2">
<Button
type="button"
variant="outline"
size="sm"
disabled={page <= 1 || loading}
onClick={() => setPage((p) => Math.max(1, p - 1))}
>
</Button>
<Button
type="button"
variant="outline"
size="sm"
disabled={loading || data.page >= Math.ceil(data.total / data.per_page)}
onClick={() => setPage((p) => p + 1)}
>
</Button>
</div>
</div>
</>
) : null}
</CardContent>
</Card>
);
}
function WalletTxnsPanel(): React.ReactElement {
const [data, setData] = useState<AdminWalletTxnListData | null>(null);
const [loading, setLoading] = useState(true);
const [err, setErr] = useState<string | null>(null);
const [page, setPage] = useState(1);
const [draft, setDraft] = useState<TxnFilters>(emptyTxnFilters);
const [applied, setApplied] = useState<TxnFilters>(emptyTxnFilters);
const load = useCallback(async () => {
setLoading(true);
setErr(null);
try {
const player_id =
applied.playerId.trim() === "" ? undefined : Number(applied.playerId);
const d = await getAdminWalletTransactions({
page,
per_page: 20,
abnormal: applied.abnormalOnly || undefined,
player_id:
player_id !== undefined && !Number.isNaN(player_id) && player_id > 0
? player_id
: undefined,
player_account: applied.playerAccount.trim() || undefined,
txn_no: applied.txnNo.trim() || undefined,
external_ref_no: applied.externalRefNo.trim() || undefined,
created_from: applied.createdFrom.trim() || undefined,
created_to: applied.createdTo.trim() || undefined,
biz_type: applied.bizType.trim() || undefined,
status: applied.statusCsv.trim() || undefined,
});
setData(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "加载失败");
setData(null);
} finally {
setLoading(false);
}
}, [page, applied]);
useEffect(() => {
void load();
}, [load]);
const runSearch = () => {
setApplied({ ...draft });
setPage(1);
};
return (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
§5.11 {" "}
<code className="rounded bg-muted px-1">pending_reconcile</code>
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
<div className="grid gap-1.5">
<Label htmlFor="tx-no"></Label>
<Input
id="tx-no"
placeholder="模糊"
value={draft.txnNo}
onChange={(e) => setDraft((d) => ({ ...d, txnNo: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="tx-ext"></Label>
<Input
id="tx-ext"
placeholder="模糊"
value={draft.externalRefNo}
onChange={(e) => setDraft((d) => ({ ...d, externalRefNo: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="tx-account"></Label>
<Input
id="tx-account"
placeholder="site_player_id / 用户名"
value={draft.playerAccount}
onChange={(e) => setDraft((d) => ({ ...d, playerAccount: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="tx-player"> ID</Label>
<Input
id="tx-player"
inputMode="numeric"
placeholder="可选,优先于账号"
value={draft.playerId}
onChange={(e) => setDraft((d) => ({ ...d, playerId: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="tx-biz"></Label>
<Input
id="tx-biz"
placeholder="如 transfer_in"
value={draft.bizType}
onChange={(e) => setDraft((d) => ({ ...d, bizType: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="tx-status"></Label>
<Input
id="tx-status"
placeholder="posted 或逗号分隔"
value={draft.statusCsv}
onChange={(e) => setDraft((d) => ({ ...d, statusCsv: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="tx-from"></Label>
<Input
id="tx-from"
type="date"
value={draft.createdFrom}
onChange={(e) => setDraft((d) => ({ ...d, createdFrom: e.target.value }))}
/>
</div>
<div className="grid gap-1.5">
<Label htmlFor="tx-to"></Label>
<Input
id="tx-to"
type="date"
value={draft.createdTo}
onChange={(e) => setDraft((d) => ({ ...d, createdTo: e.target.value }))}
/>
</div>
<div className="flex flex-col justify-end gap-2 sm:col-span-2 lg:col-span-1">
<span className="text-sm font-medium leading-none"></span>
<label className="flex min-h-9 cursor-pointer items-center gap-2 text-sm">
<Checkbox
checked={draft.abnormalOnly}
onCheckedChange={(v) =>
setDraft((d) => ({ ...d, abnormalOnly: v === true }))
}
/>
</label>
</div>
</div>
<div className="flex flex-wrap gap-2">
<Button type="button" size="sm" onClick={() => runSearch()}>
</Button>
<Button type="button" size="sm" variant="secondary" onClick={() => void load()}>
</Button>
</div>
{err ? <p className="text-sm text-red-600 dark:text-red-400">{err}</p> : null}
{loading && !data ? (
<p className="text-sm text-muted-foreground"></p>
) : null}
{data ? (
<>
<div className="rounded-md border">
<Table className="table-fixed">
<TableHeader>
<TableRow>
<TableHead className="min-w-0 max-w-[14rem]"></TableHead>
<TableHead className="min-w-0 max-w-[12rem]"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="whitespace-nowrap"></TableHead>
<TableHead className="w-24"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{data.items.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-muted-foreground">
</TableCell>
</TableRow>
) : (
data.items.map((row) => (
<TableRow key={row.id}>
<TableCell className="min-w-0 max-w-[14rem] align-top whitespace-normal">
<CellMonoId value={row.txn_no} copyHint="流水号" />
</TableCell>
<TableCell className="min-w-0 max-w-[12rem] align-top whitespace-normal">
<CellMonoId value={row.external_ref_no} copyHint="主站流水号" />
</TableCell>
<TableCell className="min-w-0 text-xs">
#{row.player_id}
<br />
<span className="text-muted-foreground">
{row.site_player_id ?? row.username ?? "—"}
</span>
</TableCell>
<TableCell className="min-w-0 text-xs">{row.biz_type}</TableCell>
<TableCell className="tabular-nums text-xs">
{row.amount} ({row.direction === 1 ? "入" : "出"})
</TableCell>
<TableCell>
<Badge variant={statusBadgeVariant(row.status)}>{row.status}</Badge>
</TableCell>
<TableCell className="whitespace-nowrap text-xs text-muted-foreground">
{formatTs(row.created_at)}
</TableCell>
<TableCell className="whitespace-nowrap text-xs text-muted-foreground">
{formatTs(row.updated_at)}
</TableCell>
<TableCell className="text-xs text-muted-foreground"></TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="flex flex-col gap-3 border-t border-border pt-4 sm:flex-row sm:items-center sm:justify-between">
<p className="text-xs text-muted-foreground">
{data.total} · {data.page} /{" "}
{Math.max(1, Math.ceil(data.total / data.per_page))}
</p>
<div className="flex flex-wrap justify-end gap-2">
<Button
type="button"
variant="outline"
size="sm"
disabled={page <= 1 || loading}
onClick={() => setPage((p) => Math.max(1, p - 1))}
>
</Button>
<Button
type="button"
variant="outline"
size="sm"
disabled={loading || data.page >= Math.ceil(data.total / data.per_page)}
onClick={() => setPage((p) => p + 1)}
>
</Button>
</div>
</div>
</>
) : null}
</CardContent>
</Card>
);
}
function PlayerWalletPanel(): React.ReactElement {
const [playerId, setPlayerId] = useState("");
const [result, setResult] = useState<AdminPlayerWalletsData | null>(null);
const [err, setErr] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const query = useCallback(async () => {
const id = Number(playerId.trim());
if (Number.isNaN(id) || id < 1) {
setErr("请输入有效玩家 ID");
setResult(null);
return;
}
setLoading(true);
setErr(null);
try {
const d = await getAdminPlayerWallets(id);
setResult(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "查询失败");
setResult(null);
} finally {
setLoading(false);
}
}, [playerId]);
return (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<CardDescription>
<code className="rounded bg-muted px-1">players.id</code>{" "}
§5.12
</CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="flex flex-wrap items-end gap-2">
<div className="grid gap-1.5">
<Label htmlFor="pw-id"> ID</Label>
<Input
id="pw-id"
inputMode="numeric"
placeholder="例如 1"
value={playerId}
onChange={(e) => setPlayerId(e.target.value)}
className="w-40"
/>
</div>
<Button type="button" onClick={() => void query()} disabled={loading}>
{loading ? "查询中…" : "查询"}
</Button>
</div>
{err ? <p className="text-sm text-red-600 dark:text-red-400">{err}</p> : null}
{result ? (
<div className="space-y-3 rounded-lg border p-4 text-sm">
<p>
<span className="text-muted-foreground"></span>{" "}
{result.player.site_code}:{result.player.site_player_id}
</p>
<Table>
<TableHeader>
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{result.wallets.length === 0 ? (
<TableRow>
<TableCell colSpan={4} className="text-muted-foreground">
</TableCell>
</TableRow>
) : (
result.wallets.map((w) => (
<TableRow key={w.id}>
<TableCell>{w.wallet_type}</TableCell>
<TableCell>{w.currency_code}</TableCell>
<TableCell className="font-mono tabular-nums">{w.balance}</TableCell>
<TableCell className="tabular-nums">
{formatMinorUnits(w.available_balance, w.currency_code)}
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
) : null}
</CardContent>
</Card>
);
}

View File

@@ -0,0 +1,84 @@
/** GET /api/v1/admin/wallet/transfer-orders */
export type AdminTransferOrderItem = {
id: number;
transfer_no: string;
player_id: number;
site_code: string | null;
site_player_id: string | null;
username: string | null;
nickname: string | null;
direction: string;
currency_code: string;
amount: number;
idempotent_key: string;
status: string;
external_ref_no: string | null;
external_request_payload: Record<string, unknown> | null;
external_response_payload: Record<string, unknown> | null;
fail_reason: string | null;
created_at: string | null;
finished_at: string | null;
};
export type AdminTransferOrderListData = {
items: AdminTransferOrderItem[];
total: number;
page: number;
per_page: number;
};
/** GET /api/v1/admin/wallet/transactions */
export type AdminWalletTxnItem = {
id: number;
txn_no: string;
player_id: number;
site_code: string | null;
site_player_id: string | null;
username: string | null;
wallet_id: number;
biz_type: string;
biz_no: string;
direction: number;
amount: number;
balance_before: number;
balance_after: number;
status: string;
external_ref_no: string | null;
idempotent_key: string | null;
remark: string | null;
created_at: string | null;
/** 界面「完成时间」展示(表 `updated_at` */
updated_at: string | null;
};
export type AdminWalletTxnListData = {
items: AdminWalletTxnItem[];
total: number;
page: number;
per_page: number;
};
/** GET /api/v1/admin/players/{player}/wallets */
export type AdminPlayerWalletRow = {
id: number;
wallet_type: string;
currency_code: string;
balance: number;
frozen_balance: number;
available_balance: number;
status: number;
version: number;
};
export type AdminPlayerWalletsData = {
player: {
id: number;
site_code: string;
site_player_id: string;
username: string | null;
nickname: string | null;
default_currency: string;
status: number;
};
wallets: AdminPlayerWalletRow[];
};

View File

@@ -5,3 +5,11 @@ export type {
AdminProfile,
} from "./admin-auth";
export type { AdminPingResponse } from "./admin-ping";
export type {
AdminPlayerWalletsData,
AdminPlayerWalletRow,
AdminTransferOrderItem,
AdminTransferOrderListData,
AdminWalletTxnItem,
AdminWalletTxnListData,
} from "./admin-wallet";