feat(domain): chỉnh ngày bắt đầu/hết hạn tên miền và điền hạn từ dữ liệu cũ
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>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
e37106f2dc
commit
7136bec265
@@ -0,0 +1,46 @@
|
||||
<?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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user