Files
lotteryLaravel/app/Services/Settlement/Matchers/StraightLikeSettlementMatcher.php

58 lines
1.9 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\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;
/**
* 直选类:仅与**头奖**号码完全一致中奖(产品文档 Straight / 头奖口径)。
*
* 适用于 `straight`、`roll`(组合已展开为多条 4D
*/
final class StraightLikeSettlementMatcher implements SettlementPlayMatcher
{
public function __construct(
private readonly OddsSnapshotReader $odds,
) {}
public function match(TicketItem $item, PublishedDrawResultBoard $board, Collection $combinations): array
{
$target = $board->firstPrizeNumber4d();
if ($target === '') {
return ['win_amount' => 0, 'matched_prize_tier' => null, 'match_detail' => ['reason' => 'no_first_prize']];
}
$snapshot = is_array($item->odds_snapshot_json) ? $item->odds_snapshot_json : null;
$oddsVal = $this->odds->oddsValueForScope($snapshot, 'first');
$lines = [];
$total = 0;
foreach ($combinations as $c) {
/** @var TicketCombination $c */
if ((string) $c->number_4d !== $target) {
continue;
}
$bet = (int) $c->bet_amount;
$payout = (int) floor($bet * ($oddsVal / 10_000));
$total += $payout;
$lines[] = [
'number_4d' => $c->number_4d,
'bet_amount' => $bet,
'odds_value' => $oddsVal,
'payout' => $payout,
];
}
return [
'win_amount' => $total,
'matched_prize_tier' => $total > 0 ? 'first' : null,
'match_detail' => ['lines' => $lines, 'first_prize' => $target],
];
}
}