diff --git a/app/index/controller/Goods.php b/app/index/controller/Goods.php index 84dda7b22..f86bc08a9 100755 --- a/app/index/controller/Goods.php +++ b/app/index/controller/Goods.php @@ -152,6 +152,10 @@ class Goods extends Common // 是否商品详情页展示相册 MyViewAssign('common_is_goods_detail_show_photo', MyC('common_is_goods_detail_show_photo', 0, true)); + // 面包屑导航 + $breadcrumb_data = GoodsService::GoodsBreadcrumbData($goods); + MyViewAssign('breadcrumb_data', $breadcrumb_data); + // 加载放大镜 MyViewAssign('is_load_imagezoom', 1); diff --git a/app/index/controller/Search.php b/app/index/controller/Search.php index 6691cbea6..c559148bc 100755 --- a/app/index/controller/Search.php +++ b/app/index/controller/Search.php @@ -109,6 +109,10 @@ class Search extends Common // 排序方式 MyViewAssign('map_order_by_list', SearchService::SearchMapOrderByList($this->data_request)); + // 面包屑导航 + $breadcrumb_data = SearchService::SearchBreadcrumbData($params); + MyViewAssign('breadcrumb_data', $breadcrumb_data); + // 搜索记录 $params['user_id'] = empty($this->user) ? 0 : $this->user['id']; $params['search_result_data'] = $ret['data']; diff --git a/app/index/view/default/category/index.html b/app/index/view/default/category/index.html index cbcdc4198..90911eb12 100755 --- a/app/index/view/default/category/index.html +++ b/app/index/view/default/category/index.html @@ -24,7 +24,7 @@ {{foreach $goods_category_list as $v}}
  • - + {{if !empty($v['icon'])}} {{$v.name}} {{/if}} @@ -37,14 +37,14 @@ {{else /}}
      {{foreach $goods_category_list as $k=>$v}} -
    • {{$v.name}}
    • +
    • {{$v.name}}
    • {{/foreach}}
    {{foreach $goods_category_list as $k=>$v}}
  • {{if !empty($vs['icon'])}} - + {{$vs.name}} {{/if}}

    - {{$vs.name}} + {{$vs.name}}

  • {{/foreach}} @@ -77,7 +77,7 @@ {{elseif $category_show_level eq 3}} {{foreach $v.items as $vs}}
    - +
    {{$vs.name}}
    @@ -87,12 +87,12 @@ {{foreach $vs.items as $kss=>$vss}}
  • {{if !empty($vss['icon'])}} - + {{$vss.name}} {{/if}}

    - {{$vss.name}} + {{$vss.name}}

  • {{/foreach}} @@ -106,7 +106,7 @@ 没有子分类数据

    - 查看分类下商品 >> + 查看分类下商品 >>

    {{/if}} diff --git a/app/index/view/default/goods/index.html b/app/index/view/default/goods/index.html index 413aa74ae..c966e09c2 100755 --- a/app/index/view/default/goods/index.html +++ b/app/index/view/default/goods/index.html @@ -12,6 +12,10 @@ {{include file="public/goods_category" /}} + +{{include file="public/breadcrumb_data" /}} + +
    diff --git a/app/index/view/default/index/index.html b/app/index/view/default/index/index.html index be16cbb25..7ad5fca54 100755 --- a/app/index/view/default/index/index.html +++ b/app/index/view/default/index/index.html @@ -177,7 +177,7 @@ {{/if}}
    - 更多 + 更多
    @@ -208,7 +208,7 @@
    {{if !empty($floor['items']) and is_array($floor['items'])}} {{foreach $floor.items as $category_key=>$category}} - {{:mb_substr($category['name'], 0, 4, 'utf-8')}} + {{:mb_substr($category['name'], 0, 4, 'utf-8')}} {{/foreach}} {{/if}}
    @@ -216,7 +216,7 @@
    {{$floor.describe}}
    {{if !empty($floor['big_images'])}} - + {{/if}} diff --git a/app/index/view/default/public/breadcrumb_data.html b/app/index/view/default/public/breadcrumb_data.html new file mode 100644 index 000000000..433f11b77 --- /dev/null +++ b/app/index/view/default/public/breadcrumb_data.html @@ -0,0 +1,40 @@ +{{if !empty($breadcrumb_data)}} + +{{/if}} \ No newline at end of file diff --git a/app/index/view/default/search/index.html b/app/index/view/default/search/index.html index 4e3f94f7e..7be1aa782 100755 --- a/app/index/view/default/search/index.html +++ b/app/index/view/default/search/index.html @@ -26,6 +26,9 @@ {{/foreach}} {{/if}} + +{{include file="public/breadcrumb_data" /}} +
    diff --git a/app/service/GoodsService.php b/app/service/GoodsService.php index 02b436876..16e230183 100755 --- a/app/service/GoodsService.php +++ b/app/service/GoodsService.php @@ -3122,5 +3122,66 @@ class GoodsService } return DataReturn('处理成功', 0, $result); } + + /** + * 商品面包屑导航数据 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-07-06 + * @desc description + * @param [array] $goods [商品信息] + */ + public static function GoodsBreadcrumbData($goods) + { + // 默认首页 + $result = [ + [ + 'type' => 0, + 'name' => '首页', + 'url' => SystemService::HomeUrl(), + 'icon' => 'am-icon-home', + ], + ]; + // 商品分类 + $cids = Db::name('GoodsCategoryJoin')->where(['goods_id'=>$goods['id']])->column('category_id'); + if(!empty($cids)) + { + $where = [ + ['id', 'in', $cids], + ['is_enable', '=', 1], + ]; + $category = Db::name('GoodsCategory')->where($where)->field('id,name')->select()->toArray(); + if(!empty($category)) + { + $category = array_map(function($v) + { + $v['url'] = MyUrl('index/search/index', ['cid'=>$v['id']]); + return $v; + }, $category); + if(count($category) == 1) + { + $result[] = [ + 'type' => 0, + 'name' => $category[0]['name'], + 'url' => $category[0]['url'], + ]; + } else { + $result[] = [ + 'type' => 1, + 'name' => '商品分类', + 'data' => $category, + ]; + } + } + } + + // 当前商品名称 + $result[] = [ + 'type' => 0, + 'name' => $goods['title'], + ]; + return $result; + } } ?> \ No newline at end of file diff --git a/app/service/NavigationService.php b/app/service/NavigationService.php index e3d126ec7..0a69d68d2 100755 --- a/app/service/NavigationService.php +++ b/app/service/NavigationService.php @@ -192,7 +192,7 @@ class NavigationService // 商品分类 case 'goods_category': - $v['url'] = MyUrl('index/search/index', ['category_id'=>$v['value']]); + $v['url'] = MyUrl('index/search/index', ['cid'=>$v['value']]); break; // 页面设计 diff --git a/app/service/SearchService.php b/app/service/SearchService.php index 37fae494b..bf6fce8ee 100755 --- a/app/service/SearchService.php +++ b/app/service/SearchService.php @@ -798,7 +798,173 @@ class SearchService 'category' => empty($category) ? null : $category, 'brand' => empty($brand) ? null : $brand, ]; - + } + + /** + * 搜索面包屑导航 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-07-06 + * @desc description + * @param [array] $params [输入参数] + */ + public static function SearchBreadcrumbData($params = []) + { + // 默认首页 + $result = [ + [ + 'type' => 0, + 'name' => '首页', + 'url' => SystemService::HomeUrl(), + 'icon' => 'am-icon-home', + ], + ]; + // 商品分类 + $temp_data = []; + if(!empty($params['cid'])) + { + // 一级 + $where = [ + ['id', '=', intval($params['cid'])], + ['is_enable', '=', 1], + ]; + $category = Db::name('GoodsCategory')->where($where)->field('id,pid,name')->find(); + if(!empty($category)) + { + $where = [ + ['pid', '=', $category['pid']], + ['is_enable', '=', 1], + ]; + $category_list = Db::name('GoodsCategory')->where($where)->field('id,pid,name')->select()->toArray(); + if(!empty($category_list)) + { + array_unshift($temp_data, [ + 'id' => $category['id'], + 'name' => $category['name'], + 'type' => 1, + 'data' => array_map(function($v) + { + $v['url'] = MyUrl('index/search/index', ['cid'=>$v['id']]); + return $v; + }, $category_list), + ]); + + // 二级 + $where = [ + ['id', '=', $category['pid']], + ['is_enable', '=', 1], + ]; + $category = Db::name('GoodsCategory')->where($where)->field('id,pid,name')->find(); + if(!empty($category)) + { + $where = [ + ['pid', '=', $category['pid']], + ['is_enable', '=', 1], + ]; + $category_list = Db::name('GoodsCategory')->where($where)->field('id,pid,name')->select()->toArray(); + if(!empty($category_list)) + { + array_unshift($temp_data, [ + 'id' => $category['id'], + 'name' => $category['name'], + 'type' => 1, + 'data' => array_map(function($v) + { + $v['url'] = MyUrl('index/search/index', ['cid'=>$v['id']]); + return $v; + }, $category_list), + ]); + + // 三级 + $where = [ + ['id', '=', $category['pid']], + ['is_enable', '=', 1], + ]; + $category = Db::name('GoodsCategory')->where($where)->field('id,pid,name')->find(); + if(!empty($category)) + { + $where = [ + ['pid', '=', $category['pid']], + ['is_enable', '=', 1], + ]; + $category_list = Db::name('GoodsCategory')->where($where)->field('id,pid,name')->select()->toArray(); + if(!empty($category_list)) + { + array_unshift($temp_data, [ + 'id' => $category['id'], + 'name' => $category['name'], + 'type' => 1, + 'data' => array_map(function($v) + { + $v['url'] = MyUrl('index/search/index', ['cid'=>$v['id']]); + return $v; + }, $category_list), + ]); + } + } + } + } + } + } + } + + // 品牌、价格、关键字、属性、规格 + // 集合名称 + $temp_name = []; + + // 品牌 + $bid = empty($params['bid']) ? (empty($params['brand_id']) ? 0 : intval($params['brand_id'])) : intval($params['bid']); + if(!empty($bid)) + { + $brand = Db::name('Brand')->where(['id'=>$bid])->field('id,name')->find(); + if(!empty($brand)) + { + $temp_name[] = $brand['name']; + } + } + + // 价格区间 + if(!empty($params['peid'])) + { + $price = Db::name('ScreeningPrice')->where(['id'=>intval($params['peid'])])->field('id,name')->find(); + if(!empty($price)) + { + $temp_name[] = $price['name']; + } + } + + // 搜索关键字 + if(!empty($params['wd'])) + { + $temp_name[] = $params['wd']; + } + + // 属性 + if(!empty($params['psid'])) + { + $temp_name[] = AsciiToStr($params['psid']); + } + + // 规格 + if(!empty($params['scid'])) + { + $temp_name[] = AsciiToStr($params['scid']); + } + if(!empty($temp_name)) + { + $temp_data[] = [ + 'type' => 0, + 'name' => implode(' / ', $temp_name).'搜索结果', + ]; + } + + // 数据合并 + if(!empty($temp_data)) + { + $result = array_merge($result, $temp_data); + } + return $result; } } ?> \ No newline at end of file diff --git a/public/static/index/default/css/common.css b/public/static/index/default/css/common.css index 82dc51a60..804e95aba 100755 --- a/public/static/index/default/css/common.css +++ b/public/static/index/default/css/common.css @@ -120,7 +120,7 @@ input.add,input.min{width:15px} .am-footer {text-align:center; display:block;position: relative;margin: 0px auto; padding: 10px 0px; } /*分类*/ - .goods-category-s {display:block;position: absolute;z-index: 1020;} + .goods-category-s {display:block;position: absolute;z-index: 1021;} .goods-category-s .all-goods, .goods-category-title .all-goods {font-size: 16px;} .goods-category-title{background:#d2364c;color:#fff ;height: 40px;line-height: 44px;display:block;position: absolute;width:150px ;text-align: center;top:0px;cursor: pointer;} .goods-category-s .category-content{ position:relative; width: 150px; float: left;background:#fff; top: 45px;} @@ -1103,4 +1103,22 @@ legend a.am-fr { .second-nav li.am-active a:hover { background-color: #1cc09f !important; color: #fff !important; +} + +/** + * 面包屑导航 + */ +.breadcrumb-data { + background: #f5f5f5; +} +.breadcrumb-data .am-breadcrumb { + padding-top: 10px; + padding-bottom: 10px; +} +.breadcrumb-data .am-breadcrumb li a { + text-decoration: none; + color: #666; +} +.breadcrumb-data .am-breadcrumb li a:hover { + color: #d2364c; } \ No newline at end of file diff --git a/public/static/index/default/css/goods.css b/public/static/index/default/css/goods.css index 81fb7a9a8..8b5a1b8d1 100755 --- a/public/static/index/default/css/goods.css +++ b/public/static/index/default/css/goods.css @@ -454,7 +454,7 @@ flex: 1 1 0%;line-height: 16px;cursor: pointer;} .scoll .goods-video-submit-close { top: 10px; } /* 基础主体 */ - .item-inform { margin-bottom: 10px; } + .item-inform { margin-top: 10px; margin-bottom: 10px; } } @media only screen and (min-width:1025px) { @@ -480,7 +480,7 @@ flex: 1 1 0%;line-height: 16px;cursor: pointer;} .theme-signin-left .cart-title{margin-left: -46px;float: left;} .scoll{display: none;} - .item-inform{max-width:1000px; background:#fff; margin-top: 20px; margin-bottom: 30px; } + .item-inform{max-width:1000px; background:#fff; margin-bottom: 30px; } .clearfix-left{display:block;float: left;width:350px;} .clearfix-right{width:calc(100% - 370px);margin-left:10px;} .freight{width:400px;float: left;} @@ -529,7 +529,7 @@ flex: 1 1 0%;line-height: 16px;cursor: pointer;} /* 小于1025 */ @media only screen and (max-width:1025px) { ul.am-tabs-nav.am-nav.am-nav-tabs { width:100% !important; left: 0px !important; } - .goods-detail { padding: 10px 5px; } + .goods-detail { padding: 0 5px 10px 5px; } } /* 手机模式下 */