Files
lotteryLaravel/app/Services/Settlement/Matchers/Pos3TierSettlementMatcher.php
kang cbb18b976f
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
lotterLaravel E2E / e2e-api (push) Has been cancelled
feat(lottery): 扩展传统马来赔率、玩法结算与开注商短码支持
2026-07-10 17:04:28 +08:00

59 lines
2.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Services\Settlement\Matchers;
use App\Models\TicketItem;
use Illuminate\Support\Collection;
use App\Services\Settlement\OddsSnapshotReader;
use App\Services\Settlement\PublishedDrawResultBoard;
use App\Services\Settlement\Contracts\SettlementPlayMatcher;
/** pos_3a / pos_3b / pos_3c后三位命中对应档。头奖命中时 `matched_prize_tier` 为 firstJackpot 口径)。 */
final class Pos3TierSettlementMatcher implements SettlementPlayMatcher
{
/** @var array<string, string> */
private const PLAY_TO_TIER = [
'pos_3a' => 'first',
'pos_3b' => 'second',
'pos_3c' => 'third',
'pos_3d' => 'starter',
'pos_3e' => 'consolation',
];
public function __construct(
private readonly OddsSnapshotReader $odds,
) {}
public function match(TicketItem $item, PublishedDrawResultBoard $board, Collection $combinations): array
{
$tier = self::PLAY_TO_TIER[$item->play_code] ?? 'first';
$suffix = $board->suffix3ForTier($tier, 0);
if ($suffix === '') {
return ['win_amount' => 0, 'matched_prize_tier' => null, 'match_detail' => ['reason' => 'no_suffix']];
}
$snapshot = is_array($item->odds_snapshot_json) ? $item->odds_snapshot_json : null;
$oddsVal = $this->odds->oddsValueForScope($snapshot, $tier);
$lines = [];
$total = 0;
if (substr((string) $item->normalized_number, -3) === $suffix) {
$bet = (int) $item->unit_bet_amount;
$total = (int) floor($bet * ($oddsVal / 10_000));
$lines[] = [
'number' => $item->original_number,
'suffix3' => $suffix,
'bet_amount' => $bet,
'odds_value' => $oddsVal,
'payout' => $total,
];
}
return [
'win_amount' => $total,
'matched_prize_tier' => $total > 0 ? $tier : null,
'match_detail' => ['lines' => $lines],
];
}
}