<?php
/**
 * 芋头CMS
 * ============================================================================
 * 版权所有 2016-2028 沅陵县乌托邦网络服务有限公司，并保留所有权利。
 * 网站地址: http://www.yutoucms.cn
 * ----------------------------------------------------------------------------
 * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷。
 * ============================================================================
 * Author: 芋头 <mxgsf@qq.com>
 * Date: 2026-5-30
 */
if (!defined('ROOT_PATH')) { exit('Access Denied'); }

$pageTitle = '首页';
$extraHead = '';

$slideList = $db->fetchAll("SELECT * FROM {$db->table('slide')} WHERE status = 1 ORDER BY sort_order ASC, id DESC LIMIT 5");
$articleChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id = 23 AND channel_type = 1 AND is_show = 1 ORDER BY list_order ASC, id ASC LIMIT 3");
if (!$articleChannels) {
    $articleChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE channel_type = 1 AND is_show = 1 ORDER BY list_order ASC, id ASC LIMIT 3");
}
$productChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE parent_id = 22 AND is_show = 1 ORDER BY list_order ASC, id ASC");
if (!$productChannels) {
    $productChannels = $db->fetchAll("SELECT * FROM {$db->table('channel')} WHERE channel_type = 2 AND is_show = 1 ORDER BY list_order ASC, id ASC LIMIT 8");
}
$allProducts = $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 ORDER BY p.create_time DESC LIMIT 8");
$productMap = [];
if ($productChannels) {
    foreach ($productChannels as $pch) {
        $productMap[$pch['id']] = $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 = ? ORDER BY p.create_time DESC LIMIT 8", [$pch['id']]);
    }
}
$caseProducts = $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.litpic <> '' ORDER BY p.create_time DESC LIMIT 5");
$recommendImage = $db->fetch("SELECT litpic FROM {$db->table('article')} WHERE litpic <> '' AND status = 1 ORDER BY create_time DESC LIMIT 1");
if (!$recommendImage) {
    $recommendImage = $db->fetch("SELECT litpic FROM {$db->table('product')} WHERE litpic <> '' AND status = 1 ORDER BY create_time DESC LIMIT 1");
}
$thumbProducts = [];
$companyIntro = trim($siteConfig['company_intro'] ?? '');

require_once __DIR__ . '/_header.php';
?>
<div class="banner">
  <div data-am-widget="slider" class="am-slider am-slider-a2" data-am-slider='{"directionNav":false,"slideshowSpeed":3000}'>
    <ul class="am-slides">
      <?php if ($slideList): ?>
        <?php foreach ($slideList as $slide): ?>
        <li><a href="<?php echo !empty($slide['link']) ? htmlspecialchars($slide['link']) : 'javascript:;'; ?>" target="_blank">
          <div class="ddsgg" style="background: url(<?php echo htmlspecialchars($slide['litpic']); ?>) no-repeat center; background-size:cover;">
            <div class="jz"><div class="bn_bt"></div></div>
          </div>
        </a></li>
        <?php endforeach; ?>
      <?php else: ?>
        <li><a href="javascript:;">
          <div class="ddsgg" style="background: url(<?php echo $site['template_dir']; ?>static/upload/image/20220801/1659354277651388.jpg) no-repeat center; background-size:cover;">
            <div class="jz"><div class="bn_bt"></div></div>
          </div>
        </a></li>
      <?php endif; ?>
    </ul>
  </div>
</div>
<div class="sbanner">
  <div data-am-widget="slider" class="am-slider am-slider-a2" data-am-slider='{"controlNav":true,"slideshowSpeed":3000}'>
    <ul class="am-slides">
      <?php if ($slideList): ?>
        <?php foreach ($slideList as $idx => $slide): ?>
        <li><a href="<?php echo !empty($slide['link']) ? htmlspecialchars($slide['link']) : 'javascript:;'; ?>" target="_blank">
          <div class="ddsgg" style="background: url(<?php echo htmlspecialchars($slide['litpic']); ?>) no-repeat center; background-size:cover;">
            <div class="jz"><div class="bn_bt"></div></div>
          </div>
        </a></li>
        <?php endforeach; ?>
      <?php else: ?>
        <li><a href="javascript:;">
          <div class="ddsgg" style="background: url(<?php echo $site['template_dir']; ?>static/upload/image/20220801/1659354519922523.jpg) no-repeat center; background-size:cover;">
            <div class="jz"><div class="bn_bt"></div></div>
          </div>
        </a></li>
      <?php endif; ?>
    </ul>
  </div>
