This commit is contained in:
aozhiwei 2024-11-11 14:01:41 +08:00
parent 58720a2435
commit 133548133d

View File

@ -56,16 +56,26 @@ func (this *User) DecDice(num int32) error {
if this.Score < int64(num) {
return errors.New("")
}
oldScore := this.Score
this.Score -= int64(num)
oldDice := this.Dice
this.Dice -= num
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Model(this).Select(
"dice").Updates(this); result.Error != nil {
this.Score = oldScore
this.Dice = oldDice
return result.Error
}
return nil
}
func (this *User) AddScore(score int32) error {
if score <= 0 {
return nil
}
oldScore := this.Score
this.Score += int64(score)
if result := f5.GetApp().GetOrmDb(constant.WHEEL_DB).Model(this).Select(
"score").Updates(this); result.Error != nil {
this.Score = oldScore
return result.Error
}
return nil
}