feat: 更新管理员导航,添加结算和奖池模块,并优化活动匹配逻辑

This commit is contained in:
2026-05-11 15:35:41 +08:00
parent 0103d25426
commit f083b28fc6
19 changed files with 1226 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
import type { LucideIcon } from "lucide-react";
import {
CalendarClock,
CircleDollarSign,
Landmark,
LayoutDashboard,
LogIn,
Settings,
@@ -23,6 +25,8 @@ export const adminNavIconBySegment: Record<AdminNavItem["segment"], LucideIcon>
tickets: Ticket,
wallet: Wallet,
risk: ShieldAlert,
settlement: Landmark,
jackpot: CircleDollarSign,
settings: Settings,
};

View File

@@ -16,7 +16,11 @@ export type AdminNavItem = {
| "tickets"
| "wallet"
| "risk"
| "settings";
| "settings"
| "settlement"
| "jackpot";
/** 高亮匹配:默认用 `href`Jackpot 多子页时传公共前缀如 `/admin/jackpot` */
activeMatchPrefix?: string;
};
export const adminShellNavItems: AdminNavItem[] = [
@@ -27,5 +31,12 @@ export const adminShellNavItems: AdminNavItem[] = [
{ segment: "tickets", label: "注单 / 票务", href: "/admin/tickets" },
{ segment: "wallet", label: "钱包", href: "/admin/wallet" },
{ segment: "risk", label: "风控", href: "/admin/risk" },
{ segment: "settlement", label: "结算", href: "/admin/settlement-batches" },
{
segment: "jackpot",
label: "Jackpot",
href: "/admin/jackpot/pools",
activeMatchPrefix: "/admin/jackpot",
},
{ segment: "settings", label: "系统设置", href: "/admin/settings" },
];

View File

@@ -0,0 +1,209 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { getAdminJackpotPools, putAdminJackpotPool } from "@/api/admin-jackpot";
import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { formatAdminMinorUnits } from "@/lib/money";
import { toast } from "sonner";
import { LotteryApiBizError } from "@/types/api/errors";
import type { AdminJackpotPoolRow } from "@/types/api/admin-jackpot";
type Draft = {
current_amount: string;
contribution_rate: string;
trigger_threshold: string;
payout_rate: string;
force_trigger_draw_gap: string;
min_bet_amount: string;
status: string;
};
function toDraft(p: AdminJackpotPoolRow): Draft {
return {
current_amount: String(p.current_amount),
contribution_rate: String(p.contribution_rate),
trigger_threshold: String(p.trigger_threshold),
payout_rate: String(p.payout_rate),
force_trigger_draw_gap: String(p.force_trigger_draw_gap),
min_bet_amount: String(p.min_bet_amount),
status: String(p.status),
};
}
export function JackpotPoolsConsole() {
const [items, setItems] = useState<AdminJackpotPoolRow[]>([]);
const [drafts, setDrafts] = useState<Record<number, Draft>>({});
const [loading, setLoading] = useState(true);
const [savingId, setSavingId] = useState<number | null>(null);
const load = useCallback(async () => {
setLoading(true);
try {
const res = await getAdminJackpotPools();
setItems(res.items);
const d: Record<number, Draft> = {};
for (const p of res.items) {
d[p.id] = toDraft(p);
}
setDrafts(d);
} catch (e) {
toast.error(e instanceof LotteryApiBizError ? e.message : "加载失败");
} finally {
setLoading(false);
}
}, []);
useEffect(() => {
queueMicrotask(() => {
void load();
});
}, [load]);
const updateDraft = (id: number, patch: Partial<Draft>) => {
setDrafts((prev) => ({
...prev,
[id]: { ...prev[id], ...patch },
}));
};
const save = async (p: AdminJackpotPoolRow) => {
const d = drafts[p.id];
if (!d) return;
setSavingId(p.id);
try {
await putAdminJackpotPool(p.id, {
current_amount: Number.parseInt(d.current_amount, 10),
contribution_rate: Number(d.contribution_rate),
trigger_threshold: Number.parseInt(d.trigger_threshold, 10),
payout_rate: Number(d.payout_rate),
force_trigger_draw_gap: Number.parseInt(d.force_trigger_draw_gap, 10),
min_bet_amount: Number.parseInt(d.min_bet_amount, 10),
status: Number.parseInt(d.status, 10),
});
toast.success("已保存");
await load();
} catch (e) {
toast.error(e instanceof LotteryApiBizError ? e.message : "保存失败");
} finally {
setSavingId(null);
}
};
return (
<ModuleScaffold>
<Card>
<CardHeader>
<CardTitle className="text-base">Jackpot </CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="space-y-8">
{loading ? <p className="text-muted-foreground text-sm"></p> : null}
{!loading && items.length === 0 ? (
<p className="text-muted-foreground text-sm"></p>
) : null}
{items.map((p) => {
const d = drafts[p.id] ?? toDraft(p);
return (
<div key={p.id} className="space-y-4 rounded-lg border border-border p-4">
<div className="flex flex-wrap items-baseline justify-between gap-2">
<h3 className="font-mono text-sm font-semibold">{p.currency_code}</h3>
<span className="text-xs text-muted-foreground">
{formatAdminMinorUnits(p.current_amount, p.currency_code)}
</span>
</div>
<div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
<div className="space-y-1.5">
<Label htmlFor={`amt-${p.id}`}></Label>
<Input
id={`amt-${p.id}`}
className="font-mono"
value={d.current_amount}
onChange={(e) => updateDraft(p.id, { current_amount: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`cr-${p.id}`}> 01</Label>
<Input
id={`cr-${p.id}`}
className="font-mono"
value={d.contribution_rate}
onChange={(e) => updateDraft(p.id, { contribution_rate: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`th-${p.id}`}></Label>
<Input
id={`th-${p.id}`}
className="font-mono"
value={d.trigger_threshold}
onChange={(e) => updateDraft(p.id, { trigger_threshold: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`pr-${p.id}`}> 01</Label>
<Input
id={`pr-${p.id}`}
className="font-mono"
value={d.payout_rate}
onChange={(e) => updateDraft(p.id, { payout_rate: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`gap-${p.id}`}></Label>
<Input
id={`gap-${p.id}`}
className="font-mono"
value={d.force_trigger_draw_gap}
onChange={(e) => updateDraft(p.id, { force_trigger_draw_gap: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor={`min-${p.id}`}></Label>
<Input
id={`min-${p.id}`}
className="font-mono"
value={d.min_bet_amount}
onChange={(e) => updateDraft(p.id, { min_bet_amount: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label></Label>
<Select
value={d.status}
onValueChange={(v) => updateDraft(p.id, { status: v ?? "0" })}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="0"></SelectItem>
<SelectItem value="1"></SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="flex justify-end">
<Button type="button" disabled={savingId === p.id} onClick={() => void save(p)}>
{savingId === p.id ? "保存中…" : "保存"}
</Button>
</div>
</div>
);
})}
</CardContent>
</Card>
</ModuleScaffold>
);
}

View File

@@ -0,0 +1,236 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { getAdminJackpotContributions, getAdminJackpotPayoutLogs } from "@/api/admin-jackpot";
import { AdminListPaginationFooter } from "@/components/admin/admin-list-pagination-footer";
import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
import { formatAdminMinorUnits } from "@/lib/money";
import { LotteryApiBizError } from "@/types/api/errors";
import type {
AdminJackpotContributionsData,
AdminJackpotPayoutLogsData,
} from "@/types/api/admin-jackpot";
export function JackpotRecordsConsole() {
const formatDt = useAdminDateTimeFormatter();
const [drawNo, setDrawNo] = useState("");
const [appliedDrawNo, setAppliedDrawNo] = useState("");
const [payouts, setPayouts] = useState<AdminJackpotPayoutLogsData | null>(null);
const [pPage, setPPage] = useState(1);
const [pPer, setPPer] = useState(15);
const [contribs, setContribs] = useState<AdminJackpotContributionsData | null>(null);
const [cPage, setCPage] = useState(1);
const [cPer, setCPer] = useState(15);
const [loadingP, setLoadingP] = useState(true);
const [loadingC, setLoadingC] = useState(true);
const [err, setErr] = useState<string | null>(null);
const loadPayouts = useCallback(async () => {
setLoadingP(true);
try {
const d = await getAdminJackpotPayoutLogs({
page: pPage,
per_page: pPer,
draw_no: appliedDrawNo.trim() || undefined,
});
setPayouts(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "派彩记录加载失败");
} finally {
setLoadingP(false);
}
}, [pPage, pPer, appliedDrawNo]);
const loadContribs = useCallback(async () => {
setLoadingC(true);
try {
const d = await getAdminJackpotContributions({
page: cPage,
per_page: cPer,
draw_no: appliedDrawNo.trim() || undefined,
});
setContribs(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "蓄水记录加载失败");
} finally {
setLoadingC(false);
}
}, [cPage, cPer, appliedDrawNo]);
useEffect(() => {
queueMicrotask(() => {
void loadPayouts();
});
}, [loadPayouts]);
useEffect(() => {
queueMicrotask(() => {
void loadContribs();
});
}, [loadContribs]);
const applyDraw = () => {
setAppliedDrawNo(drawNo);
setPPage(1);
setCPage(1);
};
return (
<ModuleScaffold>
<Card className="mb-6">
<CardHeader className="pb-3">
<CardTitle className="text-base"></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-3 sm:flex-row sm:items-end">
<div className="flex max-w-xs flex-1 flex-col gap-1.5">
<Label htmlFor="jk-draw"></Label>
<Input
id="jk-draw"
className="font-mono"
value={drawNo}
onChange={(e) => setDrawNo(e.target.value)}
placeholder="可选"
/>
</div>
<Button type="button" onClick={applyDraw}>
</Button>
</CardContent>
</Card>
{err ? <p className="text-destructive mb-4 text-sm">{err}</p> : null}
<Card className="mb-8">
<CardHeader>
<CardTitle className="text-base">Jackpot </CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
{loadingP && !payouts ? (
<p className="text-muted-foreground text-sm"></p>
) : (
<Table>
<TableHeader>
<TableRow>
<TableHead>ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{(payouts?.items ?? []).map((r) => (
<TableRow key={r.id}>
<TableCell className="font-mono text-xs">{r.id}</TableCell>
<TableCell className="font-mono text-xs">{r.draw_no ?? "—"}</TableCell>
<TableCell className="text-xs">{r.trigger_type}</TableCell>
<TableCell className="text-right font-mono text-xs tabular-nums">
{formatAdminMinorUnits(r.total_payout_amount, r.currency_code ?? "NPR")}
</TableCell>
<TableCell className="text-right tabular-nums">{r.winner_count}</TableCell>
<TableCell className="text-xs text-muted-foreground whitespace-nowrap">
{formatDt(r.created_at)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
{payouts ? (
<AdminListPaginationFooter
selectId="jk-payout-per"
total={payouts.meta.total}
page={payouts.meta.current_page}
lastPage={payouts.meta.last_page}
perPage={payouts.meta.per_page}
loading={loadingP}
onPerPageChange={(n) => {
setPPer(n);
setPPage(1);
}}
onPageChange={setPPage}
/>
) : null}
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle className="text-base">Jackpot </CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
{loadingC && !contribs ? (
<p className="text-muted-foreground text-sm"></p>
) : (
<Table>
<TableHeader>
<TableRow>
<TableHead>ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{(contribs?.items ?? []).map((r) => (
<TableRow key={r.id}>
<TableCell className="font-mono text-xs">{r.id}</TableCell>
<TableCell className="font-mono text-xs">{r.draw_no ?? "—"}</TableCell>
<TableCell className="font-mono text-xs">{r.ticket_no ?? "—"}</TableCell>
<TableCell className="max-w-[10rem] truncate text-xs">
{r.player_username ?? "—"}
</TableCell>
<TableCell className="text-right font-mono text-xs tabular-nums">
{formatAdminMinorUnits(r.contribution_amount, r.currency_code ?? "NPR")}
</TableCell>
<TableCell className="text-xs text-muted-foreground whitespace-nowrap">
{formatDt(r.created_at)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
{contribs ? (
<AdminListPaginationFooter
selectId="jk-contrib-per"
total={contribs.meta.total}
page={contribs.meta.current_page}
lastPage={contribs.meta.last_page}
perPage={contribs.meta.per_page}
loading={loadingC}
onPerPageChange={(n) => {
setCPer(n);
setCPage(1);
}}
onPageChange={setCPage}
/>
) : null}
</CardContent>
</Card>
</ModuleScaffold>
);
}

View File

@@ -0,0 +1,37 @@
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { cn } from "@/lib/utils";
const LINKS: { href: string; label: string }[] = [
{ href: "/admin/jackpot/pools", label: "奖池配置" },
{ href: "/admin/jackpot/records", label: "记录" },
];
export function JackpotSubNav() {
const pathname = usePathname();
return (
<nav className="mb-6 flex flex-wrap gap-2 border-b border-border pb-3" aria-label="Jackpot 子导航">
{LINKS.map(({ href, label }) => {
const active = pathname === href || pathname.startsWith(`${href}/`);
return (
<Link
key={href}
href={href}
className={cn(
"rounded-md px-3 py-1.5 text-sm transition-colors",
active
? "bg-primary text-primary-foreground"
: "bg-muted/60 text-muted-foreground hover:bg-muted hover:text-foreground",
)}
>
{label}
</Link>
);
})}
</nav>
);
}

View File

@@ -0,0 +1,4 @@
export const jackpotModuleMeta = {
title: "Jackpot",
description: "奖池配置与蓄水 / 派彩记录",
} as const;

View File

@@ -0,0 +1,4 @@
export const settlementModuleMeta = {
title: "结算批次",
description: "按期查看结算批次与注单结算明细",
} as const;

View File

@@ -0,0 +1,190 @@
"use client";
import Link from "next/link";
import { useCallback, useEffect, useState } from "react";
import { getAdminSettlementBatch, getAdminSettlementBatchDetails } from "@/api/admin-settlement";
import { AdminListPaginationFooter } from "@/components/admin/admin-list-pagination-footer";
import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { Button, buttonVariants } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
import { formatAdminMinorUnits } from "@/lib/money";
import { cn } from "@/lib/utils";
import { LotteryApiBizError } from "@/types/api/errors";
import type {
AdminSettlementBatchDetailsData,
AdminSettlementBatchShowData,
} from "@/types/api/admin-settlement";
type Props = {
batchId: number;
};
export function SettlementBatchDetailsConsole({ batchId }: Props) {
const formatDt = useAdminDateTimeFormatter();
const [summary, setSummary] = useState<AdminSettlementBatchShowData | null>(null);
const [details, setDetails] = useState<AdminSettlementBatchDetailsData | null>(null);
const [loading, setLoading] = useState(true);
const [err, setErr] = useState<string | null>(null);
const [page, setPage] = useState(1);
const [perPage, setPerPage] = useState(25);
const load = useCallback(async () => {
setLoading(true);
setErr(null);
try {
const [s, d] = await Promise.all([
getAdminSettlementBatch(batchId),
getAdminSettlementBatchDetails(batchId, { page, per_page: perPage }),
]);
setSummary(s);
setDetails(d);
} catch (e) {
setErr(e instanceof LotteryApiBizError ? e.message : "加载失败");
setSummary(null);
setDetails(null);
} finally {
setLoading(false);
}
}, [batchId, page, perPage]);
useEffect(() => {
const t = window.setTimeout(() => void load(), 0);
return () => window.clearTimeout(t);
}, [load]);
return (
<ModuleScaffold>
<div className="mb-4">
<Link href="/admin/settlement-batches" className={cn(buttonVariants({ variant: "ghost", size: "sm" }), "px-0")}>
</Link>
</div>
{err ? (
<Card className="border-destructive/40">
<CardHeader>
<CardTitle className="text-base"></CardTitle>
<CardDescription>{err}</CardDescription>
</CardHeader>
<CardContent>
<Button type="button" size="sm" variant="secondary" onClick={() => void load()}>
</Button>
</CardContent>
</Card>
) : null}
{summary ? (
<Card className="mb-6">
<CardHeader>
<CardTitle className="font-mono text-base"> #{summary.id}</CardTitle>
<CardDescription>
{summary.draw_no ?? "—"} · {summary.draw_status ?? "—"} · v
{summary.result_batch_version ?? "—"}
</CardDescription>
</CardHeader>
<CardContent className="grid gap-2 text-sm sm:grid-cols-2">
<p>
<span className="text-muted-foreground"></span>{" "}
<span className="font-mono">{summary.status}</span>
</p>
<p>
<span className="text-muted-foreground"></span>{" "}
<span className="tabular-nums">{summary.total_ticket_count}</span>
</p>
<p>
<span className="text-muted-foreground"></span>{" "}
<span className="tabular-nums">{summary.total_win_count}</span>
</p>
<p>
<span className="text-muted-foreground"></span>{" "}
<span className="font-mono tabular-nums">{formatAdminMinorUnits(summary.total_payout_amount)}</span>
</p>
<p>
<span className="text-muted-foreground">Jackpot </span>{" "}
<span className="font-mono tabular-nums">
{formatAdminMinorUnits(summary.total_jackpot_payout_amount)}
</span>
</p>
<p>
<span className="text-muted-foreground"></span> {formatDt(summary.started_at)}
</p>
<p>
<span className="text-muted-foreground"></span> {formatDt(summary.finished_at)}
</p>
</CardContent>
</Card>
) : loading ? (
<p className="text-muted-foreground text-sm"></p>
) : null}
<Card>
<CardHeader>
<CardTitle className="text-base"></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
{details ? (
<>
<Table>
<TableHeader>
<TableRow>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right">Jackpot</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{details.items.map((r) => (
<TableRow key={r.id}>
<TableCell className="font-mono text-xs">{r.ticket_no ?? "—"}</TableCell>
<TableCell className="font-mono text-xs">{r.play_code ?? "—"}</TableCell>
<TableCell className="max-w-[10rem] truncate text-xs">
{r.player_username ?? r.site_player_id ?? r.player_id ?? "—"}
</TableCell>
<TableCell className="text-xs">{r.matched_prize_tier ?? "—"}</TableCell>
<TableCell className="text-right font-mono text-xs tabular-nums">
{formatAdminMinorUnits(r.win_amount)}
</TableCell>
<TableCell className="text-right font-mono text-xs tabular-nums">
{formatAdminMinorUnits(r.jackpot_allocation_amount)}
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<AdminListPaginationFooter
selectId="settlement-details-per-page"
total={details.meta.total}
page={details.meta.current_page}
lastPage={details.meta.last_page}
perPage={details.meta.per_page}
loading={loading}
onPerPageChange={(n) => {
setPerPage(n);
setPage(1);
}}
onPageChange={setPage}
/>
</>
) : (
<p className="text-muted-foreground text-sm">{loading ? "加载明细…" : "无数据"}</p>
)}
</CardContent>
</Card>
</ModuleScaffold>
);
}

View File

@@ -0,0 +1,218 @@
"use client";
import Link from "next/link";
import { useCallback, useEffect, useState } from "react";
import { getAdminSettlementBatches } from "@/api/admin-settlement";
import { AdminListPaginationFooter } from "@/components/admin/admin-list-pagination-footer";
import { ModuleScaffold } from "@/components/admin/module-scaffold";
import { Button, buttonVariants } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { useAdminDateTimeFormatter } from "@/hooks/use-admin-datetime-formatter";
import { formatAdminMinorUnits } from "@/lib/money";
import { cn } from "@/lib/utils";
import { LotteryApiBizError } from "@/types/api/errors";
import type { AdminSettlementBatchListData, AdminSettlementBatchRow } from "@/types/api/admin-settlement";
import { settlementModuleMeta } from "@/modules/settlement/meta";
const STATUS_ALL = "__all__";
const STATUS_OPTIONS: { value: string; label: string }[] = [
{ value: STATUS_ALL, label: "不限" },
{ value: "running", label: "进行中" },
{ value: "completed", label: "已完成" },
{ value: "failed", label: "失败" },
];
export function SettlementBatchesConsole() {
const formatDt = useAdminDateTimeFormatter();
const [data, setData] = useState<AdminSettlementBatchListData | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const [draftDrawNo, setDraftDrawNo] = useState("");
const [appliedDrawNo, setAppliedDrawNo] = useState("");
const [draftStatus, setDraftStatus] = useState(STATUS_ALL);
const [appliedStatus, setAppliedStatus] = useState(STATUS_ALL);
const [page, setPage] = useState(1);
const [perPage, setPerPage] = useState(20);
const load = useCallback(async () => {
setLoading(true);
setError(null);
try {
const d = await getAdminSettlementBatches({
page,
per_page: perPage,
draw_no: appliedDrawNo.trim() || undefined,
status:
appliedStatus === STATUS_ALL || appliedStatus.trim() === ""
? undefined
: appliedStatus.trim(),
});
setData(d);
} catch (e) {
setError(e instanceof LotteryApiBizError ? e.message : "加载失败");
setData(null);
} finally {
setLoading(false);
}
}, [page, perPage, appliedDrawNo, appliedStatus]);
useEffect(() => {
const t = window.setTimeout(() => void load(), 0);
return () => window.clearTimeout(t);
}, [load]);
const applyFilters = () => {
setAppliedDrawNo(draftDrawNo);
setAppliedStatus(draftStatus);
setPage(1);
};
return (
<ModuleScaffold>
<div className="mb-6">
<h1 className="text-lg font-semibold tracking-tight">{settlementModuleMeta.title}</h1>
<p className="text-muted-foreground mt-1 text-sm">{settlementModuleMeta.description}</p>
</div>
<Card className="mb-6">
<CardHeader className="pb-3">
<CardTitle className="text-base"></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-4 sm:flex-row sm:flex-wrap sm:items-end">
<div className="flex min-w-[12rem] flex-1 flex-col gap-1.5">
<Label htmlFor="sb-draw-no"></Label>
<Input
id="sb-draw-no"
value={draftDrawNo}
onChange={(e) => setDraftDrawNo(e.target.value)}
placeholder="如 20260511-001"
className="font-mono"
/>
</div>
<div className="flex min-w-[10rem] flex-col gap-1.5">
<Label></Label>
<Select value={draftStatus} onValueChange={(v) => setDraftStatus(v ?? STATUS_ALL)}>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{STATUS_OPTIONS.map((o) => (
<SelectItem key={o.value} value={o.value}>
{o.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<Button type="button" onClick={applyFilters}>
</Button>
</CardContent>
</Card>
<Card>
<CardHeader>
<CardTitle className="text-base"></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
{error ? <p className="text-destructive text-sm">{error}</p> : null}
{loading && !data ? (
<p className="text-muted-foreground text-sm"></p>
) : (
<Table>
<TableHeader>
<TableRow>
<TableHead>ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right"></TableHead>
<TableHead className="text-right">Jackpot</TableHead>
<TableHead></TableHead>
<TableHead />
</TableRow>
</TableHeader>
<TableBody>
{(data?.items ?? []).map((row: AdminSettlementBatchRow) => (
<TableRow key={row.id}>
<TableCell className="font-mono text-xs">{row.id}</TableCell>
<TableCell className="font-mono text-sm">{row.draw_no ?? "—"}</TableCell>
<TableCell className="font-mono text-xs">v{row.settle_version}</TableCell>
<TableCell>
<span
className={cn(
"rounded px-1.5 py-0.5 text-xs font-medium",
row.status === "completed" && "bg-emerald-500/15 text-emerald-800",
row.status === "running" && "bg-amber-500/15 text-amber-900",
row.status === "failed" && "bg-destructive/15 text-destructive",
)}
>
{row.status}
</span>
</TableCell>
<TableCell className="text-right tabular-nums">{row.total_ticket_count}</TableCell>
<TableCell className="text-right tabular-nums">{row.total_win_count}</TableCell>
<TableCell className="text-right font-mono text-xs tabular-nums">
{formatAdminMinorUnits(row.total_payout_amount)}
</TableCell>
<TableCell className="text-right font-mono text-xs tabular-nums">
{formatAdminMinorUnits(row.total_jackpot_payout_amount)}
</TableCell>
<TableCell className="text-xs text-muted-foreground whitespace-nowrap">
{formatDt(row.finished_at ?? row.started_at)}
</TableCell>
<TableCell>
<Link
href={`/admin/settlement-batches/${row.id}/details`}
className={cn(buttonVariants({ variant: "link", size: "sm" }), "px-0")}
>
</Link>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
)}
{data ? (
<AdminListPaginationFooter
selectId="settlement-batches-per-page"
total={data.meta.total}
page={data.meta.current_page}
lastPage={data.meta.last_page}
perPage={data.meta.per_page}
loading={loading}
onPerPageChange={(n) => {
setPerPage(n);
setPage(1);
}}
onPageChange={setPage}
/>
) : null}
</CardContent>
</Card>
</ModuleScaffold>
);
}