diff --git a/service/Application/Common/Conf/config.php b/service/Application/Common/Conf/config.php index 1dd3011f1..f2e0fcb44 100755 --- a/service/Application/Common/Conf/config.php +++ b/service/Application/Common/Conf/config.php @@ -14,7 +14,7 @@ return array( 'IS_DEVELOP' => true, // 显示页面Trace信息 - 'SHOW_PAGE_TRACE' => false, + 'SHOW_PAGE_TRACE' => true, // 允许访问的模块列表 'MODULE_ALLOW_LIST' => array('Admin', 'Api', 'Home'), diff --git a/service/Application/Common/Lang/zh-cn.php b/service/Application/Common/Lang/zh-cn.php index ce12dd089..398156e3d 100755 --- a/service/Application/Common/Lang/zh-cn.php +++ b/service/Application/Common/Lang/zh-cn.php @@ -41,7 +41,7 @@ return array( 'common_ip_name' => 'ip地址', 'common_admin_name' => '管理员', 'common_not_login_name' => '未登录', - 'common_not_data_tips' => '没有数据', + 'common_not_data_tips' => '没有相关数据', 'common_create_time_name' => '创建时间', 'common_reg_time_name' => '注册时间', 'common_upd_time_name' => '更新时间', diff --git a/service/Application/Home/Controller/SearchController.class.php b/service/Application/Home/Controller/SearchController.class.php index 36fdea73e..55cb2f2ce 100755 --- a/service/Application/Home/Controller/SearchController.class.php +++ b/service/Application/Home/Controller/SearchController.class.php @@ -28,9 +28,15 @@ class SearchController extends CommonController // 调用父类前置方法 parent::_initialize(); + // 品牌id + $this->params['brand_id'] = intval(I('brand_id', 0)); + // 分类id $this->params['category_id'] = intval(I('category_id', 0)); + // 筛选价格id + $this->params['screening_price_id'] = intval(I('screening_price_id', 0)); + // 搜索关键字 $this->params['keywords'] = trim(I('keywords')); @@ -79,7 +85,8 @@ class SearchController extends CommonController public function GoodsList() { $data = SearchService::GoodsList($this->params); - $this->ajaxReturn(L('common_operation_success'), 0, $data); + $msg = empty($data['data']) ? L('common_not_data_tips') : L('common_operation_success'); + $this->ajaxReturn($msg, 0, $data); } } ?> \ No newline at end of file diff --git a/service/Application/Home/View/Default/Public/GoodsCategory.html b/service/Application/Home/View/Default/Public/GoodsCategory.html index 030ca8255..912fc7906 100755 --- a/service/Application/Home/View/Default/Public/GoodsCategory.html +++ b/service/Application/Home/View/Default/Public/GoodsCategory.html @@ -1,9 +1,11 @@
-
- 全部分类 -
+ +
+ 全部分类 +
+
style="display:none;">
    diff --git a/service/Application/Home/View/Default/Search/Index.html b/service/Application/Home/View/Default/Search/Index.html index a008d3e19..15e394e2c 100755 --- a/service/Application/Home/View/Default/Search/Index.html +++ b/service/Application/Home/View/Default/Search/Index.html @@ -27,9 +27,9 @@

    - 分类 - 复古复古 - 筛选结果 + 筛选出 + ... + 条数据

  • @@ -45,7 +45,7 @@
    不限
    -
    {{$brand.name}}
    +
    {{$brand.name}}
    没有相关品牌 @@ -60,7 +60,7 @@
    不限
    -
    {{$category.name}}
    +
    {{$category.name}}
    没有相关分类 @@ -74,8 +74,8 @@
    不限
    - -
    {{$price.name}}
    + +
    {{$screening_price.name}}
    没有相关价格 diff --git a/service/Application/Service/GoodsService.class.php b/service/Application/Service/GoodsService.class.php index 99517145e..6ac495d32 100755 --- a/service/Application/Service/GoodsService.class.php +++ b/service/Application/Service/GoodsService.class.php @@ -159,6 +159,21 @@ class GoodsService return $data; } + /** + * 获取商品总数 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2018-09-07 + * @desc description + * @param array $params [输入参数: where, field, is_photo] + */ + public static function GoodsTotal($params = []) + { + $where = empty($params['where']) ? [] : $params['where']; + return (int) M('Goods')->alias('g')->join(' INNER JOIN __GOODS_CATEGORY_JOIN__ AS gci ON g.id=gci.goods_id')->where($where)->count('DISTINCT g.id'); + } + /** * 获取商品列表 * @author Devil @@ -180,7 +195,7 @@ class GoodsService $m = isset($params['m']) ? intval($params['m']) : 0; $n = isset($params['n']) ? intval($params['n']) : 10; - $data = M('Goods')->alias('g')->join(' INNER JOIN __GOODS_CATEGORY_JOIN__ AS gci ON g.id=gci.goods_id') ->field($field)->where($where)->group('g.id')->order($order_by)->limit($m, $n)->select(); + $data = M('Goods')->alias('g')->join(' INNER JOIN __GOODS_CATEGORY_JOIN__ AS gci ON g.id=gci.goods_id')->field($field)->where($where)->group('g.id')->order($order_by)->limit($m, $n)->select(); if(!empty($data)) { $images_host = C('IMAGE_HOST'); diff --git a/service/Application/Service/SearchService.class.php b/service/Application/Service/SearchService.class.php index 907030f9f..748e1dc04 100644 --- a/service/Application/Service/SearchService.class.php +++ b/service/Application/Service/SearchService.class.php @@ -25,9 +25,9 @@ class SearchService public static function GoodsCategoryList($params = []) { // 根据分类id获取同级列表 - $category = GoodsService::GoodsCategoryRow(['id'=>$params['category_id']]); - $pid = empty($category['pid']) ? 0 : $category['pid']; - return GoodsService::GoodsCategoryList(['pid'=>$pid]); + // $category = GoodsService::GoodsCategoryRow(['id'=>$params['category_id']]); + // $pid = empty($category['pid']) ? 0 : $category['pid']; + return GoodsService::GoodsCategoryList(['pid'=>$params['category_id']]); } /** @@ -57,14 +57,61 @@ class SearchService public static function GoodsList($params = []) { $result = [ - 'total' => 0, - 'data' => [], + 'page_total' => 0, + 'total' => 450, + 'data' => [], ]; $goods_where = [ - 'g.is_delete_time' => 0, + 'g.is_delete_time' => 0, + 'g.is_shelves' => 1, ]; - $result['data'] = GoodsService::GoodsList(['where'=>$goods_where]); + // 品牌 + if(!empty($params['brand_id'])) + { + $goods_where['g.brand_id'] = intval($params['brand_id']); + } + + // 分类id + if(!empty($params['category_id'])) + { + $category_ids = GoodsService::GoodsCategoryItemsIds(['category_id'=>$params['category_id']]); + $category_ids[] = $params['category_id']; + $goods_where['gci.id'] = ['in', $category_ids]; + } + + // 筛选价格 + if(!empty($params['screening_price_id'])) + { + $price = M('ScreeningPrice')->field('min_price,max_price')->where(['is_enable'=>1, 'id'=>intval($params['screening_price_id'])])->find(); + if(!empty($price['min_price']) && !empty($price['max_price'])) + { + $goods_where['g.price'] = [ + ['EGT', $price['min_price']], + ['LT', $price['max_price']], + ]; + } else if(!empty($price['min_price'])) + { + $goods_where['g.price'] = ['EGT', $price['min_price']]; + } else if(!empty($price['max_price'])) + { + $goods_where['g.price'] = ['LT', $price['max_price']]; + } + } + + // 获取商品总数 + $result['total'] = GoodsService::GoodsTotal(['where'=>$goods_where]); + + // 获取商品列表 + if($result['total'] > 0) + { + $page = intval(I('page', 1)); + $n = 10; + $m = intval(($page-1)*$n); + $result['data'] = GoodsService::GoodsList(['where'=>$goods_where, 'm'=>$m, 'n'=>$n]); + + $result['page_total'] = ceil($result['total']/$n); + } return $result; } } diff --git a/service/Public/Home/Default/Css/Common.css b/service/Public/Home/Default/Css/Common.css index 69ea88939..5906f1b3d 100755 --- a/service/Public/Home/Default/Css/Common.css +++ b/service/Public/Home/Default/Css/Common.css @@ -50,8 +50,9 @@ body{margin:0; a:link,a:visited,a:hover{text-decoration:none; outline:none;} +a:hover, a:focus { color: #d2364c; } + /*所有超链接不要下划线*/ - *, *:after, *:before{ -webkit-box-sizing: border-box; -moz-box-sizing: border-box; diff --git a/service/Public/Home/Default/Css/Search.css b/service/Public/Home/Default/Css/Search.css index fca09d19b..f641c6975 100755 --- a/service/Public/Home/Default/Css/Search.css +++ b/service/Public/Home/Default/Css/Search.css @@ -142,7 +142,7 @@ dl#select3 .dd-conent{ left:-200%; right:0px;} .nav.white{padding-left:0px} /*选中效果*/ - .search-list ul li:hover .i-pic.limit,.search-side li:hover .i-pic.check{box-shadow:0px 12px 12px -10px rgba(0,0,0,.4);} + .search-list ul li:hover .i-pic.limit,.search-side li:hover .i-pic.check{box-shadow:0px 12px 12px -10px rgba(0,0,0,.4); border: 1px solid #d2364c; } } @media only screen and (max-width: 640px) { diff --git a/service/Public/Home/Default/Js/Search.js b/service/Public/Home/Default/Js/Search.js index a1c5255e5..49fb76192 100755 --- a/service/Public/Home/Default/Js/Search.js +++ b/service/Public/Home/Default/Js/Search.js @@ -9,17 +9,20 @@ $(function() $('#'+selected_tag_name).remove(); } else { if ($('#'+selected_tag_name).length > 0) { - $('#'+selected_tag_name).find("a").html($(this).text()); + $('#'+selected_tag_name).find('a').html($(this).find('a').text()); + $('#'+selected_tag_name).find('a').attr('data-value', $(this).find('a').attr('data-value')); } else { var copy_html = $(this).clone(); $(".select-result dl").append(copy_html.attr("id", selected_tag_name)); } } + get_goods_list(1); }); $(document).on('click', '.select-result dl dd', function() { $(this).remove(); $('#'+$(this).attr('id')+'-dl').find('.select-all').addClass('selected').siblings().removeClass('selected'); + get_goods_list(1); }); $(document).on('click', 'ul.select dd', function() { @@ -39,7 +42,7 @@ $(function() $(this).hide(); $('.select-result .select-no').show(); $('.select-result').hide(); - + get_goods_list(1); }); @@ -113,15 +116,31 @@ $(function() search_nav(); // 获取商品列表 - function get_goods_list() + function get_goods_list(page) { - var keywords = $('#search-input').val() || ''; + // 请求参数处理 + var data = { + keywords: $('#search-input').val() || '', + page: page || parseInt($('.search-pages-submit').attr('data-page')) || 1, + } + $('.select-result .selected a').each(function(k, v) + { + data[$(this).attr('data-field')] = $(this).attr('data-value'); + }); + + // 清空数据 + if(data.page == 1) + { + $('.data-list').html(''); + } + + // 请求数据 $.ajax({ url:$('.search-pages-submit').data('url'), type:'POST', dataType:"json", timeout:10000, - data:{keywords: keywords}, + data:data, success:function(result) { if(result.code == 0 && result.data.data.length > 0) @@ -131,6 +150,8 @@ $(function() var html = '
  • '; html += ''; html += ''; + html += ''; + html += ''; html += '

    '+result.data.data[i]['title']+'

    '; html += '
    '; html += '

    ¥'+result.data.data[i]['price']+'

    '; @@ -139,10 +160,11 @@ $(function() $('.data-list').append(html); } - + $('.search-pages-submit').attr('data-page', data.page+1); } else { Prompt(result.msg); } + $('.select .title-tips strong').text(result.data.total); }, error:function(xhr, type) { @@ -150,6 +172,12 @@ $(function() } }); } - get_goods_list(); + get_goods_list(1); + + // 加载更多数据 + $('.search-pages-submit').on('click', function() + { + get_goods_list(); + }); }); \ No newline at end of file