🐛 Fix did not remove user from program if they didn't pay

This commit is contained in:
LittleSheep 2025-04-02 23:15:59 +08:00
parent e716f5700c
commit ef20829b2e

View File

@ -84,12 +84,14 @@ func PeriodicChargeProgramFee() {
var members []models.ProgramMember
// Every month paid once
if err := database.C.Where("last_paid IS NULL OR last_paid < ?", time.Now().AddDate(0, 0, -30)).
Preload("Program").Find(&members).Error; err != nil {
Preload("Program").Preload("Account").Find(&members).Error; err != nil {
return
}
for _, member := range members {
if err := ChargeForProgram(member); err == nil {
database.C.Model(&member).Update("last_paid", time.Now())
} else {
LeaveProgram(member.Account, member.Program)
}
}
}