Files
portal-api/app/Integrations/Whmcs/Support/CustomerIdResolver.php
T
2026-09-09 16:56:22 +07:00

38 lines
992 B
PHP

<?php
namespace App\Integrations\Whmcs\Support;
use Illuminate\Support\Facades\DB;
/**
* Resolves a WHMCS `tblclients.id` to the matching local `customers.id`,
* bridged through the uuid both sides already share (see ClientWriter).
*/
class CustomerIdResolver
{
/** @var array<int, int>|null whmcs client id => local customer id */
private static ?array $map = null;
public function resolve(int $whmcsClientId): ?int
{
self::$map ??= $this->build();
return self::$map[$whmcsClientId] ?? null;
}
private function build(): array
{
$uuidsByWhmcsId = DB::connection('whmcs')->table('tblclients')->pluck('uuid', 'id');
$customerIdsByUuid = DB::table('customers')->pluck('id', 'uuid');
$map = [];
foreach ($uuidsByWhmcsId as $whmcsId => $uuid) {
if (isset($customerIdsByUuid[$uuid])) {
$map[$whmcsId] = $customerIdsByUuid[$uuid];
}
}
return $map;
}
}