MASTER PLAN - Tenant 1001 Özel
subscriptions tablosu VARsubscription_plans tablosu VARusers tablosu VARsubscriptions.status → active, trial, expired, cancelledsubscriptions.current_period_end → Bitiş tarihisubscriptions.has_trial, trial_days, trial_ends_at VARsubscription_plans.trial_days VAR (plan seviyesi)users.has_used_trial field YOK → Migration gerekli!subscription_plans.is_trial boolean YOK → Migration gerekli!// 🚨 SORUN: 1 saatlik cache!
$cacheKey = 'user_' . $this->id . '_is_premium_tenant_1001';
return Cache::remember($cacheKey, 3600, function () {
$activeSubscription = $this->subscriptions()
->where('status', 'active')
->where('current_period_end', '>', now())
->first();
return $activeSubscription ? true : false;
});
❌ Cache kullanıyor → Trial bitince 1 saat geç fark edilir!
public function isTrialActive(): bool
{
$trialSubscription = $this->subscriptions()
->where('status', 'trial')
->whereNotNull('trial_ends_at')
->where('trial_ends_at', '>', now())
->first();
return $trialSubscription ? true : false;
}
✅ Cache YOK, direkt DB kontrolü (İYİ!)
// Normal üye (premium değil) → 30 saniye preview
if (!$user->isPremium()) {
// Preview ver
}
❌ Cached isPremium() kullanıyor → Fresh check gerekli!
scopeActive() → status='active' ve current_period_end > now()scopeTrial() → status='trial'scopeExpired() → status='expired'Kayıp: SONSUZ
Kayıp: 1 SAAT/İSTEK
Request-Level Fresh Check + Event-Based System + Cron Backup
Her müzik isteğinde gerçek zamanlı kontrol, durum değişince event fırlat, yedek cron!
isPremium() → 1 saat cacheisPremiumFresh() → CACHE YOK!is_trial checkbox)
database/migrations/YYYY_MM_DD_add_has_used_trial_to_users.php
Boolean field, default false, index ekle
database/migrations/YYYY_MM_DD_add_is_trial_to_subscription_plans.php
Boolean field, default false, unique constraint (sadece 1 plan is_trial=true)
app/Models/User.php
isPremium()'i kopyala ama Cache KULLANMA! Direkt DB check
Tenant 1001 kontrolü ekle: if (!$this->isMuzibuTenant()) return false;
Modules/Subscription/app/Models/SubscriptionPlan.php
$fillable'a 'is_trial' ekle, $casts'a 'is_trial' => 'boolean'
app/Events/TrialExpired.php
Properties: $user, $subscription
app/Events/SubscriptionExpired.php
app/Listeners/SendTrialExpiredEmail.php
Email gönder, push bildirim, log tut, analytics
Subscription bittiyse → Status güncelle (active → expired)
Event fırlat: event(new TrialExpired($user, $subscription))
app/Providers/EventServiceProvider.php
$listen array'ine event-listener mapping'leri ekle
Modules/Muzibu/app/Http/Controllers/Api/SongStreamController.php:98
if (!$user->isPremium()) → if (!$user->isPremiumFresh())
Dynamic playlist controller'ında da isPremiumFresh() kullan
Her chunk isteğinde kontrol et
app/Http/Middleware/CheckSubscription.php
Tüm API route'larına eklenebilir, otomatik expire check
Subscription Plans → Yeni Plan
Title: "Trial", slug: "trial", fiyat: ₺0.00, süre: 7 gün
is_trial checkbox'ı işaretle
Modules/Subscription/.../subscription-plan-manage-component.blade.php
7 lokasyon: Cycle card badge, Edit modal input, New modal input
RegisterController'da:
1. has_used_trial kontrol et
2. False ise trial plan bul (is_trial = true)
3. Subscription oluştur, has_used_trial = true yap
app/Console/Kernel.php
Siteye girmeyen kullanıcıların expired subscription'larını temizle
| # | Görev | Dosya/Konum | Öncelik |
|---|---|---|---|
| 1 | Migration: users.has_used_trial | database/migrations/ | YÜKSEK |
| 2 | Migration: subscription_plans.is_trial | database/migrations/ | YÜKSEK |
| 3 | User.php: isPremiumFresh() ekle | app/Models/User.php | YÜKSEK |
| 4 | SubscriptionPlan: is_trial fillable | Modules/Subscription/.../SubscriptionPlan.php | YÜKSEK |
| 5 | Event: TrialExpired oluştur | app/Events/TrialExpired.php | YÜKSEK |
| 6 | Event: SubscriptionExpired oluştur | app/Events/SubscriptionExpired.php | YÜKSEK |
| 7 | Listener'lar oluştur | app/Listeners/ | YÜKSEK |
| 8 | isPremiumFresh() event dispatch | app/Models/User.php | YÜKSEK |
| 9 | EventServiceProvider kayıt | app/Providers/EventServiceProvider.php | YÜKSEK |
| 10 | SongStreamController: Fresh check | Modules/Muzibu/.../SongStreamController.php:98 | YÜKSEK |
| 11 | HLS Playlist: Fresh check | Modules/Muzibu/.../DynamicPlaylistController.php | YÜKSEK |
| 12 | Middleware: SubscriptionCheck (opsiyonel) | app/Http/Middleware/ | ORTA |
| 13 | Admin: Trial planı oluştur (manuel) | Admin Panel → Subscription Plans | ORTA |
| 14 | Admin UI: Trial field temizle | ...subscription-plan-manage-component.blade.php | ORTA |
| 15 | Register: Otomatik trial subscription | RegisterController veya User boot() | ORTA |
| 16 | Cron: Günlük yedek temizlik | app/Console/Kernel.php | DÜŞÜK |
Her müzik isteğinde isPremiumFresh() çağır → CACHE YOK!
Tenant 1001 kontrolü: if (!$this->isMuzibuTenant()) return false;
Subscription bittiyse → Status güncelle (active → expired)
Event fırlat → Listener'lar çalışır (email, log, bildirim)
Günlük toplu temizlik (siteye girmeyenler için)
Sadece yedek amaçlı, asıl kontrol request-level