Add subscription tiers, notification preferences, and logging infrastructure
- Add database migrations for plans, subscriptions, notification preferences, and notification log tables - Implement DispatchUserNotificationJob to handle channel resolution, daily limits, and logging (sent/tier_restricted/daily_limit) - Add SendScheduledWhatsAppJob for scheduled notification delivery - Create PlanFeatures service to resolve tier capabilities, check daily limits, and validate fuel
This commit is contained in:
56
app/Models/NotificationLog.php
Normal file
56
app/Models/NotificationLog.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\NotificationLogFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class NotificationLog extends Model
|
||||
{
|
||||
/** @use HasFactory<NotificationLogFactory> */
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
protected $table = 'notification_log';
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'channel',
|
||||
'trigger_type',
|
||||
'fuel_type',
|
||||
'price',
|
||||
'sent',
|
||||
'missed_reason',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/** Count sent notifications for this channel today. */
|
||||
public function scopeSentToday(Builder $query, string $channel): void
|
||||
{
|
||||
$query->where('channel', $channel)
|
||||
->where('sent', true)
|
||||
->whereDate('created_at', today());
|
||||
}
|
||||
|
||||
/** Notifications that were not sent. */
|
||||
public function scopeMissed(Builder $query): void
|
||||
{
|
||||
$query->where('sent', false);
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'sent' => 'boolean',
|
||||
'price' => 'decimal:3',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user