feat(draw): 支持多玩法provider及本地化结算时区功能
- Draw相关控制器添加provider_code和provider_name字段支持 - 允许手动录入开奖批次时指定provider_code - RNG开奖批次生成支持多provider,分别生成对应批次数据 - DrawPublishService和DrawManualResultService中支持基于provider_code管理开奖版本和发布流程 - DrawResultViewService调整,支持按provider汇总及筛选开奖结果 - Settlement处理逻辑调整,按provider区分待结算票据及批次,分开结算 - 结算期间管理相关服务支持使用站点本地结算时区计算开账建议和日期处理 - 增加AdminSite的settlement_timezone字段及相关请求验证和数据存取支持 - 优化AdminSettlementPeriod相关代码,防止存在未结清票据时关账 - Ticket明细返回接口添加结算时区信息,提升用户时间体验 - 多处查询排序和版本号处理改进,保证多provider数据正确顺序与一致性
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services\Draw;
|
||||
|
||||
use App\Models\Draw;
|
||||
use App\Models\AdminUser;
|
||||
use App\Models\BetProvider;
|
||||
use App\Lottery\DrawStatus;
|
||||
use App\Models\DrawResultItem;
|
||||
use App\Models\DrawResultBatch;
|
||||
@@ -16,9 +17,9 @@ final class DrawManualResultService
|
||||
/**
|
||||
* @param list<array{prize_type: string, prize_index: int, number_4d: string}> $items
|
||||
*/
|
||||
public function createPendingBatch(Draw $draw, AdminUser $admin, array $items): DrawResultBatch
|
||||
public function createPendingBatch(Draw $draw, AdminUser $admin, array $items, ?string $providerCode = null): DrawResultBatch
|
||||
{
|
||||
return DB::transaction(function () use ($draw, $admin, $items): DrawResultBatch {
|
||||
return DB::transaction(function () use ($draw, $admin, $items, $providerCode): DrawResultBatch {
|
||||
/** @var Draw $locked */
|
||||
$locked = Draw::query()->whereKey($draw->id)->lockForUpdate()->firstOrFail();
|
||||
if (! in_array($locked->status, [DrawStatus::Closed->value, DrawStatus::Review->value], true)) {
|
||||
@@ -28,16 +29,34 @@ final class DrawManualResultService
|
||||
throw new \RuntimeException('draw_already_settled');
|
||||
}
|
||||
|
||||
$providerCode = strtoupper(trim((string) ($providerCode ?: BetProvider::DEFAULT_CODE)));
|
||||
/** @var BetProvider|null $provider */
|
||||
$provider = BetProvider::query()
|
||||
->where('code', $providerCode)
|
||||
->where('is_enabled', true)
|
||||
->first();
|
||||
if ($provider === null && $providerCode !== BetProvider::DEFAULT_CODE) {
|
||||
throw new \RuntimeException('bet_provider_not_found');
|
||||
}
|
||||
$providerName = $provider?->name ?? 'Singapore';
|
||||
|
||||
if (DrawResultBatch::query()
|
||||
->where('draw_id', $locked->id)
|
||||
->where('provider_code', $providerCode)
|
||||
->where('status', DrawResultBatchStatus::PendingReview->value)
|
||||
->exists()) {
|
||||
throw new \RuntimeException('draw_pending_result_batch_exists');
|
||||
}
|
||||
|
||||
$nextVersion = max(1, (int) $locked->current_result_version + 1);
|
||||
$latestVersion = (int) DrawResultBatch::query()
|
||||
->where('draw_id', $locked->id)
|
||||
->where('provider_code', $providerCode)
|
||||
->max('result_version');
|
||||
$nextVersion = max(1, $latestVersion + 1);
|
||||
$batch = DrawResultBatch::query()->create([
|
||||
'draw_id' => $locked->id,
|
||||
'provider_code' => $providerCode,
|
||||
'provider_name' => $providerName,
|
||||
'result_version' => $nextVersion,
|
||||
'source_type' => DrawResultSourceType::Manual->value,
|
||||
'rng_seed_hash' => null,
|
||||
|
||||
Reference in New Issue
Block a user