feat: 增强代理和玩家管理功能
- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
This commit is contained in:
@@ -10,7 +10,10 @@ use App\Support\ApiResponse;
|
||||
use App\Models\SettlementBatch;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Support\AdminDrawResponsePolicy;
|
||||
use App\Support\AdminScopePolicy;
|
||||
use App\Support\ApiMessage;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/draws/{draw}/finance-summary — 单期投注/派彩汇总(客服/财务视角,PRD §15.4)。
|
||||
@@ -23,6 +26,17 @@ final class AdminDrawFinanceSummaryController extends Controller
|
||||
{
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if(! $admin instanceof AdminUser, 401);
|
||||
|
||||
if (! AdminDrawResponsePolicy::canViewDrawFinance($admin)) {
|
||||
return ApiMessage::errorResponse(
|
||||
$request,
|
||||
'admin.permission_denied',
|
||||
ErrorCode::AdminForbidden->value,
|
||||
null,
|
||||
403,
|
||||
);
|
||||
}
|
||||
|
||||
$scope = AdminScopePolicy::resolveContext($request, $admin);
|
||||
|
||||
$drawId = (int) $draw->id;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\Draw;
|
||||
use App\Models\TicketItem;
|
||||
@@ -10,6 +9,8 @@ use App\Models\TicketOrder;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\AdminApiList;
|
||||
use App\Support\AdminScopeContext;
|
||||
use App\Support\AdminDrawApiPresenter;
|
||||
use App\Support\AdminDrawResponsePolicy;
|
||||
use App\Support\AdminScopePolicy;
|
||||
use App\Services\LotterySettings;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -44,19 +45,30 @@ final class AdminDrawIndexController extends Controller
|
||||
/** @var LengthAwarePaginator $paginator */
|
||||
$paginator = $q->paginate($p['perPage'], ['*'], 'page', $p['page']);
|
||||
|
||||
$statsByDrawId = $this->aggregateListStats(
|
||||
$paginator->getCollection()->pluck('id')->map(fn ($id) => (int) $id)->all(),
|
||||
$scope,
|
||||
);
|
||||
$statsByDrawId = AdminDrawResponsePolicy::canViewDrawFinance($admin)
|
||||
? $this->aggregateListStats(
|
||||
$paginator->getCollection()->pluck('id')->map(fn ($id) => (int) $id)->all(),
|
||||
$scope,
|
||||
)
|
||||
: [];
|
||||
|
||||
return AdminApiList::jsonWith($paginator, fn (Draw $row) => $this->row($row, $statsByDrawId), [
|
||||
'schedule' => [
|
||||
'timezone' => LotterySettings::drawTimezone(),
|
||||
'interval_minutes' => LotterySettings::drawIntervalMinutes(),
|
||||
'betting_window_seconds' => LotterySettings::drawBettingWindowSeconds(),
|
||||
'close_before_draw_seconds' => LotterySettings::drawCloseBeforeDrawSeconds(),
|
||||
return AdminApiList::jsonWith(
|
||||
$paginator,
|
||||
fn (Draw $row): array => AdminDrawApiPresenter::listRow(
|
||||
$row,
|
||||
$statsByDrawId[(int) $row->id] ?? null,
|
||||
$admin,
|
||||
),
|
||||
[
|
||||
'schedule' => [
|
||||
'timezone' => LotterySettings::drawTimezone(),
|
||||
'interval_minutes' => LotterySettings::drawIntervalMinutes(),
|
||||
'betting_window_seconds' => LotterySettings::drawBettingWindowSeconds(),
|
||||
'close_before_draw_seconds' => LotterySettings::drawCloseBeforeDrawSeconds(),
|
||||
],
|
||||
'capabilities' => AdminDrawResponsePolicy::capabilities($admin),
|
||||
],
|
||||
]);
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,38 +141,4 @@ final class AdminDrawIndexController extends Controller
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, array{total_bet_minor: int, total_payout_minor: int, profit_loss_minor: int}> $statsByDrawId
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function row(Draw $draw, array $statsByDrawId): array
|
||||
{
|
||||
$stats = $statsByDrawId[(int) $draw->id] ?? [
|
||||
'total_bet_minor' => 0,
|
||||
'total_payout_minor' => 0,
|
||||
'profit_loss_minor' => 0,
|
||||
];
|
||||
|
||||
return [
|
||||
'id' => (int) $draw->id,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'business_date' => $draw->business_date instanceof Carbon
|
||||
? $draw->business_date->format('Y-m-d')
|
||||
: (string) $draw->business_date,
|
||||
'sequence_no' => (int) $draw->sequence_no,
|
||||
'status' => $draw->status,
|
||||
'start_time' => $draw->start_time?->toIso8601String(),
|
||||
'close_time' => $draw->close_time?->toIso8601String(),
|
||||
'draw_time' => $draw->draw_time?->toIso8601String(),
|
||||
'cooling_end_time' => $draw->cooling_end_time?->toIso8601String(),
|
||||
'result_source' => $draw->result_source,
|
||||
'current_result_version' => (int) $draw->current_result_version,
|
||||
'settle_version' => (int) $draw->settle_version,
|
||||
'is_reopened' => (bool) $draw->is_reopened,
|
||||
'total_bet_minor' => $stats['total_bet_minor'],
|
||||
'total_payout_minor' => $stats['total_payout_minor'],
|
||||
'profit_loss_minor' => $stats['profit_loss_minor'],
|
||||
'updated_at' => $draw->updated_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,56 +4,46 @@ namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use App\Models\Draw;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Models\DrawResultItem;
|
||||
use App\Models\DrawResultBatch;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\AdminDrawApiPresenter;
|
||||
use App\Support\AdminDrawResponsePolicy;
|
||||
use App\Lottery\DrawResultBatchStatus;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/draws/{draw}/result-batches — 开奖批次与号码(审核/结果核对)。
|
||||
*/
|
||||
final class AdminDrawResultBatchesIndexController extends Controller
|
||||
{
|
||||
public function __invoke(Draw $draw): JsonResponse
|
||||
public function __invoke(Request $request, Draw $draw): JsonResponse
|
||||
{
|
||||
$batches = $draw->resultBatches()
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
$manage = AdminDrawResponsePolicy::canManageDrawResults($admin);
|
||||
|
||||
$query = $draw->resultBatches()
|
||||
->with(['items' => function ($q): void {
|
||||
$q->orderBy('prize_type')->orderBy('prize_index');
|
||||
}])
|
||||
->orderByDesc('result_version')
|
||||
->get();
|
||||
->orderByDesc('result_version');
|
||||
|
||||
if (! $manage) {
|
||||
$query->where('status', DrawResultBatchStatus::Published->value);
|
||||
}
|
||||
|
||||
$batches = $query->get();
|
||||
|
||||
return ApiResponse::success([
|
||||
'draw_id' => (int) $draw->id,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'draw_status' => $draw->status,
|
||||
'batches' => $batches->map(fn (DrawResultBatch $b) => $this->serializeBatch($b))->all(),
|
||||
'capabilities' => AdminDrawResponsePolicy::capabilities($admin),
|
||||
'batches' => $batches
|
||||
->map(fn (DrawResultBatch $b): array => AdminDrawApiPresenter::resultBatch($b, $admin))
|
||||
->all(),
|
||||
]);
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
private function serializeBatch(DrawResultBatch $batch): array
|
||||
{
|
||||
return [
|
||||
'id' => (int) $batch->id,
|
||||
'result_version' => (int) $batch->result_version,
|
||||
'source_type' => $batch->source_type,
|
||||
'rng_seed_hash' => $batch->rng_seed_hash,
|
||||
'status' => $batch->status,
|
||||
'created_by' => $batch->created_by,
|
||||
'confirmed_by' => $batch->confirmed_by,
|
||||
'confirmed_at' => $batch->confirmed_at?->toIso8601String(),
|
||||
'created_at' => $batch->created_at?->toIso8601String(),
|
||||
'updated_at' => $batch->updated_at?->toIso8601String(),
|
||||
'items' => $batch->items->map(fn (DrawResultItem $item) => [
|
||||
'prize_type' => $item->prize_type,
|
||||
'prize_index' => (int) $item->prize_index,
|
||||
'number_4d' => $item->number_4d,
|
||||
'suffix_3d' => $item->suffix_3d,
|
||||
'suffix_2d' => $item->suffix_2d,
|
||||
'head_digit' => $item->head_digit,
|
||||
'tail_digit' => $item->tail_digit,
|
||||
])->values()->all(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Draw;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Draw;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Lottery\DrawResultBatchStatus;
|
||||
use App\Support\AdminDrawApiPresenter;
|
||||
use App\Services\Draw\DrawHallSnapshotBuilder;
|
||||
|
||||
/**
|
||||
@@ -19,41 +19,13 @@ final class AdminDrawShowController extends Controller
|
||||
private readonly DrawHallSnapshotBuilder $hallPreview,
|
||||
) {}
|
||||
|
||||
public function __invoke(Draw $draw): JsonResponse
|
||||
public function __invoke(Request $request, Draw $draw): JsonResponse
|
||||
{
|
||||
$nowUtc = now()->utc();
|
||||
$batchCounts = [
|
||||
'total' => $draw->resultBatches()->count(),
|
||||
'pending_review' => $draw->resultBatches()
|
||||
->where('status', DrawResultBatchStatus::PendingReview->value)
|
||||
->count(),
|
||||
'published' => $draw->resultBatches()
|
||||
->where('status', DrawResultBatchStatus::Published->value)
|
||||
->count(),
|
||||
];
|
||||
$admin = $request->lotteryAdmin();
|
||||
abort_if($admin === null, 401);
|
||||
|
||||
return ApiResponse::success([
|
||||
'id' => (int) $draw->id,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'business_date' => $draw->business_date instanceof Carbon
|
||||
? $draw->business_date->format('Y-m-d')
|
||||
: (string) $draw->business_date,
|
||||
'sequence_no' => (int) $draw->sequence_no,
|
||||
/** 数据库当期状态(权威) */
|
||||
'status' => $draw->status,
|
||||
/** 与玩家大厅 snapshot 对齐的展示态(未跑 tick 时可能与 status 不一致) */
|
||||
'hall_preview_status' => $this->hallPreview->effectiveHallDisplayStatus($draw, $nowUtc),
|
||||
'start_time' => $draw->start_time?->toIso8601String(),
|
||||
'close_time' => $draw->close_time?->toIso8601String(),
|
||||
'draw_time' => $draw->draw_time?->toIso8601String(),
|
||||
'cooling_end_time' => $draw->cooling_end_time?->toIso8601String(),
|
||||
'result_source' => $draw->result_source,
|
||||
'current_result_version' => (int) $draw->current_result_version,
|
||||
'settle_version' => (int) $draw->settle_version,
|
||||
'is_reopened' => (bool) $draw->is_reopened,
|
||||
'created_at' => $draw->created_at?->toIso8601String(),
|
||||
'updated_at' => $draw->updated_at?->toIso8601String(),
|
||||
'result_batch_counts' => $batchCounts,
|
||||
]);
|
||||
return ApiResponse::success(
|
||||
AdminDrawApiPresenter::show($draw, $admin, $this->hallPreview),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user