feat: 增强代理和玩家管理功能
- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
This commit is contained in:
138
app/Support/AdminDrawApiPresenter.php
Normal file
138
app/Support/AdminDrawApiPresenter.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Draw;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\DrawResultItem;
|
||||
use App\Models\DrawResultBatch;
|
||||
use App\Lottery\DrawResultBatchStatus;
|
||||
use App\Services\Draw\DrawHallSnapshotBuilder;
|
||||
|
||||
final class AdminDrawApiPresenter
|
||||
{
|
||||
/**
|
||||
* @param array{total_bet_minor: int, total_payout_minor: int, profit_loss_minor: int}|null $stats
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public static function listRow(Draw $draw, ?array $stats, AdminUser $admin): array
|
||||
{
|
||||
$manage = AdminDrawResponsePolicy::canManageDrawResults($admin);
|
||||
$finance = AdminDrawResponsePolicy::canViewDrawFinance($admin);
|
||||
|
||||
$row = [
|
||||
'id' => (int) $draw->id,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'business_date' => self::formatBusinessDate($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(),
|
||||
'updated_at' => $draw->updated_at?->toIso8601String(),
|
||||
];
|
||||
|
||||
if ($manage) {
|
||||
$row['result_source'] = $draw->result_source;
|
||||
$row['current_result_version'] = (int) $draw->current_result_version;
|
||||
$row['settle_version'] = (int) $draw->settle_version;
|
||||
$row['is_reopened'] = (bool) $draw->is_reopened;
|
||||
}
|
||||
|
||||
if ($finance && $stats !== null) {
|
||||
$row['total_bet_minor'] = $stats['total_bet_minor'];
|
||||
$row['total_payout_minor'] = $stats['total_payout_minor'];
|
||||
$row['profit_loss_minor'] = $stats['profit_loss_minor'];
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public static function show(Draw $draw, AdminUser $admin, DrawHallSnapshotBuilder $hallPreview): array
|
||||
{
|
||||
$manage = AdminDrawResponsePolicy::canManageDrawResults($admin);
|
||||
$nowUtc = now()->utc();
|
||||
|
||||
$batchCounts = [
|
||||
'published' => $draw->resultBatches()
|
||||
->where('status', DrawResultBatchStatus::Published->value)
|
||||
->count(),
|
||||
];
|
||||
|
||||
if ($manage) {
|
||||
$batchCounts['total'] = $draw->resultBatches()->count();
|
||||
$batchCounts['pending_review'] = $draw->resultBatches()
|
||||
->where('status', DrawResultBatchStatus::PendingReview->value)
|
||||
->count();
|
||||
}
|
||||
|
||||
$payload = [
|
||||
'id' => (int) $draw->id,
|
||||
'draw_no' => $draw->draw_no,
|
||||
'business_date' => self::formatBusinessDate($draw->business_date),
|
||||
'sequence_no' => (int) $draw->sequence_no,
|
||||
'status' => $draw->status,
|
||||
'hall_preview_status' => $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_batch_counts' => $batchCounts,
|
||||
'capabilities' => AdminDrawResponsePolicy::capabilities($admin),
|
||||
];
|
||||
|
||||
if ($manage) {
|
||||
$payload['result_source'] = $draw->result_source;
|
||||
$payload['current_result_version'] = (int) $draw->current_result_version;
|
||||
$payload['settle_version'] = (int) $draw->settle_version;
|
||||
$payload['is_reopened'] = (bool) $draw->is_reopened;
|
||||
$payload['created_at'] = $draw->created_at?->toIso8601String();
|
||||
$payload['updated_at'] = $draw->updated_at?->toIso8601String();
|
||||
}
|
||||
|
||||
return $payload;
|
||||
}
|
||||
|
||||
/** @return array<string, mixed> */
|
||||
public static function resultBatch(DrawResultBatch $batch, AdminUser $admin): array
|
||||
{
|
||||
$manage = AdminDrawResponsePolicy::canManageDrawResults($admin);
|
||||
|
||||
$row = [
|
||||
'id' => (int) $batch->id,
|
||||
'result_version' => (int) $batch->result_version,
|
||||
'status' => $batch->status,
|
||||
'confirmed_at' => $batch->confirmed_at?->toIso8601String(),
|
||||
'items' => $batch->items->map(static fn (DrawResultItem $item): array => [
|
||||
'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(),
|
||||
];
|
||||
|
||||
if ($manage) {
|
||||
$row['source_type'] = $batch->source_type;
|
||||
$row['rng_seed_hash'] = $batch->rng_seed_hash;
|
||||
$row['created_by'] = $batch->created_by;
|
||||
$row['confirmed_by'] = $batch->confirmed_by;
|
||||
$row['created_at'] = $batch->created_at?->toIso8601String();
|
||||
$row['updated_at'] = $batch->updated_at?->toIso8601String();
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
private static function formatBusinessDate(mixed $businessDate): string
|
||||
{
|
||||
return $businessDate instanceof Carbon
|
||||
? $businessDate->format('Y-m-d')
|
||||
: (string) $businessDate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user