This commit is contained in:
杨丹华
2025-05-16 16:44:28 +08:00
10 changed files with 139 additions and 463 deletions

View File

@@ -13,6 +13,7 @@ use app\index\model\ProductRelatedModel;
use app\index\model\ProductSkuAttrModel;
use app\index\model\ProductSkuModel;
use app\index\model\SysBannerModel;
use app\index\model\SysBannerProdCateMappingModel;
use app\index\validate\ProductInquiryValidate;
use think\facade\View;
use think\helper\Arr;
@@ -22,12 +23,50 @@ use think\helper\Arr;
*/
class Product extends Common
{
// 获取分类页的banner图焦点横幅
private function getCategoryBanner($category_id)
{
$focus_image = [];
// 获取产品分类页焦点横幅
$banner = SysBannerModel::with(['items' => function($query) use($category_id) {
$query->withoutField([
'status',
'created_at',
'updated_at',
'deleted_at'
])
->whereExists(function($q) use($category_id) {
$r = $q->getModel()->getTable();
$m = new SysBannerProdCateMappingModel;
$q->model($m)->name($m->getName())
->where("banner_item_id = $r.id")
->where('product_category_id' , '=', $category_id);
})
->where('status', '=', 1)
->order(['sort' => 'asc', 'id' => 'desc']);
}])
->uniqueLabel(['BANNER_6808abd813d78'])
->language($this->lang_id)
->enabled(true)
->select();
if (!$banner->isEmpty()) {
$banner_map = [];
foreach ($banner as $v) {
$banner_map[$v->unique_label] = $v;
}
$focus_image = data_get($banner_map, 'BANNER_6808abd813d78')?->items->toArray();
}
return $focus_image;
}
// 产品分类 - 查看顶层分类
public function category()
{
// 参数
$param = request()->param(['id']);
// 获取产品分类页焦点横幅
View::assign('focus_image', $this->getCategoryBanner($param['id']));
// 获取分类及产品信息
$categorys_data = ProductCategoryModel::field(['id', 'pid', 'name', 'path', 'level'])
->language($this->lang_id)
@@ -96,11 +135,13 @@ class Product extends Common
foreach ($pros as $pro) {
$pros_map[$pro['group_mark']][] = $pro;
}
foreach ($list as &$it) {
if (isset($pros_map[$it['id']])) {
$it['products'] = $pros_map[$it['id']];
}
foreach ($list as $k => &$it) {
unset($it['children']);
if (!isset($pros_map[$it['id']])) {
unset($list[$k]);
continue;
}
$it['products'] = $pros_map[$it['id']];
}
unset($it);
}
@@ -116,30 +157,8 @@ class Product extends Common
// 参数
$param = request()->param(['id']);
$focus_image = [];
// 获取产品分类页焦点横幅
$banner = SysBannerModel::with(['items' => function($query) {
$query->withoutField([
'status',
'created_at',
'updated_at',
'deleted_at'
])
->where('status', '=', 1)
->order(['sort' => 'asc', 'id' => 'desc']);
}])
->uniqueLabel(['BANNER_6808abd813d78'])
->language($this->lang_id)
->enabled(true)
->select();
if (!$banner->isEmpty()) {
$banner_map = [];
foreach ($banner as $v) {
$banner_map[$v->unique_label] = $v;
}
$focus_image = data_get($banner_map, 'BANNER_6808abd813d78')?->items->toArray();
}
View::assign('focus_image', $focus_image);
View::assign('focus_image', $this->getCategoryBanner($param['id']));
// 获取分类及产品信息
$categorys_data = ProductCategoryModel::field(['id', 'name', 'level'])
@@ -488,7 +507,7 @@ class Product extends Common
$m = $map[$pro['category_id']];
$pro_map[$m['path']][] = $pro;
}
// 获取二级分类下的产品信息
foreach ($categorys as $val) {
if ($val['level'] != 2) {
@@ -496,7 +515,7 @@ class Product extends Common
}
foreach ($pro_map as $k => $pro) {
if (in_array($val['id'], explode(',', $k))) {
if (in_array($val['id'], explode(',', strval($k)))) {
$newpros[] = [
'category' => $val,
'products' => $pro,

View File

@@ -0,0 +1,15 @@
<?php
declare (strict_types = 1);
namespace app\index\model;
use app\common\model\SysBannerProdCateMappingBaseModel;
/**
* banner与产品分类关联表模型
* @mixin \think\Model
*/
class SysBannerProdCateMappingModel extends SysBannerProdCateMappingBaseModel
{
//
}

View File

@@ -16,6 +16,8 @@ Route::get('/', 'Index/index');
Route::group('product', function () {
// 产品分类页
Route::get('category/:id', 'Product/category');
// 产品分类 - 查看子类
Route::get('subcategory/:id', 'Product/subcategory');
// 产品详情页
Route::get('detail/:id', 'Product/detail');
// 产品询盘

View File

@@ -4,7 +4,17 @@
{/block}
{block name="main"}
<div class="orico_Page_category">
<!--首页主题内容 -->
<!-- banner轮播 -->
{notempty name="focus_image"}
<div class="opdBanner">
{volist name="focus_image" id="fi"}
<a {notempty name="fi.link" }href="{$fi.link}" {/notempty}>
<img src="{$fi.image}" class="opdbannerImg" />
</a>
{/volist}
</div>
{/notempty}
<!--分类/产品内容 -->
<div class="pageMain">
{volist name="list" id="vo"}
<div class="cat">
@@ -15,6 +25,7 @@
<img src="/static/index/images/more.png" class="catmoreImg" />
</a>
</div>
{notempty name="vo.products"}
<div class="ori-pd-list">
{volist name="vo.products" id="pro"}
<a class="oripditem" href="{:url('product/detail', ['id' => $pro.id])}">
@@ -29,8 +40,30 @@
</a>
{/volist}
</div>
{/notempty}
</div>
{/volist}
</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
$(function () {
// 显示第一张图片
$('.opdbannerImg').eq(0).show();
let currentIndex = 0;
const imgCount = $('.opdbannerImg').length;
setInterval(() => {
// 淡出当前图片
$('.opdbannerImg').eq(currentIndex).fadeTo(10, 0, () => {
// 隐藏当前图片
$('.opdbannerImg').eq(currentIndex).hide();
// 计算下一张图片的索引
currentIndex = (currentIndex + 1) % imgCount;
// 显示并淡入下一张图片
$('.opdbannerImg').eq(currentIndex).show().fadeTo(10, 1);
});
}, 10000);
});
</script>
{/block}

View File

@@ -25,16 +25,15 @@
</ul>
<!-- 右边子菜单-->
{volist name="header_categorys" id="vo" key="idx"}
<div class="navItem_cyright" {eq name="idx" value="1" }style="display: block;"
{else/}style="display: none;" {/eq}>
<div class="navItem_cyright" {eq name="idx" value="1" }style="display: block;"{else/}style="display: none;"{/eq}>
{volist name="vo.children" id="vc"}
<dl class="nav_cyrightit">
<dt>
<a href="{:url('product/category', ['id' => $vc.id])}">{$vc.name}</a>
<a href="{:url('product/subcategory', ['id' => $vc.id])}">{$vc.name}</a>
</dt>
{volist name="vc.children" id="vcc"}
<dd>
<a href="{:url('product/category', ['id' => $vcc.id])}">{$vcc.name}</a>
<a href="{:url('product/subcategory', ['id' => $vcc.id])}">{$vcc.name}</a>
</dd>
{/volist}
</dl>