fix(subscribe): ensure active status and reset timestamps during traffic resets

This commit is contained in:
Chang lue Tsen 2025-08-23 09:07:56 -04:00
parent d33f4cd1ce
commit d5460d0cd1

View File

@ -238,8 +238,10 @@ func (l *ResetTrafficLogic) resetMonth(ctx context.Context) error {
err = db.Model(&user.Subscribe{}).Where("`id` IN ?", monthlyResetUsers).
Updates(map[string]interface{}{
"upload": 0,
"download": 0,
"upload": 0,
"download": 0,
"status": 1, // Ensure status is active
"finished_at": nil,
}).Error
if err != nil {
logger.Errorw("[ResetTraffic] Failed to update monthly reset users", logger.Field("error", err.Error()))
@ -321,8 +323,10 @@ func (l *ResetTrafficLogic) reset1st(ctx context.Context, cache resetTrafficCach
// Reset upload and download traffic to zero
err = db.Model(&user.Subscribe{}).Where("`id` IN ?", users1stReset).
Updates(map[string]interface{}{
"upload": 0,
"download": 0,
"upload": 0,
"download": 0,
"status": 1, // Ensure status is active
"finished_at": nil,
}).Error
if err != nil {
logger.Errorw("[ResetTraffic] Failed to update 1st reset users", logger.Field("error", err.Error()))
@ -405,8 +409,10 @@ func (l *ResetTrafficLogic) resetYear(ctx context.Context) error {
// Reset upload and download traffic to zero
err = db.Model(&user.Subscribe{}).Where("`id` IN ?", usersYearReset).
Updates(map[string]interface{}{
"upload": 0,
"download": 0,
"upload": 0,
"download": 0,
"status": 1, // Ensure status is active
"finished_at": nil,
}).Error
if err != nil {
logger.Errorw("[ResetTraffic] Failed to update yearly reset users", logger.Field("error", err.Error()))