feat: 添加结算功能,更新 TicketItem 模型以支持最新结算详情,增强 DrawTickService 以自动处理结算,更新 TicketWalletService 以支持派彩入账,扩展 API 路由以管理结算批次和奖池

This commit is contained in:
2026-05-11 15:34:34 +08:00
parent 6a55fa9592
commit 19003f5041
50 changed files with 3604 additions and 3 deletions

View File

@@ -0,0 +1,59 @@
<?php
namespace App\Services\Settlement\Matchers;
use App\Models\TicketCombination;
use App\Models\TicketItem;
use App\Services\Settlement\Contracts\SettlementPlayMatcher;
use App\Services\Settlement\OddsSnapshotReader;
use App\Services\Settlement\PublishedDrawResultBoard;
use Illuminate\Support\Collection;
/**
* Big / 包号展开类:命中 23 档中**最优档**计奖(产品文档 Big / iBox / mBox / Box
*/
final class BigSpreadSettlementMatcher implements SettlementPlayMatcher
{
public function __construct(
private readonly OddsSnapshotReader $odds,
) {}
public function match(TicketItem $item, PublishedDrawResultBoard $board, Collection $combinations): array
{
$snapshot = is_array($item->odds_snapshot_json) ? $item->odds_snapshot_json : null;
$lines = [];
$total = 0;
$bestTier = null;
$bestRank = 99;
foreach ($combinations as $c) {
/** @var TicketCombination $c */
$hit = $board->bestTierForNumber((string) $c->number_4d);
if ($hit === null) {
continue;
}
$tier = $hit['tier'];
$oddsVal = $this->odds->oddsValueForScope($snapshot, $tier);
$bet = (int) $c->bet_amount;
$payout = (int) floor($bet * ($oddsVal / 10_000));
$total += $payout;
$lines[] = [
'number_4d' => $c->number_4d,
'matched_tier' => $tier,
'bet_amount' => $bet,
'odds_value' => $oddsVal,
'payout' => $payout,
];
if ($hit['rank'] < $bestRank) {
$bestRank = $hit['rank'];
$bestTier = $tier;
}
}
return [
'win_amount' => $total,
'matched_prize_tier' => $bestTier,
'match_detail' => ['lines' => $lines],
];
}
}