feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk

- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch
- Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay
- Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng
- Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
baodev0
2026-10-11 23:07:51 +07:00
co-authored by Claude Opus 5.5
parent 10af41c5cf
commit c5115b52dd
53 changed files with 1887 additions and 613 deletions
+88 -6
View File
@@ -3,8 +3,11 @@
namespace App\Jobs\DnsManager;
use App\Events\DnsSyncCompleted;
use App\Models\DnsDomain;
use App\Models\DnsServer;
use App\Repositories\DnsManager\Domain\DnsDomainRepositoryInterface;
use App\Repositories\DnsManager\Record\DnsRecordRepositoryInterface;
use App\Services\Plesk\PleskDomainService;
use App\Services\ServerService;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -19,19 +22,46 @@ class SyncDnsFromPlesk implements ShouldQueue
private const PLESK_RECORD_TYPES = ['A', 'AAAA', 'CNAME', 'TXT', 'MX', 'NS', 'SRV'];
public function __construct(private readonly ?int $serverId = null)
{
}
public function handle(
DnsDomainRepositoryInterface $domainRepository,
DnsRecordRepositoryInterface $recordRepository,
ServerService $serverService,
PleskDomainService $pleskDomainService,
): void {
$synced = 0;
$imported = 0;
$failedDomains = [];
if ($this->serverId !== null) {
$server = DnsServer::find($this->serverId);
$pleskDomains = $server ? $pleskDomainService->listDomains($server) : false;
if ($pleskDomains === false) {
Log::error('DNS sync: không lấy được danh sách domain từ Plesk', [
'server_id' => $this->serverId,
'error' => $pleskDomainService->getLastError(),
]);
event(new DnsSyncCompleted(0, ['server #' . $this->serverId], 0));
return;
}
$imported = $this->importDomains($pleskDomains);
}
$domains = $domainRepository->model
->notCancelled()
->whereNotNull('dns_manager_server_id')
->when(
$this->serverId !== null,
fn ($query) => $query->where('dns_manager_server_id', $this->serverId),
fn ($query) => $query->whereNotNull('dns_manager_server_id'),
)
->get();
$synced = 0;
$failedDomains = [];
foreach ($domains as $domain) {
if (!$serverService->addServerById($domain->dns_manager_server_id)) {
$failedDomains[] = $domain->domain_name;
@@ -63,9 +93,61 @@ class SyncDnsFromPlesk implements ShouldQueue
}
}
Log::info('DNS sync from Plesk finished', ['synced' => $synced, 'failed_domains' => $failedDomains]);
Log::info('DNS sync from Plesk finished', [
'server_id' => $this->serverId,
'imported' => $imported,
'synced' => $synced,
'failed_domains' => $failedDomains,
]);
event(new DnsSyncCompleted($synced, $failedDomains));
event(new DnsSyncCompleted($synced, $failedDomains, $imported));
}
/**
* @param array<int, array<string, mixed>> $pleskDomains
*/
private function importDomains(array $pleskDomains): int
{
$imported = 0;
foreach ($pleskDomains as $item) {
$name = strtolower(trim((string) ($item['name'] ?? '')));
if ($name === '' || empty($item['id']) || !empty($item['base_domain_id'])) {
continue;
}
$domain = DnsDomain::whereRaw('LOWER(domain_name) = ?', [$name])->first();
if (!$domain) {
DnsDomain::create([
'domain_name' => $name,
'dns_manager_server_id' => $this->serverId,
'plesk_id' => $item['id'],
'is_created' => DnsDomain::STATUS_CREATED,
]);
$imported++;
continue;
}
$sameServer = in_array((int) $domain->dns_manager_server_id, [0, $this->serverId], true);
if ($domain->plesk_id || !$sameServer || (int) $domain->is_created === DnsDomain::STATUS_CANCELLED) {
continue;
}
$domain->update([
'dns_manager_server_id' => $this->serverId,
'plesk_id' => $item['id'],
'is_created' => (int) $domain->is_created === DnsDomain::STATUS_PENDING
? DnsDomain::STATUS_CREATED
: $domain->is_created,
]);
$imported++;
}
return $imported;
}
private function mapPleskRecord(array $item, string $type, string $domainName): array