$bestProfit) { $bestProfit = $profit; $bestResult = $result; } } return $bestResult; } public static function checkWin(array $result, string $betType, string $betTarget): bool { $redCount = count(array_filter($result, fn($c) => $c === 'red')); switch ($betTarget) { case 'even': return ($redCount % 2 === 0); case 'odd': return ($redCount % 2 === 1); case '4red': return ($redCount === 4); case '4white': return ($redCount === 0); case '3red1white': return ($redCount === 3); case '1red3white': return ($redCount === 1); default: return false; } } public static function calculatePlatformProfit(array $result, array $bets): float { $totalBet = 0; $totalPayout = 0; foreach ($bets as $bet) { $amount = (float)$bet['amount']; $totalBet += $amount; if (self::checkWin($result, $bet['bet_type'], $bet['bet_target'] ?? $bet['bet_value'] ?? '')) { $totalPayout += $amount + $amount * (float)$bet['odds']; } } return $totalBet - $totalPayout; } public static function getResultTable(): ?string { return null; } public static function formatResultForStorage(array $result, int $periodId): array { $redCount = count(array_filter($result, fn($c) => $c === 'red')); return [ 'dice1' => ($result[0] === 'red') ? 1 : 0, 'dice2' => ($result[1] === 'red') ? 1 : 0, 'dice3' => ($result[2] === 'red') ? 1 : 0, 'total' => $redCount, ]; } public static function parseResultFromDb(array $row): array { return [ ((int)($row['dice1'] ?? 0)) ? 'red' : 'white', ((int)($row['dice2'] ?? 0)) ? 'red' : 'white', ((int)($row['dice3'] ?? 0)) ? 'red' : 'white', // 第4个硬币从 result JSON 恢复,或根据 total 推断 'white', // fallback ]; } }