* Date: 2026-5-20
*/
if (!defined('ROOT_PATH')) { exit('Access Denied'); }
require_once __DIR__ . '/../_functions.php';
if (empty($product) && !empty($id)) {
$product = $db->fetch("SELECT p.*, c.channel_name, c.channel_thumb, c.channel_dir FROM {$db->table('product')} p LEFT JOIN {$db->table('channel')} c ON p.channel_id = c.id WHERE p.id = ? AND p.status = 1 LIMIT 1", [intval($id)]);
}
if (empty($product)) {
echo 'Product not found';
return;
}
$pageTitle = (string) ($product['title'] ?? '产品详情');
$currentChannel = !empty($product['channel_id']) ? k607_channel_by_id($db, intval($product['channel_id'])) : null;
$heroImage = k607_channel_hero_image($currentChannel, !empty($product['litpic']) ? $product['litpic'] : (!empty($slides[0]['litpic']) ? $slides[0]['litpic'] : ''));
$productSummary = (string) (($product['summary'] ?? '') !== '' ? $product['summary'] : ($product['content'] ?? ''));
$gallery = [];
if (!empty($product['pictures'])) {
$galleryRaw = is_array($product['pictures']) ? $product['pictures'] : json_decode((string) $product['pictures'], true);
if (is_array($galleryRaw)) {
foreach ($galleryRaw as $pic) {
if (is_array($pic)) {
$url = $pic['url'] ?? ($pic['src'] ?? ($pic['image'] ?? ''));
if ($url !== '') {
$gallery[] = $url;
}
} elseif (is_string($pic) && trim($pic) !== '') {
$gallery[] = trim($pic);
}
}
}
}
if (!empty($product['litpic'])) {
array_unshift($gallery, (string) $product['litpic']);
}
$gallery = array_values(array_unique(array_filter($gallery)));
$mainImage = !empty($gallery[0]) ? $gallery[0] : 'https://picsum.photos/1200/900?random=' . max(1, intval($product['id'] ?? 1));
require_once __DIR__ . '/../_header.php';
?>
1): ?>
$pic): ?>
(function () {
var mainImage = document.getElementById('detailMainImage');
var thumbs = document.querySelectorAll('#detailGallery img');
if (!mainImage || !thumbs.length) return;
thumbs.forEach(function (thumb) {
thumb.addEventListener('click', function () {
var src = this.getAttribute('data-src');
if (!src) return;
mainImage.setAttribute('src', src);
thumbs.forEach(function (item) { item.classList.remove('active'); });
this.classList.add('active');
});
});
})();
HTML;
require_once __DIR__ . '/../_footer.php';
?>