- Mail campaign: mẫu nhắc gia hạn thanh toán QR, chọn dịch vụ + chu kỳ từng dòng (renewal_services) - Hosting: nhiều server Plesk cho một gói (service_plan_servers), chuyển server khi server chết - Admin xem/sửa giấy tờ định danh khách, tuỳ chọn gia hạn cho khách, nhật ký cấp phát dịch vụ - Đánh dấu mẫu email dịch vụ là non-marketing Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
78 lines
1.7 KiB
PHP
78 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',
|
|
'renewal_services',
|
|
'cc',
|
|
'bcc',
|
|
'recipient_type',
|
|
'total_recipients',
|
|
'sent_count',
|
|
'failed_count',
|
|
'status',
|
|
'created_by',
|
|
'completed_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'variables' => 'array',
|
|
'attachments' => 'array',
|
|
'renewal_services' => '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');
|
|
}
|
|
}
|