Files
portal-api/app/Models/MailCampaign.php
T
baodev0andClaude Opus 5.5 40bf6b54f9 feat(admin): star/tags marks, service product-type filter, campaign bulk actions, SMTP test
- Star (is_starred) and colored tags for services, customers, orders, invoices:
  Markable trait, tags/taggables tables, PATCH administrator/marks/{type}/{key},
  tag CRUD, list filters starred / tag_ids[]
- GET administrator/services accepts product_type (falls back to product type
  for legacy rows without services.type)
- Mail campaigns: bulk cancel / retry failed / delete; cancelled campaigns are
  skipped by SendMailCampaignRecipient
- POST administrator/settings/test-smtp sends a test email through the saved
  mail transport

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-15 21:53:41 +07:00

74 lines
1.6 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',
'cc',
'bcc',
'recipient_type',
'total_recipients',
'sent_count',
'failed_count',
'status',
'created_by',
'completed_at',
];
protected $casts = [
'variables' => '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');
}
}