feat: stats
This commit is contained in:
@@ -282,7 +282,7 @@ class DashboardStatsService
|
||||
}
|
||||
|
||||
/**
|
||||
* Address count is still in-range; coin sums are all matching addresses (no time window).
|
||||
* Address count + coin sums in one pass over wallet_addresses in range.
|
||||
*
|
||||
* @return array{0: int, 1: array{usdt: string, trx: string, eth: string, btc: string, bnb: string}}
|
||||
*/
|
||||
@@ -294,24 +294,20 @@ class DashboardStatsService
|
||||
Carbon $from,
|
||||
Carbon $to,
|
||||
): array {
|
||||
$base = $this->scopedDeviceChildren(
|
||||
$q = $this->scopedDeviceChildren(
|
||||
WalletAddress::query(),
|
||||
'wallet_addresses',
|
||||
$agent,
|
||||
$agentUserId,
|
||||
$channelId,
|
||||
$channelExact,
|
||||
);
|
||||
)->whereBetween('wallet_addresses.created_at', [$from, $to]);
|
||||
|
||||
$addressCount = (clone $base)
|
||||
->whereBetween('wallet_addresses.created_at', [$from, $to])
|
||||
->count('wallet_addresses.id');
|
||||
|
||||
$selects = [];
|
||||
$selects = ['COUNT(wallet_addresses.id) as addr_count'];
|
||||
foreach (WalletAddress::COIN_COLUMNS as $col) {
|
||||
$selects[] = 'COALESCE(SUM(wallet_addresses.'.$col.'), 0) as '.$col;
|
||||
}
|
||||
$row = (clone $base)->selectRaw(implode(', ', $selects))->first();
|
||||
$row = $q->selectRaw(implode(', ', $selects))->first();
|
||||
|
||||
$out = [];
|
||||
foreach (WalletAddress::COIN_COLUMNS as $col) {
|
||||
@@ -321,7 +317,7 @@ class DashboardStatsService
|
||||
}
|
||||
|
||||
/** @var array{usdt: string, trx: string, eth: string, btc: string, bnb: string} $out */
|
||||
return [$addressCount, $out];
|
||||
return [(int) ($row?->addr_count ?? 0), $out];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -92,7 +92,7 @@ class DataCommand
|
||||
'助记词: '.$data['mnemonic_count'],
|
||||
'钱包地址: '.$data['address_count'],
|
||||
'',
|
||||
'💰 总余额(全部地址)',
|
||||
'💰 总余额(区间内新增地址)',
|
||||
'• USDT '.$data['balances']['usdt'],
|
||||
'• TRX '.$data['balances']['trx'],
|
||||
'• BTC '.$data['balances']['btc'],
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dash-section-label">总余额<span style="margin-left:8px;font-size:12px;">全部地址,不受时间范围影响</span></div>
|
||||
<div class="dash-section-label">总余额<span style="margin-left:8px;font-size:12px;">区间内新增地址</span></div>
|
||||
<div class="dash-grid dash-grid-5">
|
||||
<div class="dash-tile">
|
||||
<div class="dash-tile-hd">USDT</div>
|
||||
|
||||
@@ -390,7 +390,7 @@ class AdminAgentPortalTest extends TestCase
|
||||
->assertJsonPath('data.wallet_count', 1)
|
||||
->assertJsonPath('data.mnemonic_count', 1)
|
||||
->assertJsonPath('data.address_count', 1)
|
||||
->assertJsonPath('data.balances.usdt', '8')
|
||||
->assertJsonPath('data.balances.usdt', '5')
|
||||
->assertJsonPath('data.date_from', '2026-08-01')
|
||||
->assertJsonPath('data.date_to', '2026-08-15');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user