update calculate user balance in admin section
This commit is contained in:
parent
dd18e74529
commit
fcd89bc345
@ -123,14 +123,11 @@ export default class AdminUserHandler {
|
|||||||
|
|
||||||
// Calculate balances for each user
|
// Calculate balances for each user
|
||||||
const usersWithBalances = await Promise.all(users.map(async (user) => {
|
const usersWithBalances = await Promise.all(users.map(async (user) => {
|
||||||
const activeWalletsBalance = await WalletService.getActiveWalletsBalance(user.id);
|
// Доступный баланс (bonus_balance + total_balance)
|
||||||
const archivedWalletsBalance = await WalletService.getArchivedWalletsBalance(user.id);
|
const availableBalance = user.bonus_balance + (user.total_balance || 0);
|
||||||
const totalBalance = (user.total_balance || 0) + (user.bonus_balance || 0) + activeWalletsBalance + archivedWalletsBalance;
|
|
||||||
return {
|
return {
|
||||||
...user,
|
...user,
|
||||||
activeWalletsBalance,
|
availableBalance
|
||||||
archivedWalletsBalance,
|
|
||||||
totalBalance
|
|
||||||
};
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -140,7 +137,7 @@ export default class AdminUserHandler {
|
|||||||
// Create inline keyboard with user list
|
// Create inline keyboard with user list
|
||||||
const keyboard = {
|
const keyboard = {
|
||||||
inline_keyboard: usersWithBalances.map(user => [{
|
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}`
|
callback_data: `view_user_${user.telegram_id}`
|
||||||
}])
|
}])
|
||||||
};
|
};
|
||||||
@ -236,12 +233,8 @@ export default class AdminUserHandler {
|
|||||||
ORDER BY p.purchase_date DESC
|
ORDER BY p.purchase_date DESC
|
||||||
`, [telegramId]);
|
`, [telegramId]);
|
||||||
|
|
||||||
// Get wallet balances
|
// Доступный баланс (bonus_balance + total_balance)
|
||||||
const activeWalletsBalance = await WalletService.getActiveWalletsBalance(user.id);
|
const availableBalance = user.bonus_balance + (user.total_balance || 0);
|
||||||
const archivedWalletsBalance = await WalletService.getArchivedWalletsBalance(user.id);
|
|
||||||
|
|
||||||
// Общий баланс (крипто + бонусы + total_balance)
|
|
||||||
const totalBalance = activeWalletsBalance + archivedWalletsBalance + user.bonus_balance + (user.total_balance || 0);
|
|
||||||
|
|
||||||
const message = `
|
const message = `
|
||||||
👤 User Profile:
|
👤 User Profile:
|
||||||
@ -252,10 +245,8 @@ export default class AdminUserHandler {
|
|||||||
📊 Activity:
|
📊 Activity:
|
||||||
- Total Purchases: ${detailedUser.purchase_count}
|
- Total Purchases: ${detailedUser.purchase_count}
|
||||||
- Total Spent: $${detailedUser.total_spent || 0}
|
- 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}
|
- Bonus Balance: $${user.bonus_balance || 0}
|
||||||
- Total Balance: $${totalBalance.toFixed(2)}
|
- Available Balance: $${availableBalance.toFixed(2)}
|
||||||
|
|
||||||
💰 Recent Transactions (Last 5 of ${transactions.length}):
|
💰 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')}
|
${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')}
|
||||||
|
Loading…
Reference in New Issue
Block a user