统一会员门禁逻辑并补权限分支测试
This commit is contained in:
@@ -189,7 +189,7 @@ func (s *SmokeAIAdviceService) getCached(ctx context.Context, uid int, adviceTyp
|
||||
}
|
||||
|
||||
func (s *SmokeAIAdviceService) isAllowed(ctx context.Context, user *usermodel.User, adviceDate time.Time) (bool, error) {
|
||||
isVIP, err := s.isVIP(ctx, user)
|
||||
isVIP, err := hasActiveMembership(ctx, s.db, user.MiniProgramID, user.ID, time.Now())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
@@ -199,19 +199,6 @@ func (s *SmokeAIAdviceService) isAllowed(ctx context.Context, user *usermodel.Us
|
||||
return s.isUnlocked(ctx, int(user.ID), adviceDate)
|
||||
}
|
||||
|
||||
func (s *SmokeAIAdviceService) isVIP(ctx context.Context, user *usermodel.User) (bool, error) {
|
||||
now := time.Now()
|
||||
var count int64
|
||||
if err := s.db.WithContext(ctx).
|
||||
Model(&usermodel.UserMembership{}).
|
||||
Where("mini_program_id = ? AND user_id = ? AND status = ? AND ends_at > ?",
|
||||
user.MiniProgramID, user.ID, "active", now).
|
||||
Count(&count).Error; err != nil {
|
||||
return false, fmt.Errorf("check vip: %w", err)
|
||||
}
|
||||
return count > 0, nil
|
||||
}
|
||||
|
||||
func (s *SmokeAIAdviceService) isUnlocked(ctx context.Context, uid int, adviceDate time.Time) (bool, error) {
|
||||
startOfDay := dateOnly(adviceDate)
|
||||
var unlock smokemodel.SmokeAIAdviceUnlock
|
||||
|
||||
Reference in New Issue
Block a user