chore: refacto db

This commit is contained in:
2026-05-13 19:03:33 +02:00
parent 0039dda8a0
commit 426f4b42ee
9 changed files with 0 additions and 695 deletions
-14
View File
@@ -58,17 +58,3 @@ func (d *Database) ResetClientReferralBalance(username string) error {
}
return nil
}
func (d *Database) UseClientReferralBalance(tx *gorm.DB, username string, amount float64) error {
if amount <= 0 {
return nil
}
var balance float64
if err := tx.Raw(`SELECT referral_balance FROM clients WHERE username = ? FOR UPDATE`, username).Scan(&balance).Error; err != nil {
return fmt.Errorf("client non trouvé")
}
if balance < amount {
return fmt.Errorf("solde parrainage insuffisant (disponible: %.2f€)", balance)
}
return tx.Exec(`UPDATE clients SET referral_balance = referral_balance - ? WHERE username = ?`, amount, username).Error
}