false, 'Error' => 'business_not_found']; } $qSP = queryOne(" SELECT ID, Name, Code, TypeID, Description FROM ServicePoints WHERE BusinessID = ? AND BeaconMinor = ? AND IsActive = 1 LIMIT 1 ", [(int) $qBiz['BusinessID'], $minor]); if (!$qSP) { return [ 'Found' => false, 'Error' => 'servicepoint_not_found', 'BusinessID' => (int) $qBiz['BusinessID'], 'BusinessName' => $qBiz['BusinessName'], ]; } return [ 'Found' => true, 'ServicePointID' => (int) $qSP['ID'], 'ServicePointName' => $qSP['Name'], 'ServicePointCode' => $qSP['Code'] ?? '', 'ServicePointTypeID' => (int) $qSP['TypeID'], 'ServicePointDescription' => $qSP['Description'] ?? '', 'BusinessID' => (int) $qBiz['BusinessID'], 'BusinessName' => $qBiz['BusinessName'], ]; } try { $data = readJsonBody(); // Batch request if (isset($data['Beacons']) && is_array($data['Beacons'])) { $results = []; foreach ($data['Beacons'] as $beacon) { $uuid = trim($beacon['UUID'] ?? ''); $major = isset($beacon['Major']) && is_numeric($beacon['Major']) ? (int) $beacon['Major'] : 0; $minor = isset($beacon['Minor']) && is_numeric($beacon['Minor']) ? (int) $beacon['Minor'] : -1; if ($uuid === '' || $major <= 0 || $minor < 0) { $results[] = ['UUID' => $uuid, 'Major' => $major, 'Minor' => $minor, 'ServicePointID' => null, 'Error' => 'invalid_params']; continue; } $resolved = resolveSingle($uuid, $major, $minor); if ($resolved['Found']) { $results[] = [ 'UUID' => $uuid, 'Major' => $major, 'Minor' => $minor, 'ServicePointID' => $resolved['ServicePointID'], 'ServicePointName' => $resolved['ServicePointName'], 'ServicePointCode' => $resolved['ServicePointCode'], 'BusinessID' => $resolved['BusinessID'], 'BusinessName' => $resolved['BusinessName'], ]; } else { $errResult = ['UUID' => $uuid, 'Major' => $major, 'Minor' => $minor, 'ServicePointID' => null, 'Error' => $resolved['Error']]; if (isset($resolved['BusinessID'])) { $errResult['BusinessID'] = $resolved['BusinessID']; $errResult['BusinessName'] = $resolved['BusinessName']; } $results[] = $errResult; } } jsonResponse(['OK' => true, 'COUNT' => count($results), 'Results' => $results]); } // Single request $uuid = trim($data['UUID'] ?? ($_GET['UUID'] ?? '')); $major = (int) ($data['Major'] ?? ($_GET['Major'] ?? 0)); $minor = isset($data['Minor']) ? (int) $data['Minor'] : (isset($_GET['Minor']) ? (int) $_GET['Minor'] : -1); if ($uuid === '') apiAbort(['OK' => false, 'ERROR' => 'missing_uuid', 'MESSAGE' => 'UUID is required']); if ($major <= 0) apiAbort(['OK' => false, 'ERROR' => 'missing_major', 'MESSAGE' => 'Major is required']); if ($minor < 0) apiAbort(['OK' => false, 'ERROR' => 'missing_minor', 'MESSAGE' => 'Minor is required']); $resolved = resolveSingle($uuid, $major, $minor); if (!$resolved['Found']) { $err = ['OK' => false, 'ERROR' => $resolved['Error']]; if (isset($resolved['BusinessID'])) { $err['BusinessID'] = $resolved['BusinessID']; $err['BusinessName'] = $resolved['BusinessName']; $err['MESSAGE'] = 'Service point not found for this business'; } else { $err['MESSAGE'] = 'No business found for this beacon'; } apiAbort($err); } jsonResponse([ 'OK' => true, 'ServicePointID' => $resolved['ServicePointID'], 'ServicePointName' => $resolved['ServicePointName'], 'ServicePointCode' => $resolved['ServicePointCode'], 'ServicePointTypeID' => $resolved['ServicePointTypeID'], 'ServicePointDescription' => $resolved['ServicePointDescription'], 'BusinessID' => $resolved['BusinessID'], 'BusinessName' => $resolved['BusinessName'], ]); } catch (Exception $e) { jsonResponse(['OK' => false, 'ERROR' => 'server_error', 'MESSAGE' => $e->getMessage()]); }