From fcd89bc345c43bc20a82e6c25f39c34250a1414b Mon Sep 17 00:00:00 2001 From: NW Date: Thu, 9 Jan 2025 20:13:45 +0000 Subject: [PATCH] update calculate user balance in admin section --- .../adminHandlers/adminUserHandler.js | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/handlers/adminHandlers/adminUserHandler.js b/src/handlers/adminHandlers/adminUserHandler.js index f6f7bcd..daa0fda 100644 --- a/src/handlers/adminHandlers/adminUserHandler.js +++ b/src/handlers/adminHandlers/adminUserHandler.js @@ -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')}