fix(mining-admin): fix wallet ledger API to match frontend expected format

- Return usdtAvailable, usdtFrozen, pendingUsdt, settleableUsdt,
  settledTotalUsdt, expiredTotalUsdt instead of old field names
- Query SyncedUserWallet table for GREEN_POINTS wallet data
- Use miningAccount.availableBalance for pendingUsdt

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-14 05:56:24 -08:00
parent c6c875849a
commit 465e398040
1 changed files with 31 additions and 7 deletions

View File

@ -906,7 +906,7 @@ export class UsersService {
/**
*
* TODO: mining-service
* SyncedUserWallet SyncedMiningAccount
*/
async getWalletLedger(accountSequence: string, page: number, pageSize: number) {
const user = await this.prisma.syncedUser.findUnique({
@ -918,20 +918,44 @@ export class UsersService {
throw new NotFoundException(`用户 ${accountSequence} 不存在`);
}
// 获取用户的各类钱包数据
const wallets = await this.prisma.syncedUserWallet.findMany({
where: { accountSequence },
});
// 按钱包类型分类
const walletByType = new Map(wallets.map(w => [w.walletType, w]));
const greenPointsWallet = walletByType.get('GREEN_POINTS');
const contributionWallet = walletByType.get('CONTRIBUTION');
const tokenWallet = walletByType.get('TOKEN_STORAGE');
const mining = user.miningAccount;
// 构建前端期望的钱包汇总格式
// usdtAvailable = GREEN_POINTS 钱包的可用余额 (绿积分)
// usdtFrozen = GREEN_POINTS 钱包的冻结余额
// pendingUsdt = 待领取收益(挖矿余额)
// settleableUsdt = 可结算收益
// settledTotalUsdt = 已结算收益
// expiredTotalUsdt = 过期收益
const summary = {
usdtAvailable: greenPointsWallet?.balance?.toString() || '0',
usdtFrozen: greenPointsWallet?.frozenBalance?.toString() || '0',
pendingUsdt: mining?.availableBalance?.toString() || '0', // 挖矿可用余额作为待领取
settleableUsdt: '0', // 暂无数据源
settledTotalUsdt: greenPointsWallet?.totalInflow?.toString() || '0', // 总流入作为已结算
expiredTotalUsdt: '0', // 暂无数据源
};
// TODO: 实现钱包流水分页查询
// 目前从 SyncedUserWallet 只能获取汇总数据,流水明细需要额外的表
return {
summary: {
availableBalance: mining?.availableBalance?.toString() || '0',
frozenBalance: mining?.frozenBalance?.toString() || '0',
totalMined: mining?.totalMined?.toString() || '0',
},
summary,
items: [],
total: 0,
page,
pageSize,
totalPages: 0,
note: '钱包流水数据需要从 mining-service 同步',
};
}