Files
wx_service/internal/smoke/service/membership_gate.go
T
2026-02-28 16:27:48 +08:00

24 lines
562 B
Go

package service
import (
"context"
"fmt"
"time"
usermodel "wx_service/internal/model"
"gorm.io/gorm"
)
func hasActiveMembership(ctx context.Context, db *gorm.DB, miniProgramID uint, userID uint, now time.Time) (bool, error) {
var count int64
if err := db.WithContext(ctx).
Model(&usermodel.UserMembership{}).
Where("mini_program_id = ? AND user_id = ? AND status = ? AND ends_at > ?",
miniProgramID, userID, "active", now).
Count(&count).Error; err != nil {
return false, fmt.Errorf("check membership: %w", err)
}
return count > 0, nil
}