feat(admin-web): P2P划转记录管理页面 + 手续费汇总
## 后端 — mining-admin-service - users.controller: 新增 GET /users/p2p-transfers 端点(搜索+分页) - 放在 :accountSequence 路由之前避免被 catch-all 拦截 - users.service: 新增 getP2pTransfers() 代理方法 - 调用 trading-service 的 /api/v2/p2p/internal/all-transfers - 返回划转记录列表 + 汇总统计 + 分页信息 ## 前端 — mining-admin-web - 新增 /p2p-transfers 页面: - 三个汇总卡片:累计手续费收入、累计划转金额、成功划转笔数 - 搜索框支持账号、手机号、转账单号搜索 - 记录表格:转账单号、发送方、接收方、转账金额、手续费、备注、时间 - 分页控件 - sidebar: 新增"P2P划转"导航项(位于"交易管理"下方) - users.api: 新增 getP2pTransfers API + P2pTransferRecord 类型 - use-users: 新增 useP2pTransfers hook Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
9f94344e8b
commit
9adef67bb8
|
|
@ -40,6 +40,23 @@ export class UsersController {
|
|||
});
|
||||
}
|
||||
|
||||
@Get('p2p-transfers')
|
||||
@ApiOperation({ summary: '获取全部P2P转账记录(含手续费汇总)' })
|
||||
@ApiQuery({ name: 'page', required: false, type: Number })
|
||||
@ApiQuery({ name: 'pageSize', required: false, type: Number })
|
||||
@ApiQuery({ name: 'search', required: false, type: String, description: '搜索账号/手机号/转账单号' })
|
||||
async getP2pTransfers(
|
||||
@Query('page') page?: number,
|
||||
@Query('pageSize') pageSize?: number,
|
||||
@Query('search') search?: string,
|
||||
) {
|
||||
return this.usersService.getP2pTransfers(
|
||||
page ?? 1,
|
||||
pageSize ?? 20,
|
||||
search,
|
||||
);
|
||||
}
|
||||
|
||||
@Get(':accountSequence')
|
||||
@ApiOperation({ summary: '获取用户详情' })
|
||||
@ApiParam({ name: 'accountSequence', type: String })
|
||||
|
|
|
|||
|
|
@ -23,12 +23,14 @@ export interface GetOrdersQuery {
|
|||
export class UsersService {
|
||||
private readonly logger = new Logger(UsersService.name);
|
||||
private readonly miningServiceUrl: string;
|
||||
private readonly tradingServiceUrl: string;
|
||||
|
||||
constructor(
|
||||
private readonly prisma: PrismaService,
|
||||
private readonly configService: ConfigService,
|
||||
) {
|
||||
this.miningServiceUrl = this.configService.get<string>('MINING_SERVICE_URL', 'http://localhost:3021');
|
||||
this.tradingServiceUrl = this.configService.get<string>('TRADING_SERVICE_URL', 'http://localhost:3022');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1276,4 +1278,38 @@ export class UsersService {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部P2P转账记录(代理 trading-service)
|
||||
*/
|
||||
async getP2pTransfers(page: number, pageSize: number, search?: string) {
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
page: page.toString(),
|
||||
pageSize: pageSize.toString(),
|
||||
});
|
||||
if (search) params.set('search', search);
|
||||
|
||||
const url = `${this.tradingServiceUrl}/api/v2/p2p/internal/all-transfers?${params}`;
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
this.logger.warn(`Failed to fetch P2P transfers: ${response.status}`);
|
||||
return { data: [], total: 0, summary: { totalFee: '0', totalAmount: '0', totalCount: 0 }, pagination: { page, pageSize, total: 0, totalPages: 0 } };
|
||||
}
|
||||
const result = await response.json();
|
||||
const body = result.data || result;
|
||||
return {
|
||||
...body,
|
||||
pagination: {
|
||||
page,
|
||||
pageSize,
|
||||
total: body.total,
|
||||
totalPages: Math.ceil(body.total / pageSize),
|
||||
},
|
||||
};
|
||||
} catch (error: any) {
|
||||
this.logger.warn(`Failed to fetch P2P transfers: ${error.message}`);
|
||||
return { data: [], total: 0, summary: { totalFee: '0', totalAmount: '0', totalCount: 0 }, pagination: { page, pageSize, total: 0, totalPages: 0 } };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,186 @@
|
|||
'use client';
|
||||
|
||||
import { useState } from 'react';
|
||||
import { PageHeader } from '@/components/layout/page-header';
|
||||
import { useP2pTransfers } from '@/features/users/hooks/use-users';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { ChevronLeft, ChevronRight, Search, ArrowRightLeft, Coins, Hash } from 'lucide-react';
|
||||
import { formatDecimal } from '@/lib/utils/format';
|
||||
import { formatDateTime } from '@/lib/utils/date';
|
||||
|
||||
export default function P2pTransfersPage() {
|
||||
const [page, setPage] = useState(1);
|
||||
const [search, setSearch] = useState('');
|
||||
const [searchInput, setSearchInput] = useState('');
|
||||
const pageSize = 20;
|
||||
|
||||
const { data, isLoading } = useP2pTransfers({ page, pageSize, search: search || undefined });
|
||||
|
||||
const handleSearch = () => {
|
||||
setSearch(searchInput);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<PageHeader title="P2P划转记录" description="查看所有用户间积分值划转记录及手续费汇总" />
|
||||
|
||||
{/* 汇总统计 */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-4">
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">累计手续费收入</CardTitle>
|
||||
<Coins className="h-4 w-4 text-muted-foreground" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<Skeleton className="h-8 w-32" />
|
||||
) : (
|
||||
<div className="text-2xl font-bold text-green-600">
|
||||
{formatDecimal(data?.summary.totalFee || '0', 2)}
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground mt-1">积分值</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">累计划转金额</CardTitle>
|
||||
<ArrowRightLeft className="h-4 w-4 text-muted-foreground" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<Skeleton className="h-8 w-32" />
|
||||
) : (
|
||||
<div className="text-2xl font-bold">
|
||||
{formatDecimal(data?.summary.totalAmount || '0', 2)}
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground mt-1">积分值</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
|
||||
<CardTitle className="text-sm font-medium">成功划转笔数</CardTitle>
|
||||
<Hash className="h-4 w-4 text-muted-foreground" />
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<Skeleton className="h-8 w-32" />
|
||||
) : (
|
||||
<div className="text-2xl font-bold">
|
||||
{data?.summary.totalCount || 0}
|
||||
</div>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground mt-1">笔</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* 搜索 */}
|
||||
<Card>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
placeholder="搜索账号、手机号或转账单号..."
|
||||
value={searchInput}
|
||||
onChange={(e) => setSearchInput(e.target.value)}
|
||||
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
|
||||
className="max-w-md"
|
||||
/>
|
||||
<Button onClick={handleSearch} variant="outline">
|
||||
<Search className="h-4 w-4 mr-2" />
|
||||
搜索
|
||||
</Button>
|
||||
{search && (
|
||||
<Button onClick={() => { setSearch(''); setSearchInput(''); setPage(1); }} variant="ghost">
|
||||
清除
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 记录列表 */}
|
||||
<Card>
|
||||
<CardContent className="p-0">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>转账单号</TableHead>
|
||||
<TableHead>发送方</TableHead>
|
||||
<TableHead>接收方</TableHead>
|
||||
<TableHead className="text-right">转账金额</TableHead>
|
||||
<TableHead className="text-right">手续费</TableHead>
|
||||
<TableHead>备注</TableHead>
|
||||
<TableHead>时间</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{isLoading ? (
|
||||
[...Array(5)].map((_, i) => (
|
||||
<TableRow key={i}>
|
||||
{[...Array(7)].map((_, j) => (
|
||||
<TableCell key={j}>
|
||||
<Skeleton className="h-4 w-full" />
|
||||
</TableCell>
|
||||
))}
|
||||
</TableRow>
|
||||
))
|
||||
) : !data?.items.length ? (
|
||||
<TableRow>
|
||||
<TableCell colSpan={7} className="text-center py-8 text-muted-foreground">
|
||||
暂无划转记录
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
) : (
|
||||
data.items.map((record) => (
|
||||
<TableRow key={record.transferNo}>
|
||||
<TableCell className="font-mono text-xs">{record.transferNo}</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium text-sm">{record.fromNickname || record.fromPhone || '-'}</span>
|
||||
<span className="text-xs text-muted-foreground font-mono">{record.fromAccountSequence}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<div className="flex flex-col">
|
||||
<span className="font-medium text-sm">{record.toNickname || record.toPhone}</span>
|
||||
<span className="text-xs text-muted-foreground font-mono">{record.toAccountSequence}</span>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell className="text-right font-mono">{formatDecimal(record.amount, 2)}</TableCell>
|
||||
<TableCell className="text-right font-mono text-orange-600">{formatDecimal(record.fee || '0', 2)}</TableCell>
|
||||
<TableCell className="text-sm text-muted-foreground max-w-[120px] truncate">{record.memo || '-'}</TableCell>
|
||||
<TableCell className="text-sm">{formatDateTime(record.createdAt)}</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
{data && data.totalPages > 1 && (
|
||||
<div className="flex items-center justify-between p-4 border-t">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
共 {data.total} 条,第 {page} / {data.totalPages} 页
|
||||
</p>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="outline" size="sm" onClick={() => setPage(page - 1)} disabled={page <= 1}>
|
||||
<ChevronLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button variant="outline" size="sm" onClick={() => setPage(page + 1)} disabled={page >= data.totalPages}>
|
||||
<ChevronRight className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ import {
|
|||
Bot,
|
||||
HandCoins,
|
||||
FileSpreadsheet,
|
||||
SendHorizontal,
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
|
|
@ -24,6 +25,7 @@ const menuItems = [
|
|||
{ name: '仪表盘', href: '/dashboard', icon: LayoutDashboard },
|
||||
{ name: '用户管理', href: '/users', icon: Users },
|
||||
{ name: '交易管理', href: '/trading', icon: ArrowLeftRight },
|
||||
{ name: 'P2P划转', href: '/p2p-transfers', icon: SendHorizontal },
|
||||
{ name: '做市商管理', href: '/market-maker', icon: Bot },
|
||||
{ name: '手工补发', href: '/manual-mining', icon: HandCoins },
|
||||
{ name: '批量补发', href: '/batch-mining', icon: FileSpreadsheet },
|
||||
|
|
|
|||
|
|
@ -187,8 +187,46 @@ export const usersApi = {
|
|||
const response = await apiClient.get(`/users/${accountSequence}/batch-mining-records`, { params });
|
||||
return response.data.data;
|
||||
},
|
||||
|
||||
getP2pTransfers: async (
|
||||
params: PaginationParams & { search?: string }
|
||||
): Promise<{
|
||||
items: P2pTransferRecord[];
|
||||
total: number;
|
||||
totalPages: number;
|
||||
page: number;
|
||||
pageSize: number;
|
||||
summary: { totalFee: string; totalAmount: string; totalCount: number };
|
||||
}> => {
|
||||
const response = await apiClient.get('/users/p2p-transfers', { params });
|
||||
const result = response.data.data;
|
||||
return {
|
||||
items: result.data || [],
|
||||
total: result.pagination?.total || 0,
|
||||
page: result.pagination?.page || 1,
|
||||
pageSize: result.pagination?.pageSize || 20,
|
||||
totalPages: result.pagination?.totalPages || 0,
|
||||
summary: result.summary || { totalFee: '0', totalAmount: '0', totalCount: 0 },
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
// P2P转账记录类型
|
||||
export interface P2pTransferRecord {
|
||||
transferNo: string;
|
||||
fromAccountSequence: string;
|
||||
fromPhone?: string | null;
|
||||
fromNickname?: string | null;
|
||||
toAccountSequence: string;
|
||||
toPhone: string;
|
||||
toNickname?: string | null;
|
||||
amount: string;
|
||||
fee?: string;
|
||||
memo?: string | null;
|
||||
status: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
// 批量补发记录类型
|
||||
export interface BatchMiningRecord {
|
||||
id: string;
|
||||
|
|
|
|||
|
|
@ -77,3 +77,10 @@ export function useBatchMiningRecords(accountSequence: string, params: Paginatio
|
|||
enabled: !!accountSequence,
|
||||
});
|
||||
}
|
||||
|
||||
export function useP2pTransfers(params: PaginationParams & { search?: string }) {
|
||||
return useQuery({
|
||||
queryKey: ['p2p-transfers', params],
|
||||
queryFn: () => usersApi.getP2pTransfers(params),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue