$h['hotelCode'] ?? '',
'name' => getv($h, 'profile.name', ''),
'brand' => getv($h, 'brandInfo.brandName', ''),
'brandCode' => getv($h, 'brandInfo.brandCode', ''),
'phone' => getv($h, 'callCenter.phoneNumber', ''),
'address' => trim(implode(' ', array_filter([
getv($h, 'address.street1', ''),
getv($h, 'address.street3', ''),
getv($h, 'address.city', ''),
getv($h, 'address.state.name', ''),
getv($h, 'address.zip', ''),
]))),
'km' => getv($h, 'distanceFrom.kilometers', ''),
'miles' => getv($h, 'distanceFrom.miles', ''),
'image' => pickImage($h),
'website' => getv($h, 'profile.independentNonIHGWebsiteURL', ''),
'facilities' => array_values(array_filter(array_map(
fn($x) => $x['name'] ?? '',
$h['facilities'] ?? []
))),
'tax' => getv($h, 'tax.taxAndFeeDetail', ''),
'price' => getv($h, 'rate.price', getv($h, 'price.amount', null)),
'currency' => getv($h, 'rate.currency', getv($h, 'price.currency', 'CNY')),
];
}
function pageName(string $type, int $page): string {
if ($type === 'cards') return $page === 1 ? 'index.html' : "page-$page.html";
return $page === 1 ? 'table.html' : "table-$page.html";
}
function renderLayout(string $body, string $title): string {
return '
' . e($title) . '
' . $body . '
';
}
function renderPager(string $type, int $page, int $totalPages): string {
$html = '';
return $html;
}
function renderCardsPage(array $hotels, int $page, int $totalPages, int $total): string {
$body = '';
foreach ($hotels as $h) {
$features = '';
foreach (array_slice($h['facilities'], 0, 8) as $f) {
$features .= '' . e($f) . '';
}
$price = $h['price'] !== null
? '' . e(number_format((float)$h['price'])) . ' ' . e($h['currency']) . '
每晚
'
: '暂无价格
';
$body .= '
' . e($h['brandCode']) . '
' . e($h['brand'] . ' ' . $h['name']) . '
' . e($h['address']) . ' | ' . e($h['phone']) . '
📍 ' . e($h['km']) . ' 公里,' . e($h['miles']) . ' 英里 距离市中心
' . $features . '
⚡ Only a few left from
' . $price . '
' . e($h['tax']) . '
选择酒店
';
}
$body .= renderPager('cards', $page, $totalPages);
return renderLayout($body, '酒店列表');
}
function renderTablePage(array $hotels, int $page, int $totalPages, int $total): string {
$body = '';
$body .= '
| 图片 | 酒店 | 品牌 | 地址 | 距离 | 电话 | 设施 | 价格 | 税费 |
';
foreach ($hotels as $h) {
$price = $h['price'] !== null
? number_format((float)$h['price']) . ' ' . $h['currency']
: '暂无';
$body .= '
 . ') |
' . e($h['name']) . ' ' . e($h['code']) . ' |
' . e($h['brand']) . ' |
' . e($h['address']) . ' |
' . e($h['km']) . ' 公里 / ' . e($h['miles']) . ' 英里 |
' . e($h['phone']) . ' |
' . e(implode('、', array_slice($h['facilities'], 0, 8))) . ' |
' . e($price) . ' |
' . e($h['tax']) . ' |
';
}
$body .= '
';
$body .= renderPager('table', $page, $totalPages);
return renderLayout($body, '酒店表格');
}
$raw = file_get_contents($jsonFile);
$data = json_decode($raw, true, 512, JSON_THROW_ON_ERROR);
$hotelsRaw = getv($data, 'data.getHotels.hotelInfo', []);
$hotels = array_map('normalizeHotel', $hotelsRaw);
$total = count($hotels);
$totalPages = max(1, (int)ceil($total / $pageSize));
for ($page = 1; $page <= $totalPages; $page++) {
$chunk = array_slice($hotels, ($page - 1) * $pageSize, $pageSize);
file_put_contents(
$outDir . '/' . pageName('cards', $page),
renderCardsPage($chunk, $page, $totalPages, $total)
);
file_put_contents(
$outDir . '/' . pageName('table', $page),
renderTablePage($chunk, $page, $totalPages, $total)
);
}
echo "生成完成:{$outDir}\n";
echo "卡片首页:{$outDir}/index.html\n";
echo "表格首页:{$outDir}/table.html\n";