76 lines
1.7 KiB
PHP
76 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Str;
|
|
|
|
class MailCampaign extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
public const STATUS_CANCELLED = 'cancelled';
|
|
|
|
public const ACTIVE_STATUSES = ['queued', 'sending'];
|
|
|
|
public const FINISHED_STATUSES = ['completed', 'failed', self::STATUS_CANCELLED];
|
|
|
|
protected $table = 'mail_campaigns';
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'name',
|
|
'template_id',
|
|
'subject',
|
|
'message',
|
|
'variables',
|
|
'attachments',
|
|
'cc',
|
|
'bcc',
|
|
'recipient_type',
|
|
'total_recipients',
|
|
'sent_count',
|
|
'failed_count',
|
|
'status',
|
|
'created_by',
|
|
'completed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'variables' => 'array',
|
|
'attachments' => 'array',
|
|
'total_recipients' => 'integer',
|
|
'sent_count' => 'integer',
|
|
'failed_count' => 'integer',
|
|
'completed_at' => 'datetime',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $campaign) {
|
|
$campaign->uuid ??= (string) Str::uuid();
|
|
});
|
|
}
|
|
|
|
public function isMarketing(): bool
|
|
{
|
|
return $this->template === null || $this->template->isMarketing();
|
|
}
|
|
|
|
public function logs()
|
|
{
|
|
return $this->hasMany(Mail::class, 'campaign_id');
|
|
}
|
|
|
|
public function template()
|
|
{
|
|
return $this->belongsTo(Template::class, 'template_id');
|
|
}
|
|
|
|
public function creator()
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
}
|