- 将玩法相关的显示名称字段统一为 `display_name`,移除多语言字段。 - 在 `PlayTypePatchController` 中新增即时切换玩法开关的功能,并推送大厅更新。 - 优化多个控制器和服务中的权限检查与数据处理逻辑,提升代码可读性与维护性。
83 lines
2.7 KiB
PHP
83 lines
2.7 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);
|
|
|
|
return [
|
|
'period' => $period,
|
|
'metric' => $metric,
|
|
'play_code' => $playCode,
|
|
'date_from' => $dateFrom,
|
|
'date_to' => $dateTo,
|
|
'currency_code' => $this->reportQuery->resolvePeriodCurrencyCode($dateFrom, $dateTo),
|
|
'summary' => $this->reportQuery->periodFinanceTotals($dateFrom, $dateTo),
|
|
'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,
|
|
),
|
|
];
|
|
}
|
|
|
|
private function canView(AdminUser $admin): bool
|
|
{
|
|
return $admin->hasAdminPermission('prd.dashboard.view')
|
|
|| $admin->hasAdminPermission('prd.draw_result.manage')
|
|
|| $admin->hasAdminPermission('prd.draw_result.view')
|
|
|| $admin->hasAdminPermission('prd.risk.view')
|
|
|| $admin->hasAdminPermission('prd.risk.manage')
|
|
|| $admin->hasAdminPermission('prd.report.view');
|
|
}
|
|
}
|