mirror of
https://github.com/prosolis/gogobee.git
synced 2026-07-16 08:52:42 +00:00
Fix streak grace period, UNO earnings, hospital UX, wordle/lottery atomicity
- Streak grace now checks LastDeathDate instead of LastActionDate (was suppressing streak updates for all active players) - UNO single-player earnings use net payout (minus wager) not gross - Hospital sends error message on save failure instead of silent no-op - Wordle total_earned update moved into stats transaction - Lottery ticket inserts + community pot add wrapped in single transaction with euro refund on failure - Lottery fixed-tier ticket prize updated with actual prorated amount - Added last_death_date column to adventure_characters Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -64,18 +64,37 @@ func lotteryTotalTicketCount(weekStart string) int {
|
||||
return count
|
||||
}
|
||||
|
||||
func lotteryInsertTickets(userID id.UserID, weekStart string, tickets [][]int) {
|
||||
func lotteryInsertTickets(userID id.UserID, weekStart string, tickets [][]int) error {
|
||||
d := db.Get()
|
||||
tx, err := d.Begin()
|
||||
if err != nil {
|
||||
slog.Error("lottery: begin tx", "err", err)
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
|
||||
for _, nums := range tickets {
|
||||
data, _ := json.Marshal(nums)
|
||||
_, err := d.Exec(`INSERT INTO lottery_tickets (user_id, week_start, numbers) VALUES (?, ?, ?)`,
|
||||
_, err := tx.Exec(`INSERT INTO lottery_tickets (user_id, week_start, numbers) VALUES (?, ?, ?)`,
|
||||
string(userID), weekStart, string(data))
|
||||
if err != nil {
|
||||
slog.Error("lottery: failed to insert ticket", "user", userID, "err", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Each ticket costs €1 — add to community pot.
|
||||
communityPotAdd(len(tickets))
|
||||
|
||||
// Each ticket costs €1 — add to community pot (same transaction).
|
||||
_, err = tx.Exec(
|
||||
`INSERT INTO community_pot (id, balance, updated_at)
|
||||
VALUES (1, ?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(id) DO UPDATE SET balance = balance + ?, updated_at = CURRENT_TIMESTAMP`,
|
||||
len(tickets), len(tickets))
|
||||
if err != nil {
|
||||
slog.Error("lottery: failed to add to community pot", "err", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
func lotteryLoadUserTickets(userID id.UserID, weekStart string) ([]lotteryTicket, error) {
|
||||
|
||||
Reference in New Issue
Block a user