- 在多个控制器中引入 agent_node_id,以支持基于代理节点的权限和数据过滤。 - 更新 AdminRole 和 AdminUser 模型,新增角色范围和代理节点相关功能,提升角色管理的灵活性。 - 在请求验证中添加 agent_node_id 字段,确保 API 接口支持代理节点的相关操作。 - 优化 LotterySettings 服务,支持批量写入设置,提升配置管理的效率。 - 更新仪表板和报告服务,增强数据统计功能,确保管理员能够获取更全面的统计信息。
87 lines
2.8 KiB
PHP
87 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin;
|
|
|
|
use App\Models\AdminUser;
|
|
|
|
/**
|
|
* 仪表盘可筛选分析数据:区间汇总、日趋势、玩法拆解。
|
|
*/
|
|
final class AdminDashboardAnalyticsBuilder
|
|
{
|
|
public function __construct(
|
|
private readonly AdminReportQueryService $reportQuery,
|
|
) {}
|
|
|
|
/**
|
|
* @param array{
|
|
* period?: string,
|
|
* date_from?: string|null,
|
|
* date_to?: string|null,
|
|
* metric?: string,
|
|
* play_code?: string|null
|
|
* } $filters
|
|
*
|
|
* @return array<string, mixed>|null
|
|
*/
|
|
public function build(AdminUser $admin, array $filters): ?array
|
|
{
|
|
if (! $this->canView($admin)) {
|
|
return null;
|
|
}
|
|
|
|
$period = (string) ($filters['period'] ?? 'last_7_days');
|
|
$metric = (string) ($filters['metric'] ?? 'overview');
|
|
$playCode = isset($filters['play_code']) && $filters['play_code'] !== ''
|
|
? (string) $filters['play_code']
|
|
: null;
|
|
|
|
$range = $this->reportQuery->resolveDashboardPeriod(
|
|
$period,
|
|
isset($filters['date_from']) ? (string) $filters['date_from'] : null,
|
|
isset($filters['date_to']) ? (string) $filters['date_to'] : null,
|
|
);
|
|
|
|
$dateFrom = $range['date_from'];
|
|
$dateTo = $range['date_to'];
|
|
|
|
$trend = $this->reportQuery->dailyProfitSeriesFilled($dateFrom, $dateTo, scopedAdmin: $admin);
|
|
|
|
return [
|
|
'period' => $period,
|
|
'metric' => $metric,
|
|
'play_code' => $playCode,
|
|
'date_from' => $dateFrom,
|
|
'date_to' => $dateTo,
|
|
'currency_code' => $this->reportQuery->resolvePeriodCurrencyCode($dateFrom, $dateTo, $admin),
|
|
'summary' => $this->reportQuery->periodFinanceTotals($dateFrom, $dateTo, $admin),
|
|
'daily_series' => $trend['series'],
|
|
'chart_meta' => [
|
|
'chart_date_from' => $trend['chart_date_from'],
|
|
'chart_date_to' => $trend['chart_date_to'],
|
|
'truncated' => $trend['truncated'],
|
|
'span_days' => $trend['span_days'],
|
|
],
|
|
'play_breakdown' => $this->reportQuery->playDimensionBreakdownRows(
|
|
$dateFrom,
|
|
$dateTo,
|
|
$playCode,
|
|
scopedAdmin: $admin,
|
|
),
|
|
'agent_breakdown' => $this->reportQuery->agentRankingRows(
|
|
$dateFrom,
|
|
$dateTo,
|
|
$playCode,
|
|
limit: 200,
|
|
scopedAdmin: $admin,
|
|
),
|
|
];
|
|
}
|
|
|
|
/** 与 {@see AdminAuthorizationRegistry} 中 dashboard 类 API 资源的 `dashboard.view` 绑定一致。 */
|
|
private function canView(AdminUser $admin): bool
|
|
{
|
|
return $admin->hasAdminPermission('prd.dashboard.view');
|
|
}
|
|
}
|