From 9712119238ff4012e3e68bce09028f8372be5e56 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 25 Mar 2025 21:43:49 +0800 Subject: [PATCH] :bug: Fix charging for programs --- pkg/internal/services/programs.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/internal/services/programs.go b/pkg/internal/services/programs.go index ef524cb..8c57584 100644 --- a/pkg/internal/services/programs.go +++ b/pkg/internal/services/programs.go @@ -82,15 +82,14 @@ func ChargeForProgram(member models.ProgramMember) error { func PeriodicChargeProgramFee() { var members []models.ProgramMember - if err := database.C.Preload("Program").Find(&members).Error; err != nil { + // 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 { return } for _, member := range members { - // every month paid once - if member.LastPaid == nil || time.Since(*member.LastPaid) < time.Hour*24*30 { - if err := ChargeForProgram(member); err == nil { - database.C.Model(&member).Update("last_paid", time.Now()) - } + if err := ChargeForProgram(member); err == nil { + database.C.Model(&member).Update("last_paid", time.Now()) } } }