New admin triggers for db maintenance, updating display of prize results and logic fix

This commit is contained in:
2025-03-28 22:52:54 +00:00
parent 593dbb598e
commit 322b4877ed
8 changed files with 269 additions and 21 deletions

View File

@@ -1,24 +1,46 @@
package matcher
import (
"database/sql"
"fmt"
"synlotto-website/helpers"
"synlotto-website/models"
thunderballRules "synlotto-website/rules"
)
func MatchTicketToDraw(ticket models.MatchTicket, draw models.DrawResult, rules []models.PrizeRule) models.MatchResult {
func MatchTicketToDraw(ticket models.MatchTicket, draw models.DrawResult, rules []models.PrizeRule, db *sql.DB) models.MatchResult {
mainMatches := helpers.CountMatches(ticket.Balls, draw.Balls)
bonusMatches := helpers.CountMatches(ticket.BonusBalls, draw.BonusBalls)
prizeTier := getPrizeTier(ticket.GameType, mainMatches, bonusMatches, rules)
isWinner := prizeTier != ""
return models.MatchResult{
result := models.MatchResult{
MatchedDrawID: draw.DrawID,
MatchedMain: mainMatches,
MatchedBonus: bonusMatches,
PrizeTier: prizeTier,
IsWinner: isWinner,
}
if ticket.GameType == "Thunderball" && isWinner {
if idx, ok := thunderballRules.GetThunderballPrizeIndex(mainMatches, bonusMatches); ok {
query := fmt.Sprintf(`SELECT prize%d_per_winner FROM prizes_thunderball WHERE draw_date = ?`, idx)
var amount int
err := db.QueryRow(query, draw.DrawDate).Scan(&amount)
if err == nil {
result.PrizeAmount = float64(amount)
if amount == 0 {
result.PrizeLabel = "Free Ticket"
} else {
result.PrizeLabel = fmt.Sprintf("£%.2f", float64(amount))
}
}
}
}
return result
}
func getPrizeTier(game string, main, bonus int, rules []models.PrizeRule) string {