feat: 更新玩家信息和统计功能
- 在多个控制器中更新玩家相关数据的查询,新增 'nickname' 字段以增强玩家信息的完整性。 - 在 AdminDashboardSnapshotBuilder 中引入平台风险统计,提供锁定金额和使用百分比的概览。 - 更新 AdminReportQueryService 以返回更详细的统计数据,包括总投注、总中奖和总派彩金额。 - 增强测试用例以验证新增字段和统计功能的准确性。
This commit is contained in:
@@ -41,6 +41,7 @@ final class AdminDashboardSnapshotBuilder
|
||||
'finance' => null,
|
||||
'draw' => null,
|
||||
'risk' => null,
|
||||
'platform_risk' => null,
|
||||
'result_batch_queue' => null,
|
||||
'abnormal_transfer_total' => null,
|
||||
'warnings' => [],
|
||||
@@ -50,6 +51,14 @@ final class AdminDashboardSnapshotBuilder
|
||||
],
|
||||
];
|
||||
|
||||
if ($canDraw) {
|
||||
$this->fillPlatformOverview($out);
|
||||
}
|
||||
|
||||
if ($canWallet) {
|
||||
$out['abnormal_transfer_total'] = $this->abnormalTransferTotal();
|
||||
}
|
||||
|
||||
if ($hall === null) {
|
||||
return $out;
|
||||
}
|
||||
@@ -72,21 +81,23 @@ final class AdminDashboardSnapshotBuilder
|
||||
];
|
||||
|
||||
if ($canDraw) {
|
||||
$out['today_finance'] = $this->todayFinanceSummary();
|
||||
$out['lifetime_finance'] = $this->reportQuery->platformLifetimeTotals();
|
||||
$out['finance'] = $this->financeSummary($draw);
|
||||
$out['draw'] = $this->drawPanel($draw);
|
||||
$out['risk'] = $this->riskPanel($draw);
|
||||
$out['result_batch_queue'] = $this->resultBatchQueue();
|
||||
}
|
||||
|
||||
if ($canWallet) {
|
||||
$out['abnormal_transfer_total'] = $this->abnormalTransferTotal();
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $out */
|
||||
private function fillPlatformOverview(array &$out): void
|
||||
{
|
||||
$out['today_finance'] = $this->todayFinanceSummary();
|
||||
$out['lifetime_finance'] = $this->reportQuery->platformLifetimeTotals();
|
||||
$out['platform_risk'] = $this->platformRiskSummary();
|
||||
$out['result_batch_queue'] = $this->resultBatchQueue();
|
||||
}
|
||||
|
||||
private function canDrawFinanceAndRisk(AdminUser $admin): bool
|
||||
{
|
||||
return $admin->hasAdminPermission('prd.dashboard.view')
|
||||
@@ -195,7 +206,14 @@ final class AdminDashboardSnapshotBuilder
|
||||
/**
|
||||
* 全站待审核开奖批次(首页「待审核开奖」卡片用,不限于大厅当前期)。
|
||||
*
|
||||
* @return array{pending_review_total: int, pending_draw_count: int, first_pending_draw_id: int|null, first_pending_batch_id: int|null}
|
||||
* @return array{
|
||||
* pending_review_total: int,
|
||||
* pending_draw_count: int,
|
||||
* published_total: int,
|
||||
* batch_total: int,
|
||||
* first_pending_draw_id: int|null,
|
||||
* first_pending_batch_id: int|null
|
||||
* }
|
||||
*/
|
||||
private function resultBatchQueue(): array
|
||||
{
|
||||
@@ -215,11 +233,32 @@ final class AdminDashboardSnapshotBuilder
|
||||
return [
|
||||
'pending_review_total' => $pendingTotal,
|
||||
'pending_draw_count' => $pendingDrawCount,
|
||||
'published_total' => (int) DrawResultBatch::query()
|
||||
->where('status', DrawResultBatchStatus::Published->value)
|
||||
->count(),
|
||||
'batch_total' => (int) DrawResultBatch::query()->count(),
|
||||
'first_pending_draw_id' => $firstPending !== null ? (int) $firstPending->draw_id : null,
|
||||
'first_pending_batch_id' => $firstPending !== null ? (int) $firstPending->id : null,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array{locked_amount: int, cap_amount: int, usage_percent: float} */
|
||||
private function platformRiskSummary(): array
|
||||
{
|
||||
$sums = RiskPool::query()
|
||||
->selectRaw('COALESCE(SUM(locked_amount), 0) as locked, COALESCE(SUM(total_cap_amount), 0) as cap')
|
||||
->first();
|
||||
|
||||
$locked = (int) (($sums?->locked) ?? 0);
|
||||
$cap = (int) (($sums?->cap) ?? 0);
|
||||
|
||||
return [
|
||||
'locked_amount' => $locked,
|
||||
'cap_amount' => $cap,
|
||||
'usage_percent' => $cap > 0 ? round(($locked / $cap) * 100, 4) : 0.0,
|
||||
];
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function drawPanel(Draw $draw): array
|
||||
{
|
||||
|
||||
@@ -291,7 +291,9 @@ final class AdminReportQueryService
|
||||
$payoutAgg = DB::table('ticket_items')
|
||||
->selectRaw('COALESCE(SUM(win_amount), 0) as win_minor, COALESCE(SUM(jackpot_win_amount), 0) as jackpot_minor')
|
||||
->first();
|
||||
$totalPayoutMinor = (int) ($payoutAgg->win_minor ?? 0) + (int) ($payoutAgg->jackpot_minor ?? 0);
|
||||
$totalWinMinor = (int) ($payoutAgg->win_minor ?? 0);
|
||||
$totalJackpotMinor = (int) ($payoutAgg->jackpot_minor ?? 0);
|
||||
$totalPayoutMinor = $totalWinMinor + $totalJackpotMinor;
|
||||
|
||||
$activity = DB::table('draws as d')
|
||||
->join('ticket_orders as o', 'o.draw_id', '=', 'd.id')
|
||||
@@ -312,8 +314,12 @@ final class AdminReportQueryService
|
||||
return [
|
||||
'currency_code' => $currencyCode !== '' ? $currencyCode : null,
|
||||
'total_bet_minor' => $totalBetMinor,
|
||||
'total_win_minor' => $totalWinMinor,
|
||||
'total_jackpot_minor' => $totalJackpotMinor,
|
||||
'total_payout_minor' => $totalPayoutMinor,
|
||||
'approx_house_gross_minor' => $totalBetMinor - $totalPayoutMinor,
|
||||
'order_count' => (int) DB::table('ticket_orders')->count(),
|
||||
'ticket_item_count' => (int) DB::table('ticket_items')->count(),
|
||||
'draw_count' => $drawCount,
|
||||
'business_day_count' => $businessDayCount,
|
||||
'date_from' => $dateFrom,
|
||||
|
||||
Reference in New Issue
Block a user