</div>
<div class="cont">
  <div class="jz">
    <div class="c_bka">
      <div data-am-widget="slider" class="am-slider am-slider-c3 c_bkat l" data-am-slider='{"slideshowSpeed":4000,"controlNav":false}' style="padding:7px;">
        <ul class="am-slides">
          <li><img src="<?php echo !empty($recommendImage['litpic']) ? htmlspecialchars($recommendImage['litpic']) : $site['template_dir'] . 'static/upload/image/20220801/1659355113381146.jpg'; ?>" height="322" width="550" id="homeMainImage"></li>
        </ul>
      </div>
      <div class="c_ycxw r">
        <div data-am-widget="tabs" class="am-tabs am-tabs-default">
          <ul class="am-tabs-nav am-cf">
            <?php foreach ($articleChannels as $i => $ch): ?>
            <li class="<?php echo $i === 0 ? 'am-active' : ''; ?>"><a data-href="[data-tab-panel-<?php echo $i+1; ?>]" rel="nofollow"><?php echo htmlspecialchars($ch['channel_name']); ?></a></li>
            <?php endforeach; ?>
          </ul>
          <div class="am-tabs-bd">
            <?php foreach ($articleChannels as $i => $ch): ?>
            <?php $tabArticles = $db->fetchAll("SELECT * FROM {$db->table('article')} WHERE channel_id = ? AND status = 1 ORDER BY create_time DESC LIMIT 6", [$ch['id']]); ?>
            <?php if (empty($tabArticles)) {
                $tabArticles = $db->fetchAll("SELECT * FROM {$db->table('article')} WHERE status = 1 ORDER BY create_time DESC LIMIT 6");
            } ?>
            <div data-tab-panel-<?php echo $i+1; ?> class="am-tab-panel <?php echo $i === 0 ? 'am-active' : ''; ?>">
              <ul class="cyc_cnw">
                <?php foreach (array_slice($tabArticles, 0, 5) as $a): ?>
                <li><a href="<?php echo getUrl('article', $a['id']); ?>" title="<?php echo htmlspecialchars($a['title']); ?>" class="sjbzn l"><i class="am-icon-angle-right"></i><?php echo htmlspecialchars($a['title']); ?></a><span class="r"><?php echo date('Y-m-d', $a['create_time']); ?></span></li>
                <?php endforeach; ?>
              </ul>
              <div class="home-news-card-list">
                <?php foreach (array_slice($tabArticles, 0, 3) as $a): ?>
                <a href="<?php echo getUrl('article', $a['id']); ?>" class="home-news-card" title="<?php echo htmlspecialchars($a['title']); ?>">
                  <span class="home-news-card-title"><?php echo htmlspecialchars($a['title']); ?></span>
                  <span class="home-news-card-date"><?php echo date('Y-m-d', $a['create_time']); ?></span>
                </a>
                <?php endforeach; ?>
              </div>
              <a href="<?php echo getUrl('channel', $ch['id'], $ch['channel_dir'] ?? ''); ?>"><div class="am-tab-panel_more c">查看更多 <span>></span></div></a>
            </div>
            <?php endforeach; ?>
          </div>
        </div>
      </div>
    </div>
    <div class="h50"></div>
    <div class="sybt c">
      <h1>服务中心</h1>
      <h2>SERVICE CENTER</h2>
      <span class="sybt_line"></span>
    </div>
    <ul class="syfwfl c" id="homeProductTabs">
      <?php foreach ($productChannels as $i => $ch): ?>
      <li class="<?php echo $i === 0 ? 'cur' : ''; ?>"><a href="javascript:;" data-channel-id="<?php echo intval($ch['id']); ?>" onclick="switchHomeProductTab(this, <?php echo intval($ch['id']); ?>)"><?php echo htmlspecialchars($ch['channel_name']); ?></a></li>
      <?php endforeach; ?>
    </ul>
    <ul class="syfwlb c" id="homeProductList">
      <?php foreach ($allProducts as $p): ?>
      <li>
        <a href="<?php echo getUrl('product', $p['id']); ?>" title="<?php echo htmlspecialchars($p['title']); ?>">
          <span class="sytpdz"><img src="<?php echo !empty($p['litpic']) ? htmlspecialchars($p['litpic']) : $site['template_dir'] . 'static/upload/image/20220801/1659323496152728.jpg'; ?>" alt="<?php echo htmlspecialchars($p['title']); ?>"></span>
          <span class="syfwmc"><?php echo htmlspecialchars($p['title']); ?></span>
          <span class="syfwyc">查看详情</span>
        </a>
      </li>
      <?php endforeach; ?>
    </ul>
    <script>
    window.homeProductMap = <?php echo json_encode($productMap, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); ?>;
    function switchHomeProductTab(el, channelId) {
      document.querySelectorAll('#homeProductTabs li').forEach(function(li){ li.classList.remove('cur'); });
      if (el && el.parentNode) el.parentNode.classList.add('cur');
      var wrap = document.getElementById('homeProductList');
      var rows = window.homeProductMap && window.homeProductMap[channelId] ? window.homeProductMap[channelId] : [];
      if (!wrap) return;
      if (!rows.length) {
        wrap.innerHTML = '<li style="grid-column:1/-1;text-align:center;padding:40px 0;color:#999;">暂无产品</li>';
        return;
      }
      wrap.innerHTML = rows.map(function(p){
        var pic = p.litpic && p.litpic !== '' ? p.litpic : '<?php echo $site['template_dir']; ?>static/upload/image/20220801/1659323496152728.jpg';
        return '<li><a href="/public/index.php?m=product&id=' + p.id + '" title="' + (p.title || '') + '"><span class="sytpdz"><img src="' + pic + '" alt="' + (p.title || '') + '"></span><span class="syfwmc">' + (p.title || '') + '</span><span class="syfwyc">查看详情</span></a></li>';
      }).join('');
    }
    </script>
  </div>
