Files
portal-api/app/Models/Mail.php
T
baodev0andClaude Opus 5.5 30898ea46f feat: email gửi tay/nhắc gia hạn, gói hosting, sửa dữ liệu sản phẩm
- Gửi email theo template cho 1 khách, tab lịch sử email, nhắc gia hạn dịch vụ hàng loạt
- Mail lưu from/bcc/sent_by; mẫu MARKETING và mẫu cũ trong TemplateSeeder
- Gói hosting: giới hạn, trạng thái, lấy plan Plesk qua CLI gateway
- Backfill payment_method và ngày đơn hàng còn thiếu
- Bổ sung field CPU/RAM/Disk/Băng thông cho loại sản phẩm vps và cloud

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 11:32:05 +07:00

60 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',
'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');
}
}