PUT administrator/domains/{id}/term, LegacyDomainTerms và migration backfill hạn cho dịch vụ domain chưa có expires_at.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Support;
|
|
|
|
use App\Models\ModuleDomain;
|
|
use App\Models\Order;
|
|
use App\Models\Service;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class LegacyDomainTerms
|
|
{
|
|
public static function for(Service $service): ?array
|
|
{
|
|
$legacy = ModuleDomain::query()
|
|
->whereRaw('LOWER(TRIM(name)) = ?', [mb_strtolower(trim((string) $service->server_name))])
|
|
->orderByRaw('customer_id = ? desc', [$service->customer_id])
|
|
->orderByDesc('next_due_date')
|
|
->first();
|
|
|
|
if (! $legacy) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'registered_at' => $legacy->order_id ? Order::whereKey($legacy->order_id)->value('created_at') : null,
|
|
'expires_at' => $legacy->next_due_date > 0 ? Carbon::createFromTimestamp($legacy->next_due_date) : null,
|
|
];
|
|
}
|
|
|
|
public static function fill(Service $service): void
|
|
{
|
|
$terms = self::for($service);
|
|
|
|
if (! $terms) {
|
|
return;
|
|
}
|
|
|
|
if (! $service->expires_at && $terms['expires_at']) {
|
|
$service->expires_at = $terms['expires_at'];
|
|
}
|
|
|
|
if ($service->note === \App\Services\Domain\CustomerDomainServiceSync::AUTO_CREATED_NOTE && $terms['registered_at']) {
|
|
$service->started_at = $terms['registered_at'];
|
|
}
|
|
}
|
|
}
|