Files
portal-api/app/Models/Mail.php
baodev0andClaude Sonnet 5.5 55a834a2f8 feat: nhắc gia hạn QR theo dịch vụ, failover server hosting, CCCD admin, log cấp phát dịch vụ
- 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>
2026-10-30 18:36:41 +07:00

62 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Mail extends Model
{
use HasFactory;
protected $table = 'mail';
protected $fillable = [
'campaign_id',
'template_id',
'subject',
'from_address',
'to',
'cc',
'bcc',
'customer_id',
'order_id',
'service_id',
'sent_by',
'message',
'status'
];
// ponytail: status is stored as tinyint (1=sent, 2=failed, 3=pending) but the
// admin API/UI contract expects string enums; map it here so every reader agrees.
public const STATUS_MAP = [1 => 'sent', 2 => 'failed', 3 => 'pending'];
protected function status(): \Illuminate\Database\Eloquent\Casts\Attribute
{
return \Illuminate\Database\Eloquent\Casts\Attribute::make(
get: fn ($value) => self::STATUS_MAP[$value] ?? self::STATUS_MAP[1],
set: fn ($value) => is_string($value) ? (array_search($value, self::STATUS_MAP, true) ?: 1) : $value,
);
}
public function campaign()
{
return $this->belongsTo(MailCampaign::class, 'campaign_id');
}
public function customer()
{
return $this->belongsTo(Customer::class, 'customer_id');
}
public function sender()
{
return $this->belongsTo(User::class, 'sent_by');
}
public function template()
{
return $this->belongsTo(Template::class, 'template_id');
}
}