115 lines
5.4 KiB
PHP
115 lines
5.4 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\Category;
|
|
use App\Models\Product;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
$product = new Product();
|
|
$category = new Category();
|
|
$catId = isset($_GET['cat']) ? (int)$_GET['cat'] : 0;
|
|
|
|
$products = $catId
|
|
? $product->byCategory($catId)
|
|
: array_filter($product->all(), fn($p) => ($p['status'] ?? 1) == 1);
|
|
$cat = $catId ? $category->find($catId) : null;
|
|
|
|
$catName = $cat['name'] ?? '';
|
|
if ($cat) {
|
|
$seo = page_seo('product_category', [
|
|
'title' => $catName . '降温服 - 酷冰甲科技降温·定制批发',
|
|
'description' => "酷冰甲{$catName}系列降温服,采用科技降温方案,专为高温作业与户外暴晒场景设计,具备清凉持久、轻便透气、可循环重复使用等特点。支持企业定制、LOGO刺绣与小批量批发,10套起订,7天打样,全国发货。",
|
|
'keywords' => $catName . '降温服,' . $catName . ',降温服定制,降温背心,工业降温,酷冰甲',
|
|
]);
|
|
foreach (['title', 'description', 'keywords'] as $f) {
|
|
$seo[$f] = str_replace('{cat}', $catName, $seo[$f]);
|
|
}
|
|
} else {
|
|
$seo = page_seo('products', [
|
|
'title' => '降温服产品中心 - 水冷/相变/风冷多系列 | 酷冰甲',
|
|
'description' => '酷冰甲降温服产品中心,系统展示水冷循环降温服、相变冰袋降温背心、风冷制冷背心、冰马甲等多系列产品,按使用场景与降温方式分类,参数规格与适用行业一目了然。支持企业批量定制、LOGO刺绣与免费拿样,提供专业选型建议与透明报价,助力高温作业安全防护。',
|
|
'keywords' => '降温服产品,水冷降温服,相变降温服,风冷降温服,制冷背心,冰马甲,工业降温装备,降温服批发,降温服定制,酷冰甲产品',
|
|
]);
|
|
}
|
|
$pageTitle = $catName ? $catName . ' - 产品中心' : '产品中心';
|
|
$pageDesc = $catName ? str_replace('{cat}', $catName, "酷冰甲{cat}系列降温服,科技降温,清凉定制。") : '酷冰甲全系列降温服产品:水冷循环、相变蓄冷、涡扇风冷、工业降温工装,支持小批量定制。';
|
|
|
|
return $this->view('product/index', [
|
|
'pageSeo' => [
|
|
'title' => $seo['title'],
|
|
'description' => $seo['description'],
|
|
'keywords' => $seo['keywords'],
|
|
'og_type' => 'website',
|
|
'og_image' => $seo['og_image'],
|
|
'canonical' => $seo['canonical'],
|
|
'noindex' => $seo['noindex'],
|
|
'breadcrumb' => $catName ? [
|
|
['name' => '首页', 'url' => site_url()],
|
|
['name' => '产品中心', 'url' => site_url('products')],
|
|
['name' => $catName, 'url' => absolute_url()],
|
|
] : null,
|
|
],
|
|
'products' => $products,
|
|
'categories'=> $category->all(),
|
|
'activeCat' => $catId,
|
|
'cat' => $cat,
|
|
]);
|
|
}
|
|
|
|
public function show($slug)
|
|
{
|
|
$product = new Product();
|
|
$p = $product->where('slug', $slug);
|
|
if (!$p && is_numeric($slug)) { $p = $product->find((int)$slug); }
|
|
if (!$p) { \Core\App::notFound(); return ''; }
|
|
|
|
$category = new Category();
|
|
$cat = $category->find($p['category_id'] ?? 0);
|
|
$related = array_filter($product->byCategory($p['category_id'] ?? 0), fn($x) => $x['id'] != $p['id']);
|
|
|
|
$pName = e($p['name'] ?? '产品详情');
|
|
$pSummary = mb_substr(strip_tags($p['summary'] ?? $p['body'] ?? ''), 0, 160);
|
|
$pImage = $p['image'] ?? '';
|
|
$pPrice = $p['price'] ?? '';
|
|
$pSku = $p['sku'] ?? ($p['model'] ?? '');
|
|
|
|
// ── Product JSON-LD Schema ──
|
|
$productSchema = '<script type="application/ld+json">' . json_encode([
|
|
'@context' => 'https://schema.org',
|
|
'@type' => 'Product',
|
|
'name' => $p['name'] ?? '',
|
|
'description' => $pSummary,
|
|
'image' => $pImage,
|
|
'sku' => $pSku,
|
|
'category' => $cat['name'] ?? '',
|
|
] + ($pPrice ? ['offers' => [
|
|
'@type' => 'Offer',
|
|
'price' => $pPrice,
|
|
'priceCurrency' => 'CNY',
|
|
'availability' => 'https://schema.org/InStock',
|
|
]] : []), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . '</script>';
|
|
|
|
return $this->view('product/show', [
|
|
'pageSeo' => [
|
|
'title' => $pName,
|
|
'description' => $pSummary,
|
|
'og_type' => 'product',
|
|
'og_image' => $pImage,
|
|
'breadcrumb' => [
|
|
['name' => '首页', 'url' => site_url()],
|
|
['name' => '产品中心', 'url' => site_url('products')],
|
|
['name' => $p['name'] ?? '产品', 'url' => absolute_url()],
|
|
],
|
|
'jsonld' => $productSchema,
|
|
],
|
|
'p' => $p,
|
|
'cat' => $cat,
|
|
'related' => array_slice($related, 0, 3),
|
|
'specs' => $product->specsArray($p),
|
|
]);
|
|
}
|
|
}
|