🎵 Muzibu Premium

v3 FINAL - GÜNDE 5 ŞARKI

Basit, Temiz, Performanslı

📅 26 Kasım 2025 | 🎯 Tenant 1001 | ✅ Production-Ready
📋 Basit & Temiz Sistem

✅ Sistem Kuralları

Kullanıcı Tipi Günlük Limit Açıklama
🚫 Guest Her şarkının 30 saniyesi Fade-out ile bitiş, kayıt teşviki
👤 Normal Üye 5 tam şarkı Her gece 00:00'da reset
⭐ Premium/Deneme Sınırsız Tüm yetkiler

🚀 Neden Şarkı Sayısı?

  • Süper Basit: Sadece counter +1 (saat/dakika/saniye tracking yok!)
  • Minimal DB Write: Şarkı bitince tek write (günde 5 write max)
  • Anlaşılır UX: Kullanıcı kolayca anlar "3/5 şarkı kaldı"
  • Performans Canavarı: Redis/cache bile gereksiz, direkt DB yeterli
  • Lazy Reset: Cron job yok, kullanıcı çalarken kontrol

📊 Database - Minimal Yapı

// Users tablosuna SADECE 2 alan ekliyoruz:

daily_songs_played    INT      DEFAULT 0
last_song_reset       DATE     NULL

// Bu kadar! Basit ve temiz.

⚡ Performans

  • 🔥 DB Write: 5 write/kullanıcı/gün (mükemmel!)
  • 🔥 Lazy Reset: Cron yok, 00:00'da DB lock yok
  • 🔥 Cache: Opsiyonel (5 dk), zorunlu değil
  • 🔥 Listening Logs: Opsiyonel (istatistik için)
🚫 Guest Modal - 30 Saniye
⏱️ Normal Üye - 5 Şarkı Doldu
⚙️ Basit Implementasyon

1️⃣ Migration (2 alan ekle)

Schema::table('users', function (Blueprint $table) {
    $table->integer('daily_songs_played')->default(0);
    $table->date('last_song_reset')->nullable();
});

2️⃣ User Model (2 metod)

// Şarkı çalabilir mi?
public function canPlaySong(): bool
{
    // Lazy reset
    if ($this->last_song_reset < today()) {
        $this->update([
            'daily_songs_played' => 0,
            'last_song_reset' => today()
        ]);
    }

    // Premium/Trial unlimited
    if ($this->isPremium() || $this->isTrialActive()) {
        return true;
    }

    // Normal üye: 5 şarkı limiti
    return $this->daily_songs_played < 5;
}

// Şarkı dinlendi
public function incrementSongCount(): void
{
    if (!$this->isPremium() && !$this->isTrialActive()) {
        $this->increment('daily_songs_played');
    }
}

3️⃣ API Controller

// Şarkı çalmadan önce kontrol
public function stream($songId)
{
    $user = auth()->user();

    if (!$user->canPlaySong()) {
        return response()->json([
            'error' => 'daily_limit_exceeded',
            'message' => 'Günlük 5 şarkı limitiniz doldu',
            'played' => $user->daily_songs_played,
            'limit' => 5
        ], 403);
    }

    // Stream URL'i dön
    return response()->json([
        'stream_url' => $song->getStreamUrl(),
        'remaining' => 5 - $user->daily_songs_played
    ]);
}

// Şarkı bitince
public function onSongEnd($songId)
{
    auth()->user()->incrementSongCount();

    return response()->json(['success' => true]);
}

4️⃣ Frontend (Player)

// Şarkı çalmadan önce
async function playSong(songId) {
    const response = await fetch(`/api/muzibu/songs/${songId}/stream`);

    if (response.status === 403) {
        // Limit doldu modal göster
        showLimitModal();
        return;
    }

    const data = await response.json();
    howler.play(data.stream_url);

    // Şarkı bitince API call
    howler.on('end', () => {
        fetch(`/api/muzibu/songs/${songId}/track`, { method: 'POST' });
    });
}

✅ Bu Kadar!

- Migration: 2 alan
- User Model: 2 method
- API: 2 endpoint
- Frontend: 10 satır kod

Basit, temiz, performanslı! 🚀