update email template
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Whmcs\Transformers;
|
||||
|
||||
use App\Integrations\Whmcs\DTOs\CustomerDomainData;
|
||||
use App\Integrations\Whmcs\Support\CustomerIdResolver;
|
||||
use App\Integrations\Whmcs\Support\OrderIdResolver;
|
||||
use App\Integrations\Whmcs\Support\RegistrarIdResolver;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CustomerDomainTransformer
|
||||
{
|
||||
public function __construct(
|
||||
private CustomerIdResolver $customers,
|
||||
private OrderIdResolver $orders,
|
||||
private RegistrarIdResolver $registrars,
|
||||
) {
|
||||
}
|
||||
|
||||
public function transform(array|object $row): CustomerDomainData
|
||||
{
|
||||
$row = (array) $row;
|
||||
$name = trim($row['domain']);
|
||||
|
||||
$notes = [];
|
||||
$notes[] = "WHMCS status: {$row['status']}";
|
||||
|
||||
$liveInDns = DB::table('dns_manager_domain')->whereRaw('LOWER(domain_name) = ?', [mb_strtolower($name)])->exists();
|
||||
$status = $liveInDns ? 1 : 2;
|
||||
if (! $liveInDns) {
|
||||
$notes[] = 'Không tìm thấy domain này trong DNS manager (dns_manager_domain).';
|
||||
}
|
||||
|
||||
if ($row['registrar'] && ! $this->registrars->resolve($row['registrar'])) {
|
||||
$notes[] = "Registrar WHMCS chưa map: {$row['registrar']}";
|
||||
}
|
||||
|
||||
if ($row['additionalnotes']) {
|
||||
$notes[] = $row['additionalnotes'];
|
||||
}
|
||||
|
||||
return new CustomerDomainData(
|
||||
legacyId: (int) $row['id'],
|
||||
customerId: $this->customers->resolve((int) $row['userid']),
|
||||
orderId: $this->orders->resolve((int) $row['orderid']) ?? 0,
|
||||
name: $name,
|
||||
firstPayment: (int) round((float) $row['firstpaymentamount']),
|
||||
nextPayment: (int) round((float) $row['recurringamount']),
|
||||
nextDueDate: $this->toTimestamp($row['nextduedate'] ?? null),
|
||||
nextInvoiceDate: $this->toTimestamp($row['nextinvoicedate'] ?? null),
|
||||
registrarId: $row['registrar'] ? $this->registrars->resolve($row['registrar']) : null,
|
||||
status: $status,
|
||||
note: implode(' | ', $notes),
|
||||
);
|
||||
}
|
||||
|
||||
private function toTimestamp(?string $date): ?int
|
||||
{
|
||||
if (! $date || str_starts_with($date, '0000-00-00')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return strtotime($date) ?: null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user