</div>
<div class="bg_hs1 c">
  <div class="jz c">
    <div class="sybt c sybt1">
      <h1>公司介绍</h1>
      <h2>ABOUT US</h2>
      <span class="sybt_line"></span>
    </div>
    <div class="sygsjj c">
      <div class="gsjj_nr c"><?php echo $companyIntro ? $companyIntro : '<p>请在后台站点设置中完善公司介绍。</p>'; ?></div>
    </div>
  </div>
</div>
<div class="jz c">
  <div class="h50"></div>
  <div class="sybt c">
    <h1>服务案例</h1>
    <h2>SERVICE CASE</h2>
    <span class="sybt_line"></span>
  </div>
  <ul class="syanli c">
    <?php foreach ($caseProducts as $p): ?>
    <li>
      <a href="<?php echo getUrl('product', $p['id']); ?>" title="<?php echo htmlspecialchars($p['title']); ?>">
        <span class="altp"><img src="<?php echo !empty($p['litpic']) ? htmlspecialchars($p['litpic']) : $site['template_dir'] . 'static/upload/image/20220801/1659323496152728.jpg'; ?>" alt="<?php echo htmlspecialchars($p['title']); ?>"></span>
        <span class="albt"><?php echo htmlspecialchars($p['title']); ?></span>
      </a>
    </li>
    <?php endforeach; ?>
  </ul>
  <div class="h50"></div>
</div>
<?php require_once __DIR__ . '/_footer.php'; ?>
