feat: 增强管理员功能与数据处理
- 在多个控制器中引入 agent_node_id,以支持基于代理节点的权限和数据过滤。 - 更新 AdminRole 和 AdminUser 模型,新增角色范围和代理节点相关功能,提升角色管理的灵活性。 - 在请求验证中添加 agent_node_id 字段,确保 API 接口支持代理节点的相关操作。 - 优化 LotterySettings 服务,支持批量写入设置,提升配置管理的效率。 - 更新仪表板和报告服务,增强数据统计功能,确保管理员能够获取更全面的统计信息。
This commit is contained in:
@@ -3,10 +3,12 @@
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\Draw;
|
||||
use App\Models\TicketItem;
|
||||
use App\Models\TicketOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\AdminSiteScope;
|
||||
use App\Support\AdminApiList;
|
||||
use App\Services\LotterySettings;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -20,9 +22,13 @@ final class AdminDrawIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): JsonResponse
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$p = AdminApiList::readPaging($request);
|
||||
$drawNo = trim((string) $request->query('draw_no', ''));
|
||||
$status = trim((string) $request->query('status', ''));
|
||||
$agentNodeId = $request->integer('agent_node_id') ?: null;
|
||||
|
||||
$q = Draw::query()->orderByDesc('draw_time')->orderByDesc('id');
|
||||
|
||||
@@ -39,6 +45,8 @@ final class AdminDrawIndexController extends Controller
|
||||
|
||||
$statsByDrawId = $this->aggregateListStats(
|
||||
$paginator->getCollection()->pluck('id')->map(fn ($id) => (int) $id)->all(),
|
||||
$admin,
|
||||
$agentNodeId,
|
||||
);
|
||||
|
||||
return AdminApiList::jsonWith($paginator, fn (Draw $row) => $this->row($row, $statsByDrawId), [
|
||||
@@ -55,20 +63,22 @@ final class AdminDrawIndexController extends Controller
|
||||
* @param list<int> $drawIds
|
||||
* @return array<int, array{total_bet_minor: int, total_payout_minor: int, profit_loss_minor: int}>
|
||||
*/
|
||||
private function aggregateListStats(array $drawIds): array
|
||||
private function aggregateListStats(array $drawIds, AdminUser $admin, ?int $agentNodeId): array
|
||||
{
|
||||
if ($drawIds === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$betByDraw = TicketOrder::query()
|
||||
->whereIn('draw_id', $drawIds)
|
||||
$betQuery = TicketOrder::query()->whereIn('draw_id', $drawIds);
|
||||
$this->scopeOrdersToVisiblePlayers($betQuery, $admin, $agentNodeId);
|
||||
$betByDraw = $betQuery
|
||||
->groupBy('draw_id')
|
||||
->selectRaw('draw_id, COALESCE(SUM(total_actual_deduct), 0) AS total_bet')
|
||||
->pluck('total_bet', 'draw_id');
|
||||
|
||||
$payoutRows = TicketItem::query()
|
||||
->whereIn('draw_id', $drawIds)
|
||||
$payoutQuery = TicketItem::query()->whereIn('draw_id', $drawIds);
|
||||
$this->scopeTicketItemsToVisiblePlayers($payoutQuery, $admin, $agentNodeId);
|
||||
$payoutRows = $payoutQuery
|
||||
->groupBy('draw_id')
|
||||
->selectRaw(
|
||||
'draw_id, COALESCE(SUM(win_amount), 0) AS win, COALESCE(SUM(jackpot_win_amount), 0) AS jackpot',
|
||||
@@ -91,6 +101,44 @@ final class AdminDrawIndexController extends Controller
|
||||
return $stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<TicketOrder> $query
|
||||
*/
|
||||
private function scopeOrdersToVisiblePlayers($query, AdminUser $admin, ?int $agentNodeId): void
|
||||
{
|
||||
if ($admin->isSuperAdmin() && ($agentNodeId === null || $agentNodeId <= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->whereHas('player', static function ($playerQuery) use ($admin, $agentNodeId): void {
|
||||
AdminSiteScope::applyPlayerFilters(
|
||||
$playerQuery,
|
||||
$admin,
|
||||
null,
|
||||
$agentNodeId !== null && $agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Builder<TicketItem> $query
|
||||
*/
|
||||
private function scopeTicketItemsToVisiblePlayers($query, AdminUser $admin, ?int $agentNodeId): void
|
||||
{
|
||||
if ($admin->isSuperAdmin() && ($agentNodeId === null || $agentNodeId <= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$query->whereHas('player', static function ($playerQuery) use ($admin, $agentNodeId): void {
|
||||
AdminSiteScope::applyPlayerFilters(
|
||||
$playerQuery,
|
||||
$admin,
|
||||
null,
|
||||
$agentNodeId !== null && $agentNodeId > 0 ? $agentNodeId : null,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{total_bet_minor: int, total_payout_minor: int, profit_loss_minor: int}> $statsByDrawId
|
||||
* @return array<string, mixed>
|
||||
|
||||
Reference in New Issue
Block a user