update calculate user balance in admin section

This commit is contained in:
NW 2025-01-09 20:13:45 +00:00
parent dd18e74529
commit fcd89bc345

View File

@ -123,14 +123,11 @@ export default class AdminUserHandler {
// Calculate balances for each user
const usersWithBalances = await Promise.all(users.map(async (user) => {
const activeWalletsBalance = await WalletService.getActiveWalletsBalance(user.id);
const archivedWalletsBalance = await WalletService.getArchivedWalletsBalance(user.id);
const totalBalance = (user.total_balance || 0) + (user.bonus_balance || 0) + activeWalletsBalance + archivedWalletsBalance;
// Доступный баланс (bonus_balance + total_balance)
const availableBalance = user.bonus_balance + (user.total_balance || 0);
return {
...user,
activeWalletsBalance,
archivedWalletsBalance,
totalBalance
availableBalance
};
}));
@ -140,7 +137,7 @@ export default class AdminUserHandler {
// Create inline keyboard with user list
const keyboard = {
inline_keyboard: usersWithBalances.map(user => [{
text: `ID: ${user.telegram_id} | Nickname: ${user.username ? "@" + user.username : "None"} | Balance: $${user.totalBalance.toFixed(2)}`,
text: `ID: ${user.telegram_id} | Nickname: ${user.username ? "@" + user.username : "None"} | Balance: $${user.availableBalance.toFixed(2)}`,
callback_data: `view_user_${user.telegram_id}`
}])
};
@ -236,12 +233,8 @@ export default class AdminUserHandler {
ORDER BY p.purchase_date DESC
`, [telegramId]);
// Get wallet balances
const activeWalletsBalance = await WalletService.getActiveWalletsBalance(user.id);
const archivedWalletsBalance = await WalletService.getArchivedWalletsBalance(user.id);
// Общий баланс (крипто + бонусы + total_balance)
const totalBalance = activeWalletsBalance + archivedWalletsBalance + user.bonus_balance + (user.total_balance || 0);
// Доступный баланс (bonus_balance + total_balance)
const availableBalance = user.bonus_balance + (user.total_balance || 0);
const message = `
👤 User Profile:
@ -252,10 +245,8 @@ export default class AdminUserHandler {
📊 Activity:
- Total Purchases: ${detailedUser.purchase_count}
- Total Spent: $${detailedUser.total_spent || 0}
- Active Wallets: ${detailedUser.crypto_wallet_count} ($${activeWalletsBalance.toFixed(2)})
- Archived Wallets: ${detailedUser.archived_wallet_count} ($${archivedWalletsBalance.toFixed(2)})
- Bonus Balance: $${user.bonus_balance || 0}
- Total Balance: $${totalBalance.toFixed(2)}
- Available Balance: $${availableBalance.toFixed(2)}
💰 Recent Transactions (Last 5 of ${transactions.length}):
${transactions.map(t => `$${t.amount} ${t.wallet_type} (${t.tx_hash}) at ${new Date(t.created_at).toLocaleString('en-US', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })}`).join('\n')}