Files
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

76 lines
2.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ServicePlan extends Model
{
protected $fillable = [
'title',
'description',
'vcpu',
'ram',
'disk',
'domain',
'bandwidth',
'databases',
'mailboxes',
'mailbox_quota',
'ftp_accounts',
'subdomains',
'domain_aliases',
'features',
'is_active',
'sort_order',
'dns_manager_server_id',
];
protected $casts = [
'features' => 'array',
'is_active' => 'boolean',
];
public function plesk()
{
return $this->hasOne(ServicePlanPlesk::class);
}
public function dnsServer()
{
return $this->belongsTo(DnsServer::class, 'dns_manager_server_id');
}
public function servers()
{
return $this->belongsToMany(DnsServer::class, 'service_plan_servers', 'service_plan_id', 'dns_manager_server_id')
->withPivot('priority')
->orderByPivot('priority');
}
public function syncServers(array $serverIds): void
{
$ids = array_values(array_unique(array_map('intval', $serverIds)));
$this->servers()->sync(collect($ids)->mapWithKeys(fn (int $id, int $index) => [$id => ['priority' => $index]])->all());
$this->update(['dns_manager_server_id' => $ids[0] ?? null]);
}
public function summary(): array
{
return [
'title' => $this->title,
'vcpu' => $this->vcpu,
'ram' => $this->ram,
'disk' => $this->disk,
'bandwidth' => $this->bandwidth,
'databases' => $this->databases,
'mailboxes' => $this->mailboxes,
'ftp_accounts' => $this->ftp_accounts,
'subdomains' => $this->subdomains,
'domain_aliases' => $this->domain_aliases,
'features' => $this->features ?? [],
];
}
}