diff --git a/tippspiel/public/index.php b/tippspiel/public/index.php index 88b1dab..c33829f 100644 --- a/tippspiel/public/index.php +++ b/tippspiel/public/index.php @@ -187,6 +187,10 @@ if ($page === 'reminder') { } $games = Game::getGamesByRound($round['id']); $error = null; + $jokerUsage = Tipp::formatJokerUsage( + Tipp::getJokerUsage($user['id'], $activeSeason['id'], null, $round['id']) + ); + $maxIdenticalJokertipps = (int)$activeSeason['max_identical_jokertipps']; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $jokerGameId = isset($_POST['joker']) && $_POST['joker'] !== '' ? (int)$_POST['joker'] : null; @@ -225,6 +229,10 @@ if ($page === 'reminder') { exit; } $error = null; + $jokerUsage = Tipp::formatJokerUsage( + Tipp::getJokerUsage($user['id'], $activeSeason['id'], null, $round['id']) + ); + $maxIdenticalJokertipps = (int)$activeSeason['max_identical_jokertipps']; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $error = Tipp::saveSingle($user['id'], $game['id'], $_POST['score1'] ?? '', $_POST['score2'] ?? '', isset($_POST['joker'])); if ($error === null) { @@ -248,6 +256,10 @@ if ($page === 'reminder') { $currentSeason = Season::getCurrent(); $payouts = $currentSeason ? Quota::computePayouts($currentSeason['id']) : null; $maxIdenticalJokertipps = (int)($currentSeason['max_identical_jokertipps'] ?? Season::DEFAULT_MAX_IDENTICAL_JOKERTIPPS); + $jackpot = $currentSeason ? (float)$currentSeason['jackpot'] : 0.0; + $jackpotStatus = $currentSeason + ? Ranking::getJackpotStatus($currentSeason['id']) + : ['won' => false, 'amount' => 0.0, 'perWinner' => 0.0, 'winners' => []]; require __DIR__ . '/../src/Views/info/guide.php'; } elseif ($page === 'guide_admin') { // Info -> Anleitung-Admin: Saison-/Quoten-Verwaltung (nur für Admins) @@ -261,6 +273,10 @@ if ($page === 'reminder') { $payouts = $currentSeason ? Quota::computePayouts($currentSeason['id']) : null; $activeUserCount = $currentSeason ? count(User::getPaid($currentSeason['id'])) : 0; $stake = $currentSeason ? (Quota::getMapBySeason($currentSeason['id'])['einsatz'] ?? 0) : 0; + $jackpot = $currentSeason ? (float)$currentSeason['jackpot'] : 0.0; + $jackpotStatus = $currentSeason + ? Ranking::getJackpotStatus($currentSeason['id']) + : ['won' => false, 'amount' => 0.0, 'perWinner' => 0.0, 'winners' => []]; require __DIR__ . '/../src/Views/info/quotas.php'; } elseif ($page === 'money_ranking') { // Info -> Geldrangliste (Legacy UsersController::money_ranking / money_ranking_detail) @@ -373,10 +389,12 @@ if ($page === 'reminder') { 'name' => trim($_POST['name'] ?? ''), 'rounds' => $_POST['rounds'] ?? '', 'max_identical_jokertipps' => $_POST['max_identical_jokertipps'] ?? '', + 'jackpot' => str_replace(',', '.', trim($_POST['jackpot'] ?? '')), ]; if ($data['name'] === '' || !ctype_digit((string)$data['rounds']) || (int)$data['rounds'] < 1 - || !ctype_digit((string)$data['max_identical_jokertipps'])) { - throw new \Exception('Name, Runden und maximale Anzahl gleicher Joker sind erforderlich.'); + || !ctype_digit((string)$data['max_identical_jokertipps']) + || !is_numeric($data['jackpot']) || (float)$data['jackpot'] < 0) { + throw new \Exception('Name, Runden, maximale Anzahl gleicher Joker und Jackpot sind erforderlich.'); } $quotasToSave = []; @@ -443,6 +461,7 @@ if ($page === 'reminder') { 'name' => $editSeason['name'] ?? '', 'rounds' => $template['rounds'] ?? 48, 'max_identical_jokertipps' => $template['max_identical_jokertipps'] ?? Season::DEFAULT_MAX_IDENTICAL_JOKERTIPPS, + 'jackpot' => $template['jackpot'] ?? Season::DEFAULT_JACKPOT, 'quotas' => array_merge(Quota::defaults(), $template ? Quota::getMapBySeason($template['id']) : []), ]; if ($editSeason) { @@ -583,11 +602,12 @@ if ($page === 'reminder') { } $sender = Auth::user(); + $currentSeason = Season::getCurrent(); $html = Roundmail::textToHtml($text); $failed = Mailer::send($recipients['valid'], $topic, $html, $sender['email'] ?? null); $sent = array_values(array_diff($recipients['valid'], $failed)); if (!empty($sent)) { - Roundmail::create((int)$sender['id'], $sent, $topic, $html); + Roundmail::create((int)$sender['id'], $sent, $topic, $html, $currentSeason ? (int)$currentSeason['id'] : 0); } $_SESSION['admin_message'] = 'Mail an ' . count($sent) . ' Empfänger versendet.'; @@ -788,10 +808,22 @@ if ($page === 'reminder') { $ranking = []; $games = []; $teamLogos = []; + $roundCompleted = false; + $isFinalRound = false; + $roundHasJackpot = false; if ($selectedRound) { $result = Ranking::compute($currentSeason['id'], $selectedRound['id']); $ranking = Ranking::roundTable($result); $games = $result['rounds'][$selectedRound['id']]['games'] ?? []; + $roundCompleted = (bool)($result['rounds'][$selectedRound['id']]['completed'] ?? false); + $isFinalRound = (bool)$result['is_final']; + $roundEntries = $result['rounds'][$selectedRound['id']]['entries'] ?? []; + foreach ($roundEntries as $entry) { + if (($entry['jackpot_payout'] ?? 0) > 0) { + $roundHasJackpot = true; + break; + } + } $teamIds = []; foreach ($games as $game) { diff --git a/tippspiel/src/Models/Ranking.php b/tippspiel/src/Models/Ranking.php index 9f6713c..54fb28f 100644 --- a/tippspiel/src/Models/Ranking.php +++ b/tippspiel/src/Models/Ranking.php @@ -47,6 +47,9 @@ class Ranking { $tippsByRound = self::loadTipps($seasonId, $maxRoundId); $payouts = Quota::computePayouts($seasonId); + $season = Season::findById($seasonId); + $jackpot = $season ? (float)$season['jackpot'] : 0.0; + $users = []; foreach (User::getPaid($seasonId) as $user) { $users[(int)$user['id']] = $user; @@ -56,6 +59,7 @@ class Ranking { $totals = array_fill_keys($userIds, 0); $rounds = []; $dayPrizePot = 0.0; + $jackpotAwarded = false; foreach ($allRounds as $round) { $roundId = (int)$round['id']; @@ -81,6 +85,8 @@ class Ranking { $entry['total'] = $totals[$userId]; $entry['is_day_winner'] = false; $entry['payout'] = 0.0; + $entry['is_jackpot_winner'] = false; + $entry['jackpot_payout'] = 0.0; $entries[$userId] = $entry; } @@ -96,6 +102,19 @@ class Ranking { } } + // Jackpot: einmal pro Saison, wenn alle Spiele der Runde exakt getippt wurden + if (!$jackpotAwarded && $completed && $jackpot > 0) { + $jackpotWinners = self::determineJackpotWinners($entries, count($games)); + if (!empty($jackpotWinners)) { + $perJackpot = round($jackpot / count($jackpotWinners), 2); + foreach ($jackpotWinners as $userId) { + $entries[$userId]['is_jackpot_winner'] = true; + $entries[$userId]['jackpot_payout'] = $perJackpot; + } + $jackpotAwarded = true; + } + } + $rounds[$roundId] = [ 'round' => $round, 'games' => $games, @@ -119,6 +138,7 @@ class Ranking { 'is_final' => $isFinal, 'ranking_payouts' => $isFinal ? self::computeRankingPayouts($ranks, $payouts) : [], 'payouts' => $payouts, + 'jackpot' => $jackpot, ]; } @@ -163,6 +183,8 @@ class Ranking { 'is_day_winner' => $entry['is_day_winner'], 'payout' => $entry['payout'], 'ranking_payout' => $result['ranking_payouts'][$userId] ?? 0, + 'is_jackpot_winner' => $entry['is_jackpot_winner'], + 'jackpot_payout' => $entry['jackpot_payout'], 'cells' => $cells, ]; } @@ -186,6 +208,12 @@ class Ranking { 'amount' => $entry['payout'], ]; } + if ($entry['jackpot_payout'] > 0) { + $items[$userId][] = [ + 'label' => $round['round']['name'] . ' (Jackpot)', + 'amount' => $entry['jackpot_payout'], + ]; + } } } @@ -201,6 +229,54 @@ class Ranking { return $items; } + /** + * Status des Saison-Jackpots: ob er bereits gewonnen wurde und von wem. + * Gewonnen ist er, sobald in einer abgeschlossenen Runde mindestens ein Spieler + * alle Spiele exakt getippt hat (einmal pro Saison). + * + * @param int $seasonId + * @return array ['won' => bool, 'amount' => float, 'perWinner' => float, 'winners' => string[]] + */ + public static function getJackpotStatus($seasonId) { + $season = Season::findById($seasonId); + $jackpot = $season ? (float)$season['jackpot'] : 0.0; + + if ($jackpot <= 0) { + return ['won' => false, 'amount' => $jackpot, 'perWinner' => 0.0, 'winners' => []]; + } + + $users = []; + foreach (User::getPaid($seasonId) as $user) { + $users[(int)$user['id']] = $user['name']; + } + + foreach (Round::getBySeason($seasonId) as $round) { + $games = Game::getGamesByRound($round['id']); + if (empty($games) || !Round::isCompleted($games)) { + continue; + } + $gameCount = count($games); + $tippsByUser = Tipp::findByRound($round['id']); + $winners = []; + foreach ($users as $userId => $name) { + $entry = Tipp::evaluateRound($games, $tippsByUser[$userId] ?? []); + if ($entry['exact'] === $gameCount) { + $winners[] = $name; + } + } + if (!empty($winners)) { + return [ + 'won' => true, + 'amount' => $jackpot, + 'perWinner' => round($jackpot / count($winners), 2), + 'winners' => $winners, + ]; + } + } + + return ['won' => false, 'amount' => $jackpot, 'perWinner' => 0.0, 'winners' => []]; + } + /** * Wertung für Geldrangliste und Kontoliste (Legacy UsersController::money_ranking): * gerechnet wird bis zur letzten gesperrten Runde, angezeigt erst, wenn mindestens @@ -292,6 +368,23 @@ class Ranking { return $winners; } + /** + * Jackpot-Gewinner einer Runde: Spieler, die alle Spiele exakt getippt haben. + * + * @param array $entries user_id => Auswertung (Tipp::evaluateRound) + * @param int $gameCount Anzahl der Spiele der Runde + * @return array user_ids + */ + private static function determineJackpotWinners(array $entries, $gameCount) { + if ($gameCount <= 0) { + return []; + } + return array_keys(array_filter( + $entries, + fn($entry) => $entry['exact'] === $gameCount + )); + } + /** * Ränge nach Gesamtpunkten (geteilte Ränge bei Gleichstand), bei Gleichstand nach Name sortiert. * diff --git a/tippspiel/src/Models/Roundmail.php b/tippspiel/src/Models/Roundmail.php index ed0ad8a..bb11bdc 100644 --- a/tippspiel/src/Models/Roundmail.php +++ b/tippspiel/src/Models/Roundmail.php @@ -47,9 +47,12 @@ class Roundmail { */ public static function getPage($limit, $offset, $excludeReminders = false) { $db = Database::getConnection(); - $sql = "SELECT m.id, m.send_date, m.topic, m.recipients, COALESCE(u.name, 'Automailer') AS sender_name + $sql = "SELECT m.id, m.send_date, m.topic, m.recipients, m.season_id, + COALESCE(u.name, 'Automailer') AS sender_name, + s.name AS season_name FROM roundmails m - LEFT JOIN users u ON u.id = m.user_id"; + LEFT JOIN users u ON u.id = m.user_id + LEFT JOIN seasons s ON s.id = m.season_id"; if ($excludeReminders) { $sql .= " WHERE m.topic <> :topic"; } @@ -72,9 +75,10 @@ class Roundmail { public static function findById($id) { $db = Database::getConnection(); $stmt = $db->prepare( - "SELECT m.*, COALESCE(u.name, 'Automailer') AS sender_name + "SELECT m.*, COALESCE(u.name, 'Automailer') AS sender_name, s.name AS season_name FROM roundmails m LEFT JOIN users u ON u.id = m.user_id + LEFT JOIN seasons s ON s.id = m.season_id WHERE m.id = ?" ); $stmt->execute([$id]); @@ -88,15 +92,16 @@ class Roundmail { * @param string[] $recipients * @param string $topic * @param string $messageHtml + * @param int $seasonId Zugeordnete Saison (0 = keine/ohne Saisonbezug) * @return int ID */ - public static function create($userId, array $recipients, $topic, $messageHtml) { + public static function create($userId, array $recipients, $topic, $messageHtml, $seasonId = 0) { $db = Database::getConnection(); $stmt = $db->prepare( - "INSERT INTO roundmails (user_id, send_date, recipients, topic, message, created_at, updated_at) - VALUES (?, CURDATE(), ?, ?, ?, NOW(), NOW())" + "INSERT INTO roundmails (user_id, season_id, send_date, recipients, topic, message, created_at, updated_at) + VALUES (?, ?, CURDATE(), ?, ?, ?, NOW(), NOW())" ); - $stmt->execute([$userId, implode(',', $recipients), $topic, $messageHtml]); + $stmt->execute([$userId, (int)$seasonId, implode(',', $recipients), $topic, $messageHtml]); return (int)$db->lastInsertId(); } @@ -224,7 +229,7 @@ class Roundmail { $failed = Mailer::send($recipients, $topic, $html); $sent = array_values(array_diff($recipients, $failed)); if (!empty($sent)) { - self::create(0, $sent, $topic, $html); + self::create(0, $sent, $topic, $html, (int)$season['id']); } $result = sprintf('%s: Erinnerung an %d Empfänger versendet.', $round['name'], count($sent)); diff --git a/tippspiel/src/Models/Season.php b/tippspiel/src/Models/Season.php index df332b2..b7bbc5c 100644 --- a/tippspiel/src/Models/Season.php +++ b/tippspiel/src/Models/Season.php @@ -9,6 +9,9 @@ class Season { /** Legacy-Default für seasons.max_identical_jokertipps */ const DEFAULT_MAX_IDENTICAL_JOKERTIPPS = 6; + /** Default für seasons.jackpot (in Euro) */ + const DEFAULT_JACKPOT = 0; + /** Jede Runde besteht aus 4 Spielen (Legacy-Konvention) */ const GAMES_PER_ROUND = 4; @@ -67,25 +70,29 @@ class Season { * * Tipps werden NICHT vorab angelegt - sie entstehen beim ersten Tippen (siehe Tipp::saveRound). * - * @param array $data ['name', 'rounds', optional 'max_identical_jokertipps'] + * @param array $data ['name', 'rounds', optional 'max_identical_jokertipps', 'jackpot'] * @return int|false Die ID der neuen Saison oder false bei einem Fehler. */ public static function create($data) { $db = Database::getConnection(); $roundCount = (int)$data['rounds']; $maxJoker = (int)($data['max_identical_jokertipps'] ?? self::DEFAULT_MAX_IDENTICAL_JOKERTIPPS); + $jackpot = isset($data['jackpot']) && is_numeric($data['jackpot']) + ? (float)$data['jackpot'] + : self::DEFAULT_JACKPOT; $db->beginTransaction(); try { $stmt = $db->prepare( - "INSERT INTO seasons (name, rounds, max_identical_jokertipps, created_at, updated_at) - VALUES (:name, :rounds, :max_joker, NOW(), NOW())" + "INSERT INTO seasons (name, rounds, max_identical_jokertipps, jackpot, created_at, updated_at) + VALUES (:name, :rounds, :max_joker, :jackpot, NOW(), NOW())" ); $stmt->execute([ ':name' => $data['name'], ':rounds' => $roundCount, ':max_joker' => $maxJoker, + ':jackpot' => $jackpot, ]); $seasonId = (int)$db->lastInsertId(); @@ -128,7 +135,7 @@ class Season { * Hinweis: Eine Änderung von 'rounds' legt keine Runden an oder löscht welche. * * @param int $id - * @param array $data ['name', 'rounds', optional 'max_identical_jokertipps'] + * @param array $data ['name', 'rounds', optional 'max_identical_jokertipps', 'jackpot'] * @return bool */ public static function update($id, $data) { @@ -146,6 +153,11 @@ class Season { $params[':max_joker'] = (int)$data['max_identical_jokertipps']; } + if (isset($data['jackpot'])) { + $sql .= ", jackpot = :jackpot"; + $params[':jackpot'] = (float)$data['jackpot']; + } + $sql .= " WHERE id = :id"; $stmt = $db->prepare($sql); return $stmt->execute($params); @@ -153,7 +165,7 @@ class Season { /** * Löscht eine Saison mit allen abhängigen Daten (Tipps, Spiele, Runden, - * Quoten, Zahlungen, manuelle Ausschüttungen). Die aktive Saison kann nicht gelöscht werden. + * Quoten, Zahlungen, manuelle Ausschüttungen, Rundmails). Die aktive Saison kann nicht gelöscht werden. * * @param int $id * @throws \Exception wenn die Saison aktiv ist oder nicht existiert @@ -178,6 +190,7 @@ class Season { "DELETE FROM quotas WHERE season_id = ?", "DELETE FROM payments WHERE season_id = ?", "DELETE FROM manual_payouts WHERE season_id = ?", + "DELETE FROM roundmails WHERE season_id = ?", "DELETE FROM seasons WHERE id = ?", ]; foreach ($statements as $sql) { diff --git a/tippspiel/src/Views/admin/roundmails.php b/tippspiel/src/Views/admin/roundmails.php index b8304f8..157330a 100644 --- a/tippspiel/src/Views/admin/roundmails.php +++ b/tippspiel/src/Views/admin/roundmails.php @@ -89,6 +89,7 @@ $reminderParam = ($excludeReminders ?? false) ? '&hide_reminders=1' : ''; +
Datum
Versender
Saison
Empfänger
Nachricht
@@ -109,6 +110,7 @@ $reminderParam = ($excludeReminders ?? false) ? '&hide_reminders=1' : ''; Datum Thema + Saison Versender Empfänger @@ -118,12 +120,13 @@ $reminderParam = ($excludeReminders ?? false) ? '&hide_reminders=1' : ''; + - Noch keine Mails versendet. + Noch keine Mails versendet. diff --git a/tippspiel/src/Views/admin/seasons.php b/tippspiel/src/Views/admin/seasons.php index 653bec4..d204fbc 100644 --- a/tippspiel/src/Views/admin/seasons.php +++ b/tippspiel/src/Views/admin/seasons.php @@ -24,19 +24,16 @@ require __DIR__ . '/../partials/header.php';
- - +
- - + (Runden werden nur beim Anlegen erzeugt; eine Änderung legt keine Runden an oder löscht welche.)
- - +
'; echo ''; - echo ' ' . $unit; if ($amount !== null) { echo ' = ' . number_format($amount, 2, ',', '.') . ' €'; @@ -60,6 +57,11 @@ require __DIR__ . '/../partials/header.php'; Beträge berechnet aus den gespeicherten Quoten.

+

Jackpot (4-Spiele Treffer)

+
+ € +
+

Spielquoten

.season-centered { text-align: center; } -.season-centered form { display: inline-block; text-align: left; } +.season-centered form { display: block; max-width: 480px; margin: 0 auto; text-align: left; } .season-centered form h2 { text-align: center; } .season-centered table { margin: 1em auto 0; text-align: left; } /* From users.php, for consistency */ diff --git a/tippspiel/src/Views/info/guide.php b/tippspiel/src/Views/info/guide.php index 8e4c29c..3318ec6 100644 --- a/tippspiel/src/Views/info/guide.php +++ b/tippspiel/src/Views/info/guide.php @@ -23,6 +23,7 @@ $exactExamples = ['1:0', '2:1', '2:2', '3:1', '3:2', '4:2', '5:3']; Punkte Rangliste Tagessieg + Jackpot Gewinne Als App installieren @@ -127,7 +128,16 @@ Dasselbe Ergebnis darfst du pro Saison höchstens
  • Hat niemand ein exaktes Ergebnis getroffen, gibt es keinen Tagessieger. Der Betrag wandert in die nächste Runde, in der es einen Tagessieger gibt.
  • -

    6. Gewinne

    +

    6. Jackpot

    + + +

    7. Gewinne

    -

    7. Als App installieren

    +

    8. Als App installieren

    Das Tippspiel kannst du dir wie eine App auf den Startbildschirm deines Smartphones legen. Sie öffnet sich dann im Vollbild mit eigenem Symbol – ohne Adressleiste des Browsers. Der eigentliche Inhalt ist identisch mit der Webseite, und es funktioniert weiterhin nur mit Internetverbindung.

    Android (Chrome)

    diff --git a/tippspiel/src/Views/info/quotas.php b/tippspiel/src/Views/info/quotas.php index 423ebb0..43ee09a 100644 --- a/tippspiel/src/Views/info/quotas.php +++ b/tippspiel/src/Views/info/quotas.php @@ -23,6 +23,16 @@ $euro = fn($amount) => number_format($amount, 2, ',', '.') . ' €'; +
    +

    Jackpot

    + + + + + +
    Jackpot (4-Spiele Treffer)
    Gewonnen von
    +
    +

    Spielquoten

    diff --git a/tippspiel/src/Views/ranking.php b/tippspiel/src/Views/ranking.php index c85767b..244d705 100644 --- a/tippspiel/src/Views/ranking.php +++ b/tippspiel/src/Views/ranking.php @@ -70,6 +70,10 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR font-size: 2rem; /* Größe verdoppeln */ vertical-align: middle; } + .jackpot-icon { + font-size: 1.6rem; + vertical-align: middle; + } #round_id { font-size: inherit; /* Schriftgröße an die Umgebung anpassen */ } @@ -116,6 +120,7 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR .legend.legend-footer .legend-color { width: 12px; height: 12px; } .legend.legend-footer .joker-icon { width: 1.1em; height: 1.1em; } .legend.legend-footer .daily-winner-icon { font-size: 1em; } + .legend.legend-footer .jackpot-icon { font-size: 1em; } /* Rundenpunkte als Link mit Aufschlüsselungs-Popup */ .round-points-link { @@ -223,6 +228,18 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR Joker + + + + + + + + + @@ -280,6 +297,15 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR + + + + + + + + + @@ -295,6 +321,15 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR + + + + + + + + +
    Preisgeld Tagessieg + 💰 + Jackpot + Preisgeld Platzierung
    0 ? number_format($entry['payout'], 2, ',', '.') . ' €' : ''; ?> 0 ? '💰 ' . number_format($entry['jackpot_payout'], 2, ',', '.') . ' €' : ''; ?> 0 ? number_format($entry['ranking_payout'], 2, ',', '.') . ' €' : ''; ?>
    -1) ? (int)$game['score2'] : ''; ?>
    @@ -304,6 +339,9 @@ if (!isset($currentSeason) || !isset($ranking) || !isset($games) || !isset($allR