refactor: 更新权限管理与请求验证逻辑
- 在多个控制器中将权限检查从 hasAdminPermission 更新为 hasPermissionCode,以增强权限管理的灵活性。 - 引入 AdminScopePolicy,优化基于代理节点的权限和数据过滤逻辑,确保管理员能够更精确地控制访问权限。 - 在请求验证中添加 agent_node_id 字段,确保 API 接口支持代理节点的相关操作。 - 更新 AdminUser 模型,新增 hasPermissionCode 方法,以支持更细粒度的权限检查。 - 优化审计日志记录逻辑,确保在处理请求时能够准确记录管理员的操作。
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Services\Admin;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\AuditLog;
|
||||
use App\Support\AdminDataScope;
|
||||
use App\Support\AdminScopeContext;
|
||||
use App\Support\AdminScopeContextResolver;
|
||||
use App\Models\Draw;
|
||||
use App\Models\RiskPool;
|
||||
use App\Models\RiskPoolLockLog;
|
||||
@@ -23,6 +25,19 @@ use Illuminate\Support\Facades\DB;
|
||||
*/
|
||||
final class AdminReportQueryService
|
||||
{
|
||||
private function normalizeScope(AdminUser|AdminScopeContext|null $scope): ?AdminScopeContext
|
||||
{
|
||||
if ($scope instanceof AdminScopeContext) {
|
||||
return $scope;
|
||||
}
|
||||
|
||||
if ($scope instanceof AdminUser) {
|
||||
return AdminScopeContextResolver::fromValues($scope);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{date_from: string, date_to: string}
|
||||
*/
|
||||
@@ -111,9 +126,10 @@ final class AdminReportQueryService
|
||||
* business_day_count: int
|
||||
* }
|
||||
*/
|
||||
public function periodFinanceTotals(string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
public function periodFinanceTotals(string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$rows = $this->dailyProfitRows($dateFrom, $dateTo, $scopedAdmin);
|
||||
$context = $this->normalizeScope($scope);
|
||||
$rows = $this->dailyProfitRows($dateFrom, $dateTo, $context);
|
||||
$totalBet = 0;
|
||||
$totalPayout = 0;
|
||||
$totalGross = 0;
|
||||
@@ -126,7 +142,7 @@ final class AdminReportQueryService
|
||||
$activityQuery = DB::table('draws as d')
|
||||
->join('ticket_orders as o', 'o.draw_id', '=', 'd.id')
|
||||
->whereBetween('d.business_date', [$dateFrom, $dateTo]);
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($activityQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($activityQuery, $context?->admin, 'o');
|
||||
$activity = $activityQuery
|
||||
->selectRaw('COUNT(DISTINCT d.id) as draw_count')
|
||||
->selectRaw('COUNT(DISTINCT d.business_date) as business_day_count')
|
||||
@@ -146,8 +162,9 @@ final class AdminReportQueryService
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function dailyProfitSeriesFilled(string $dateFrom, string $dateTo, int $maxDays = 90, ?AdminUser $scopedAdmin = null): array
|
||||
public function dailyProfitSeriesFilled(string $dateFrom, string $dateTo, int $maxDays = 90, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$from = Carbon::parse($dateFrom)->startOfDay();
|
||||
$to = Carbon::parse($dateTo)->startOfDay();
|
||||
$spanDays = (int) $from->diffInDays($to) + 1;
|
||||
@@ -160,7 +177,7 @@ final class AdminReportQueryService
|
||||
$truncated = true;
|
||||
}
|
||||
|
||||
$indexed = collect($this->dailyProfitRows($chartFrom, $chartTo, $scopedAdmin))->keyBy('business_date');
|
||||
$indexed = collect($this->dailyProfitRows($chartFrom, $chartTo, $context))->keyBy('business_date');
|
||||
$cursor = Carbon::parse($chartFrom)->startOfDay();
|
||||
$end = Carbon::parse($chartTo)->startOfDay();
|
||||
$series = [];
|
||||
@@ -193,9 +210,9 @@ final class AdminReportQueryService
|
||||
string $dateTo,
|
||||
?string $playCode = null,
|
||||
int $limit = 12,
|
||||
?AdminUser $scopedAdmin = null,
|
||||
AdminUser|AdminScopeContext|null $scope = null,
|
||||
): array {
|
||||
return $this->playDimensionBaseQuery($playCode, $dateFrom, $dateTo, $scopedAdmin)
|
||||
return $this->playDimensionBaseQuery($playCode, $dateFrom, $dateTo, $scope)
|
||||
->orderByDesc('total_bet_minor')
|
||||
->limit($limit)
|
||||
->get()
|
||||
@@ -229,8 +246,9 @@ final class AdminReportQueryService
|
||||
string $dateTo,
|
||||
?string $playCode = null,
|
||||
int $limit = 200,
|
||||
?AdminUser $scopedAdmin = null,
|
||||
AdminUser|AdminScopeContext|null $scope = null,
|
||||
): array {
|
||||
$context = $this->normalizeScope($scope);
|
||||
$query = DB::table('ticket_items as ti')
|
||||
->join('ticket_orders as o', 'o.id', '=', 'ti.order_id')
|
||||
->leftJoin('players as p', 'p.id', '=', 'ti.player_id')
|
||||
@@ -250,7 +268,12 @@ final class AdminReportQueryService
|
||||
$query->where('ti.play_code', $playCode);
|
||||
}
|
||||
|
||||
AdminDataScope::applyToPlayersAlias($query, $scopedAdmin, 'p');
|
||||
AdminDataScope::applyToPlayersAlias(
|
||||
$query,
|
||||
$context?->admin,
|
||||
'p',
|
||||
$context?->effectiveRequestedAgentNodeId(),
|
||||
);
|
||||
|
||||
return $query
|
||||
->orderByDesc('total_bet_minor')
|
||||
@@ -270,20 +293,21 @@ final class AdminReportQueryService
|
||||
->all();
|
||||
}
|
||||
|
||||
public function resolvePeriodCurrencyCode(string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): ?string
|
||||
public function resolvePeriodCurrencyCode(string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): ?string
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$currencyQuery = DB::table('ticket_orders as o')
|
||||
->join('draws as d', 'd.id', '=', 'o.draw_id')
|
||||
->whereBetween('d.business_date', [$dateFrom, $dateTo]);
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($currencyQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($currencyQuery, $context?->admin, 'o');
|
||||
$currencyCode = (string) ($currencyQuery->orderByDesc('o.id')->value('o.currency_code') ?? '');
|
||||
|
||||
return $currencyCode !== '' ? $currencyCode : null;
|
||||
}
|
||||
|
||||
public function dailyProfitPaginated(string $dateFrom, string $dateTo, int $page, int $perPage, ?AdminUser $scopedAdmin = null): LengthAwarePaginator
|
||||
public function dailyProfitPaginated(string $dateFrom, string $dateTo, int $page, int $perPage, AdminUser|AdminScopeContext|null $scope = null): LengthAwarePaginator
|
||||
{
|
||||
$rows = $this->dailyProfitRows($dateFrom, $dateTo, $scopedAdmin);
|
||||
$rows = $this->dailyProfitRows($dateFrom, $dateTo, $scope);
|
||||
$total = count($rows);
|
||||
$offset = max(0, ($page - 1) * $perPage);
|
||||
$items = array_slice($rows, $offset, $perPage);
|
||||
@@ -296,18 +320,19 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function dailyProfitRows(string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
public function dailyProfitRows(string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$betSub = DB::table('ticket_orders as o')
|
||||
->selectRaw('o.draw_id, SUM(o.total_actual_deduct) as total_bet_minor')
|
||||
->groupBy('o.draw_id');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($betSub, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($betSub, $context?->admin, 'o');
|
||||
|
||||
$payoutSub = DB::table('ticket_items as ti')
|
||||
->join('ticket_orders as o', 'o.id', '=', 'ti.order_id')
|
||||
->selectRaw('ti.draw_id, SUM(ti.win_amount + ti.jackpot_win_amount) as total_payout_minor')
|
||||
->groupBy('ti.draw_id');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($payoutSub, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($payoutSub, $context?->admin, 'o');
|
||||
|
||||
return DB::table('draws as d')
|
||||
->whereBetween('d.business_date', [$dateFrom, $dateTo])
|
||||
@@ -351,15 +376,16 @@ final class AdminReportQueryService
|
||||
* date_to: ?string
|
||||
* }
|
||||
*/
|
||||
public function platformLifetimeTotals(?AdminUser $scopedAdmin = null): array
|
||||
public function platformLifetimeTotals(AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$betQuery = DB::table('ticket_orders as o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($betQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($betQuery, $context?->admin, 'o');
|
||||
$totalBetMinor = (int) $betQuery->sum('o.total_actual_deduct');
|
||||
|
||||
$payoutQuery = DB::table('ticket_items as ti')
|
||||
->join('ticket_orders as o', 'o.id', '=', 'ti.order_id');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($payoutQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($payoutQuery, $context?->admin, 'o');
|
||||
$payoutAgg = $payoutQuery
|
||||
->selectRaw('COALESCE(SUM(ti.win_amount), 0) as win_minor, COALESCE(SUM(ti.jackpot_win_amount), 0) as jackpot_minor')
|
||||
->first();
|
||||
@@ -369,7 +395,7 @@ final class AdminReportQueryService
|
||||
|
||||
$activityQuery = DB::table('draws as d')
|
||||
->join('ticket_orders as o', 'o.draw_id', '=', 'd.id');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($activityQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($activityQuery, $context?->admin, 'o');
|
||||
$activity = $activityQuery
|
||||
->selectRaw('COUNT(DISTINCT d.id) as draw_count')
|
||||
->selectRaw('COUNT(DISTINCT d.business_date) as business_day_count')
|
||||
@@ -384,14 +410,14 @@ final class AdminReportQueryService
|
||||
$dateTo = $this->formatBusinessDateValue($activity?->date_to);
|
||||
|
||||
$currencyQuery = DB::table('ticket_orders as o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($currencyQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($currencyQuery, $context?->admin, 'o');
|
||||
$currencyCode = (string) ($currencyQuery->orderByDesc('o.id')->value('o.currency_code') ?? '');
|
||||
|
||||
$orderCountQuery = DB::table('ticket_orders as o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($orderCountQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($orderCountQuery, $context?->admin, 'o');
|
||||
$itemCountQuery = DB::table('ticket_items as ti')
|
||||
->join('ticket_orders as o', 'o.id', '=', 'ti.order_id');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($itemCountQuery, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($itemCountQuery, $context?->admin, 'o');
|
||||
|
||||
return [
|
||||
'currency_code' => $currencyCode !== '' ? $currencyCode : null,
|
||||
@@ -415,10 +441,9 @@ final class AdminReportQueryService
|
||||
string $dateTo,
|
||||
int $page,
|
||||
int $perPage,
|
||||
?AdminUser $scopedAdmin = null,
|
||||
?int $requestedAgentNodeId = null,
|
||||
AdminUser|AdminScopeContext|null $scope = null,
|
||||
): LengthAwarePaginator {
|
||||
$query = $this->playerWinLossBaseQuery($playerId, $dateFrom, $dateTo, $scopedAdmin, $requestedAgentNodeId);
|
||||
$query = $this->playerWinLossBaseQuery($playerId, $dateFrom, $dateTo, $scope);
|
||||
|
||||
return $query->paginate($perPage, ['*'], 'page', $page);
|
||||
}
|
||||
@@ -429,9 +454,9 @@ final class AdminReportQueryService
|
||||
string $dateTo,
|
||||
int $page,
|
||||
int $perPage,
|
||||
?AdminUser $scopedAdmin = null,
|
||||
AdminUser|AdminScopeContext|null $scope = null,
|
||||
): LengthAwarePaginator {
|
||||
$query = $this->playDimensionBaseQuery($playCode, $dateFrom, $dateTo, $scopedAdmin);
|
||||
$query = $this->playDimensionBaseQuery($playCode, $dateFrom, $dateTo, $scope);
|
||||
|
||||
return $query->paginate($perPage, ['*'], 'page', $page);
|
||||
}
|
||||
@@ -442,9 +467,9 @@ final class AdminReportQueryService
|
||||
string $dateTo,
|
||||
int $page,
|
||||
int $perPage,
|
||||
?AdminUser $scopedAdmin = null,
|
||||
AdminUser|AdminScopeContext|null $scope = null,
|
||||
): LengthAwarePaginator {
|
||||
$query = $this->rebateCommissionBaseQuery($playCode, $dateFrom, $dateTo, $scopedAdmin);
|
||||
$query = $this->rebateCommissionBaseQuery($playCode, $dateFrom, $dateTo, $scope);
|
||||
|
||||
return $query->paginate($perPage, ['*'], 'page', $page);
|
||||
}
|
||||
@@ -452,21 +477,21 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
public function reportRows(string $reportType, ?array $filterJson, ?AdminUser $scopedAdmin = null): array
|
||||
public function reportRows(string $reportType, ?array $filterJson, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$range = $this->resolveDateRange($filterJson);
|
||||
$dateFrom = $range['date_from'];
|
||||
$dateTo = $range['date_to'];
|
||||
|
||||
return match ($reportType) {
|
||||
'draw_profit_summary' => $this->drawProfitExportRows($filterJson, $scopedAdmin),
|
||||
'daily_profit_summary' => $this->dailyProfitExportRows($dateFrom, $dateTo, $scopedAdmin),
|
||||
'player_win_loss' => $this->playerWinLossExportRows($filterJson, $dateFrom, $dateTo, $scopedAdmin),
|
||||
'play_dimension_report' => $this->playDimensionExportRows($filterJson, $dateFrom, $dateTo, $scopedAdmin),
|
||||
'rebate_commission_report' => $this->rebateCommissionExportRows($filterJson, $dateFrom, $dateTo, $scopedAdmin),
|
||||
'draw_profit_summary' => $this->drawProfitExportRows($filterJson, $scope),
|
||||
'daily_profit_summary' => $this->dailyProfitExportRows($dateFrom, $dateTo, $scope),
|
||||
'player_win_loss' => $this->playerWinLossExportRows($filterJson, $dateFrom, $dateTo, $scope),
|
||||
'play_dimension_report' => $this->playDimensionExportRows($filterJson, $dateFrom, $dateTo, $scope),
|
||||
'rebate_commission_report' => $this->rebateCommissionExportRows($filterJson, $dateFrom, $dateTo, $scope),
|
||||
'audit_operation_report' => $this->auditExportRows($filterJson, $dateFrom, $dateTo),
|
||||
'wallet_transfer_report', 'transfer_orders_daily' => $this->transferOrdersExportRows($filterJson, $dateFrom, $dateTo, $scopedAdmin),
|
||||
'wallet_txns_daily' => $this->walletTxnsExportRows($filterJson, $dateFrom, $dateTo, $scopedAdmin),
|
||||
'wallet_transfer_report', 'transfer_orders_daily' => $this->transferOrdersExportRows($filterJson, $dateFrom, $dateTo, $scope),
|
||||
'wallet_txns_daily' => $this->walletTxnsExportRows($filterJson, $dateFrom, $dateTo, $scope),
|
||||
'hot_number_risk_report' => $this->hotNumberRiskExportRows($filterJson),
|
||||
'sold_out_number_report' => $this->soldOutNumberExportRows($filterJson),
|
||||
default => [
|
||||
@@ -513,12 +538,12 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
private function dailyProfitExportRows(string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
private function dailyProfitExportRows(string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$rows = [
|
||||
['日期', '下注', '派彩', '盈亏'],
|
||||
];
|
||||
foreach ($this->dailyProfitRows($dateFrom, $dateTo, $scopedAdmin) as $row) {
|
||||
foreach ($this->dailyProfitRows($dateFrom, $dateTo, $scope) as $row) {
|
||||
$rows[] = [
|
||||
$row['business_date'],
|
||||
$row['total_bet_minor'],
|
||||
@@ -533,13 +558,13 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
private function playerWinLossExportRows(?array $filterJson, string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
private function playerWinLossExportRows(?array $filterJson, string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$playerId = isset($filterJson['player_id']) ? (int) $filterJson['player_id'] : null;
|
||||
$rows = [
|
||||
['玩家ID', '用户名', '下注', '派彩', '净输赢'],
|
||||
];
|
||||
$items = $this->playerWinLossBaseQuery($playerId, $dateFrom, $dateTo, $scopedAdmin)->get();
|
||||
$items = $this->playerWinLossBaseQuery($playerId, $dateFrom, $dateTo, $scope)->get();
|
||||
foreach ($items as $row) {
|
||||
$rows[] = [
|
||||
(int) $row->player_id,
|
||||
@@ -556,13 +581,13 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
private function playDimensionExportRows(?array $filterJson, string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
private function playDimensionExportRows(?array $filterJson, string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$playCode = isset($filterJson['play_code']) ? trim((string) $filterJson['play_code']) : null;
|
||||
$rows = [
|
||||
['玩法', '维度', '下注', '派彩', '盈亏'],
|
||||
];
|
||||
$items = $this->playDimensionBaseQuery($playCode !== '' ? $playCode : null, $dateFrom, $dateTo, $scopedAdmin)->get();
|
||||
$items = $this->playDimensionBaseQuery($playCode !== '' ? $playCode : null, $dateFrom, $dateTo, $scope)->get();
|
||||
foreach ($items as $row) {
|
||||
$rows[] = [
|
||||
(string) $row->play_code,
|
||||
@@ -579,13 +604,13 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
private function rebateCommissionExportRows(?array $filterJson, string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
private function rebateCommissionExportRows(?array $filterJson, string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$playCode = isset($filterJson['play_code']) ? trim((string) $filterJson['play_code']) : null;
|
||||
$rows = [
|
||||
['玩法', '回水', '订单数', '注单数'],
|
||||
];
|
||||
$items = $this->rebateCommissionBaseQuery($playCode !== '' ? $playCode : null, $dateFrom, $dateTo, $scopedAdmin)->get();
|
||||
$items = $this->rebateCommissionBaseQuery($playCode !== '' ? $playCode : null, $dateFrom, $dateTo, $scope)->get();
|
||||
foreach ($items as $row) {
|
||||
$rows[] = [
|
||||
(string) $row->play_code,
|
||||
@@ -635,9 +660,9 @@ final class AdminReportQueryService
|
||||
?int $playerId,
|
||||
string $dateFrom,
|
||||
string $dateTo,
|
||||
?AdminUser $scopedAdmin = null,
|
||||
?int $requestedAgentNodeId = null,
|
||||
AdminUser|AdminScopeContext|null $scope = null,
|
||||
) {
|
||||
$context = $this->normalizeScope($scope);
|
||||
$query = DB::table('ticket_items as ti')
|
||||
->join('ticket_orders as o', 'o.id', '=', 'ti.order_id')
|
||||
->leftJoin('players as p', 'p.id', '=', 'ti.player_id')
|
||||
@@ -659,16 +684,20 @@ final class AdminReportQueryService
|
||||
$query->where('ti.player_id', $playerId);
|
||||
}
|
||||
|
||||
if ($scopedAdmin !== null) {
|
||||
AdminDataScope::applyToPlayersAlias($query, $scopedAdmin, 'p', $requestedAgentNodeId);
|
||||
}
|
||||
AdminDataScope::applyToPlayersAlias(
|
||||
$query,
|
||||
$context?->admin,
|
||||
'p',
|
||||
$context?->effectiveRequestedAgentNodeId(),
|
||||
);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/** @return \Illuminate\Database\Query\Builder */
|
||||
private function playDimensionBaseQuery(?string $playCode, string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null)
|
||||
private function playDimensionBaseQuery(?string $playCode, string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null)
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$query = DB::table('ticket_items as ti')
|
||||
->join('ticket_orders as o', 'o.id', '=', 'ti.order_id')
|
||||
->selectRaw('ti.play_code')
|
||||
@@ -686,14 +715,15 @@ final class AdminReportQueryService
|
||||
$query->where('ti.play_code', $playCode);
|
||||
}
|
||||
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($query, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($query, $context?->admin, 'o');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/** @return \Illuminate\Database\Query\Builder */
|
||||
private function rebateCommissionBaseQuery(?string $playCode, string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null)
|
||||
private function rebateCommissionBaseQuery(?string $playCode, string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null)
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$query = DB::table('ticket_items as ti')
|
||||
->join('ticket_orders as o', 'o.id', '=', 'ti.order_id')
|
||||
->selectRaw('ti.play_code')
|
||||
@@ -709,7 +739,7 @@ final class AdminReportQueryService
|
||||
$query->where('ti.play_code', $playCode);
|
||||
}
|
||||
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($query, $scopedAdmin, 'o');
|
||||
AdminDataScope::applyToTicketOrdersViaPlayer($query, $context?->admin, 'o');
|
||||
|
||||
return $query;
|
||||
}
|
||||
@@ -717,8 +747,9 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
private function drawProfitExportRows(?array $filterJson, ?AdminUser $scopedAdmin = null): array
|
||||
private function drawProfitExportRows(?array $filterJson, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$draw = $this->resolveDrawForReport($filterJson);
|
||||
if ($draw === null) {
|
||||
return [['提示', '请提供 draw_id 或 draw_no']];
|
||||
@@ -727,9 +758,9 @@ final class AdminReportQueryService
|
||||
$drawId = (int) $draw->id;
|
||||
$orderQuery = TicketOrder::query()->where('draw_id', $drawId);
|
||||
$itemQuery = TicketItem::query()->where('draw_id', $drawId);
|
||||
if ($scopedAdmin !== null) {
|
||||
AdminDataScope::applyEloquentViaPlayer($orderQuery, $scopedAdmin);
|
||||
AdminDataScope::applyEloquentViaPlayer($itemQuery, $scopedAdmin);
|
||||
if ($context !== null) {
|
||||
AdminDataScope::applyEloquentViaPlayer($orderQuery, $context->admin);
|
||||
AdminDataScope::applyEloquentViaPlayer($itemQuery, $context->admin);
|
||||
}
|
||||
|
||||
$totalBetMinor = (int) $orderQuery->sum('total_actual_deduct');
|
||||
@@ -952,8 +983,9 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
private function transferOrdersExportRows(?array $filterJson, string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
private function transferOrdersExportRows(?array $filterJson, string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$rows = [
|
||||
['转账单号', '玩家ID', '用户名', '昵称', '方向', '币种', '金额', '状态', '外部单号', '失败原因', '创建时间', '完成时间'],
|
||||
];
|
||||
@@ -962,8 +994,8 @@ final class AdminReportQueryService
|
||||
->with(['player:id,username,nickname'])
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($scopedAdmin !== null) {
|
||||
AdminDataScope::applyEloquentViaPlayer($query, $scopedAdmin);
|
||||
if ($context !== null) {
|
||||
AdminDataScope::applyEloquentViaPlayer($query, $context->admin);
|
||||
}
|
||||
|
||||
$playerId = isset($filterJson['player_id']) ? (int) $filterJson['player_id'] : null;
|
||||
@@ -998,8 +1030,9 @@ final class AdminReportQueryService
|
||||
/**
|
||||
* @return list<array<int, string|int|float|null>>
|
||||
*/
|
||||
private function walletTxnsExportRows(?array $filterJson, string $dateFrom, string $dateTo, ?AdminUser $scopedAdmin = null): array
|
||||
private function walletTxnsExportRows(?array $filterJson, string $dateFrom, string $dateTo, AdminUser|AdminScopeContext|null $scope = null): array
|
||||
{
|
||||
$context = $this->normalizeScope($scope);
|
||||
$rows = [
|
||||
['流水号', '玩家ID', '用户名', '业务类型', '业务单号', '方向', '金额', '变动前余额', '变动后余额', '状态', '外部单号', '备注', '创建时间'],
|
||||
];
|
||||
@@ -1008,8 +1041,8 @@ final class AdminReportQueryService
|
||||
->with(['player:id,username'])
|
||||
->orderByDesc('id');
|
||||
|
||||
if ($scopedAdmin !== null) {
|
||||
AdminDataScope::applyEloquentViaPlayer($query, $scopedAdmin);
|
||||
if ($context !== null) {
|
||||
AdminDataScope::applyEloquentViaPlayer($query, $context->admin);
|
||||
}
|
||||
|
||||
$playerId = isset($filterJson['player_id']) ? (int) $filterJson['player_id'] : null;
|
||||
|
||||
Reference in New Issue
Block a user