- Draw相关控制器添加provider_code和provider_name字段支持 - 允许手动录入开奖批次时指定provider_code - RNG开奖批次生成支持多provider,分别生成对应批次数据 - DrawPublishService和DrawManualResultService中支持基于provider_code管理开奖版本和发布流程 - DrawResultViewService调整,支持按provider汇总及筛选开奖结果 - Settlement处理逻辑调整,按provider区分待结算票据及批次,分开结算 - 结算期间管理相关服务支持使用站点本地结算时区计算开账建议和日期处理 - 增加AdminSite的settlement_timezone字段及相关请求验证和数据存取支持 - 优化AdminSettlementPeriod相关代码,防止存在未结清票据时关账 - Ticket明细返回接口添加结算时区信息,提升用户时间体验 - 多处查询排序和版本号处理改进,保证多provider数据正确顺序与一致性
141 lines
5.5 KiB
PHP
141 lines
5.5 KiB
PHP
<?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,
|
|
'provider_code' => $batch->provider_code,
|
|
'provider_name' => $batch->provider_name,
|
|
'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;
|
|
}
|
|
}
|