同步历史版本代码
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/perfect-panel/server/pkg/constant"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -74,18 +75,29 @@ func (m *defaultUserModel) FindUsersSubscribeBySubscribeId(ctx context.Context,
|
||||
// QueryUserSubscribe returns a list of records that meet the conditions.
|
||||
func (m *defaultUserModel) QueryUserSubscribe(ctx context.Context, userId int64, status ...int64) ([]*SubscribeDetails, error) {
|
||||
var list []*SubscribeDetails
|
||||
key := fmt.Sprintf("%s%d", cacheUserSubscribeUserPrefix, userId)
|
||||
|
||||
// Check if includeExpired is set in context
|
||||
includeExpired, _ := ctx.Value(constant.CtxKeyIncludeExpired).(string)
|
||||
cacheKeySuffix := ""
|
||||
if includeExpired == "all" {
|
||||
cacheKeySuffix = ":all"
|
||||
}
|
||||
|
||||
key := fmt.Sprintf("%s%d%s", cacheUserSubscribeUserPrefix, userId, cacheKeySuffix)
|
||||
err := m.QueryCtx(ctx, &list, key, func(conn *gorm.DB, v interface{}) error {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
// 获取当前时间向前推 7 天
|
||||
sevenDaysAgo := time.Now().Add(-7 * 24 * time.Hour)
|
||||
// 基础条件查询
|
||||
conn = conn.Model(&Subscribe{}).Where("`user_id` = ?", userId)
|
||||
if len(status) > 0 {
|
||||
conn = conn.Where("`status` IN ?", status)
|
||||
}
|
||||
// 订阅过期时间大于当前时间或者订阅结束时间大于当前时间
|
||||
|
||||
if includeExpired == "all" {
|
||||
// 查询所有订阅(包括已过期的)
|
||||
return conn.Preload("Subscribe").Find(&list).Error
|
||||
}
|
||||
|
||||
// 默认只查询有效订阅
|
||||
now := time.Now()
|
||||
sevenDaysAgo := time.Now().Add(-7 * 24 * time.Hour)
|
||||
return conn.Where("`expire_time` > ? OR `finished_at` >= ? OR `expire_time` = ?", now, sevenDaysAgo, time.UnixMilli(0)).
|
||||
Preload("Subscribe").
|
||||
Find(&list).Error
|
||||
|
||||
Reference in New Issue
Block a user