统一会员门禁逻辑并补权限分支测试
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user