* Date: 2026-5-20
*/
if (!defined('ROOT_PATH')) { exit('Access Denied'); }
require_once __DIR__ . '/../_functions.php';
$productChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE channel_type = 2 AND is_show = 1 ORDER BY list_order ASC, id ASC");
$filterChannelId = intval($_GET['channel_id'] ?? 0);
$currentPage = max(1, intval($_GET['page'] ?? 1));
$pageSize = 9;
$heroChannel = !empty($productChannels[0]) ? $productChannels[0] : ['channel_name' => '产品中心', 'channel_thumb' => ''];
$heroImage = k607_channel_hero_image($heroChannel, !empty($slides[0]['litpic']) ? $slides[0]['litpic'] : '');
$pageTitle = '产品中心';
$queryIds = [];
if ($filterChannelId > 0) {
$queryIds[] = $filterChannelId;
$children = $db->fetchAll("SELECT id FROM {$db->table('channel')} WHERE parent_id = ? AND is_show = 1", [$filterChannelId]);
foreach ($children as $child) {
$queryIds[] = intval($child['id']);
}
} else {
foreach ($productChannels as $nav) {
$queryIds[] = intval($nav['id']);
}
}
$queryIds = array_values(array_unique(array_filter($queryIds)));
if (empty($queryIds)) {
$queryIds[] = 0;
}
$ph = implode(',', array_fill(0, count($queryIds), '?'));
$countRow = $db->fetch("SELECT COUNT(*) AS total FROM {$db->table('product')} WHERE status = 1 AND channel_id IN ({$ph})", $queryIds);
$total = intval($countRow['total'] ?? 0);
$totalPages = max(1, (int) ceil($total / $pageSize));
$offset = ($currentPage - 1) * $pageSize;
$items = $db->fetchAll("SELECT p.*, c.channel_name FROM {$db->table('product')} p LEFT JOIN {$db->table('channel')} c ON p.channel_id = c.id WHERE p.status = 1 AND p.channel_id IN ({$ph}) ORDER BY p.create_time DESC LIMIT {$offset}, {$pageSize}", $queryIds);
require_once __DIR__ . '/../_header.php';
?>