fix(subscribe): improve query logic and handle status filtering

This commit is contained in:
Chang lue Tsen
2025-04-28 18:59:06 +09:00
parent 105ee9cc46
commit 2aaf4cf618
3 changed files with 8 additions and 6 deletions
+4 -1
View File
@@ -76,7 +76,10 @@ func (m *defaultUserModel) QueryUserSubscribe(ctx context.Context, userId int64,
// 获取当前时间向前推 7 天
sevenDaysAgo := time.Now().Add(-7 * 24 * time.Hour)
// 基础条件查询
conn = conn.Model(&Subscribe{}).Where("`user_id` = ? and `status` IN ?", userId, status)
conn = conn.Model(&Subscribe{}).Where("`user_id` = ?", userId)
if len(status) > 0 {
conn = conn.Where("`status` IN ?", status)
}
return conn.Where("`expire_time` > ? OR `finished_at` >= ?", now, sevenDaysAgo).
Preload("Subscribe").
Find(&list).Error