<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-6-2
 */
if (!defined('ROOT_PATH')) exit;
$product = $id>0 ? $db->fetch("SELECT * FROM {$db->table('product')} WHERE id=".intval($id)." AND status=1") : null;
if (!$product) { echo '产品不存在'; return; }
$currentChannel = null;
if (!empty($product['channel_id'])) {
    $currentChannel = $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".intval($product['channel_id']));
}
if (!$currentChannel) {
    $currentChannel = array('id' => 0, 'parent_id' => 0, 'channel_name' => '产品中心', 'channel_thumb' => '');
}
$topId = intval($currentChannel['parent_id'])>0 ? intval($currentChannel['parent_id']) : intval($currentChannel['id']);
$topChannel = intval($currentChannel['parent_id'])>0 ? $db->fetch("SELECT * FROM {$db->table('channel')} WHERE id=".$topId) : $currentChannel;
if (!$topChannel) { $topChannel = $currentChannel; }
$subChannels = !empty($topId) ? $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id=".$topId." AND is_show=1 ORDER BY list_order ASC,id ASC") : array();
$prev = $db->fetch("SELECT id,title FROM {$db->table('product')} WHERE channel_id=".intval($product['channel_id'])." AND id<".intval($product['id'])." AND status=1 ORDER BY id DESC LIMIT 1");
$next = $db->fetch("SELECT id,title FROM {$db->table('product')} WHERE channel_id=".intval($product['channel_id'])." AND id>".intval($product['id'])." AND status=1 ORDER BY id ASC LIMIT 1");
$bannerPic = !empty($slides[0]['slide_pic']) ? $slides[0]['slide_pic'] : (!empty($currentChannel['channel_thumb']) ? $currentChannel['channel_thumb'] : 'https://picsum.photos/1600/500?random='.intval($currentChannel['id']));
$mobileBannerPic = !empty($slides[0]['slide_pic']) ? $slides[0]['slide_pic'] : (!empty($currentChannel['channel_thumb']) ? $currentChannel['channel_thumb'] : 'https://picsum.photos/1200/400?random='.intval($currentChannel['id']));
?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title><?php echo htmlspecialchars($product['title']); ?>-<?php echo htmlspecialchars($site['site_name']); ?></title><meta name="keywords" content="<?php echo htmlspecialchars(isset($product['keywords']) ? $product['keywords'] : ''); ?>"><meta name="description" content="<?php echo htmlspecialchars(msubstr(strip_tags($product['content']),0,120)); ?>"><meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" /><link href="<?php echo $site['template_dir']; ?>css/style.css" rel="stylesheet" type="text/css" /><link href="<?php echo $site['template_dir']; ?>css/bootstrap.min.css" rel="stylesheet" type="text/css"><script src="<?php echo $site['template_dir']; ?>js/jquery-1.8.3.min.js"></script></head><body><?php include dirname(__DIR__).'/_header.php'; ?><div class="banner_n" style="background:url(<?php echo htmlspecialchars($bannerPic); ?>) no-repeat top center;background-size:cover;"><div class="capitalize"><div class="ad-tit"><?php echo htmlspecialchars($topChannel['channel_name']); ?></div><div class="ad-line"></div></div></div><div class="mbanner"><img src="<?php echo htmlspecialchars($mobileBannerPic); ?>" width="100%" /></div><div class="post"><div class="postcon clearfix"><div class="col-md-8 col-sm-12 col-xs-12 nabout_menu"><ul><?php foreach ($subChannels as $sc) { ?><li class="<?php echo intval($sc['id'])==intval($currentChannel['id']) ? 'cur' : ''; ?>"><a href="<?php echo getUrl('channel', intval($sc['id']), isset($sc['channel_dir']) ? $sc['channel_dir'] : ''); ?>"><?php echo htmlspecialchars($sc['channel_name']); ?></a></li><?php } ?></ul></div><div class="col-md-4 col-sm-12 col-xs-12 position hidden-s"><img src="<?php echo $site['template_dir']; ?>images/tb6.png" alt="当前位置" /> <a href="<?php echo getUrl('home'); ?>">首页</a> >> <a href="<?php echo getUrl('channel', intval($topChannel['id']), isset($topChannel['channel_dir']) ? $topChannel['channel_dir'] : ''); ?>"><?php echo htmlspecialchars($topChannel['channel_name']); ?></a> >> <a href="<?php echo getUrl('channel', intval($currentChannel['id']), isset($currentChannel['channel_dir']) ? $currentChannel['channel_dir'] : ''); ?>"><?php echo htmlspecialchars($currentChannel['channel_name']); ?></a></div></div></div><div class="npro cont"><div class="npronr"><div class="nprolf left"><img src="<?php echo htmlspecialchars(!empty($product['litpic']) ? $product['litpic'] : 'https://picsum.photos/600/500?random='.intval($product['id'])); ?>" alt="<?php echo htmlspecialchars($product['title']); ?>" /></div><div class="nprort right"><h3>产品名称：<span><?php echo htmlspecialchars($product['title']); ?></span></h3><p>价格：<?php echo htmlspecialchars(isset($product['price']) ? $product['price'] : '面议'); ?><br>简介：<?php echo htmlspecialchars(isset($product['summary']) && $product['summary']!=='' ? $product['summary'] : '暂无简介'); ?></p></div><div class="clear"></div><div class="nprotit">产品详情</div><div class="nproinfo ab_img"><?php echo $product['content']; ?></div><div class="page1"><div class="pageleft left"><p>上一篇：<?php if($prev){ ?><a href="<?php echo getUrl('product', intval($prev['id'])); ?>"><?php echo htmlspecialchars($prev['title']); ?></a><?php } else { ?>没有了！<?php } ?></p></div><div class="pageright right"><p>下一篇：<?php if($next){ ?><a href="<?php echo getUrl('product', intval($next['id'])); ?>"><?php echo htmlspecialchars($next['title']); ?></a><?php } else { ?>没有了！<?php } ?></p></div><div style="clear:both;"></div></div></div></div><?php include dirname(__DIR__).'/_footer.php'; ?></body></html>
