From 6b4c67eaf6c0aeb7036b9d7ad76b8b4f3b827bd2 Mon Sep 17 00:00:00 2001
From: gongfuxiang <2499232802@qq.com>
Date: Sat, 8 Sep 2018 15:35:18 +0800
Subject: [PATCH] search
---
.../Controller/SearchController.class.php | 11 ++++++--
.../Home/View/Default/Search/Index.html | 5 +++-
.../Service/SearchService.class.php | 28 ++++++++++---------
service/Public/Common/Css/Common.css | 2 +-
service/Public/Home/Default/Js/Search.js | 16 ++++++++++-
5 files changed, 44 insertions(+), 18 deletions(-)
diff --git a/service/Application/Home/Controller/SearchController.class.php b/service/Application/Home/Controller/SearchController.class.php
index 55cb2f2ce..be1b349e8 100755
--- a/service/Application/Home/Controller/SearchController.class.php
+++ b/service/Application/Home/Controller/SearchController.class.php
@@ -85,8 +85,15 @@ class SearchController extends CommonController
public function GoodsList()
{
$data = SearchService::GoodsList($this->params);
- $msg = empty($data['data']) ? L('common_not_data_tips') : L('common_operation_success');
- $this->ajaxReturn($msg, 0, $data);
+ if(empty($data['data']))
+ {
+ $msg = L('common_not_data_tips');
+ $code = -100;
+ } else {
+ $msg = L('common_operation_success');
+ $code = 0;
+ }
+ $this->ajaxReturn($msg, $code, $data);
}
}
?>
\ No newline at end of file
diff --git a/service/Application/Home/View/Default/Search/Index.html b/service/Application/Home/View/Default/Search/Index.html
index 15e394e2c..c99c0e057 100755
--- a/service/Application/Home/View/Default/Search/Index.html
+++ b/service/Application/Home/View/Default/Search/Index.html
@@ -105,7 +105,10 @@
-
+
+ {{:L('common_not_data_tips')}}
+
+
diff --git a/service/Application/Service/SearchService.class.php b/service/Application/Service/SearchService.class.php
index 748e1dc04..fa345085c 100644
--- a/service/Application/Service/SearchService.class.php
+++ b/service/Application/Service/SearchService.class.php
@@ -14,7 +14,7 @@ use Service\GoodsService;
class SearchService
{
/**
- * 根据分类id获取同级列表
+ * 根据分类id获取下级列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
@@ -24,9 +24,6 @@ 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'=>$params['category_id']]);
}
@@ -61,15 +58,21 @@ class SearchService
'total' => 450,
'data' => [],
];
- $goods_where = [
+ $where = [
'g.is_delete_time' => 0,
'g.is_shelves' => 1,
];
+ // 关键字
+ if(!empty($params['keywords']))
+ {
+ $where['g.title'] = ['like', '%'.$params['keywords'].'%'];
+ }
+
// 品牌
if(!empty($params['brand_id']))
{
- $goods_where['g.brand_id'] = intval($params['brand_id']);
+ $where['g.brand_id'] = intval($params['brand_id']);
}
// 分类id
@@ -77,7 +80,7 @@ class SearchService
{
$category_ids = GoodsService::GoodsCategoryItemsIds(['category_id'=>$params['category_id']]);
$category_ids[] = $params['category_id'];
- $goods_where['gci.id'] = ['in', $category_ids];
+ $where['gci.id'] = ['in', $category_ids];
}
// 筛选价格
@@ -86,21 +89,21 @@ class SearchService
$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'] = [
+ $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']];
+ $where['g.price'] = ['EGT', $price['min_price']];
} else if(!empty($price['max_price']))
{
- $goods_where['g.price'] = ['LT', $price['max_price']];
+ $where['g.price'] = ['LT', $price['max_price']];
}
}
// 获取商品总数
- $result['total'] = GoodsService::GoodsTotal(['where'=>$goods_where]);
+ $result['total'] = GoodsService::GoodsTotal(['where'=>$where]);
// 获取商品列表
if($result['total'] > 0)
@@ -108,8 +111,7 @@ class SearchService
$page = intval(I('page', 1));
$n = 10;
$m = intval(($page-1)*$n);
- $result['data'] = GoodsService::GoodsList(['where'=>$goods_where, 'm'=>$m, 'n'=>$n]);
-
+ $result['data'] = GoodsService::GoodsList(['where'=>$where, 'm'=>$m, 'n'=>$n]);
$result['page_total'] = ceil($result['total']/$n);
}
return $result;
diff --git a/service/Public/Common/Css/Common.css b/service/Public/Common/Css/Common.css
index 9fcf83087..4558938ef 100755
--- a/service/Public/Common/Css/Common.css
+++ b/service/Public/Common/Css/Common.css
@@ -1,5 +1,5 @@
/* 没数据 */
-.table-no {text-align:center;padding-top:30px !important;background:#FFF !important;}
+.table-no {text-align:center;padding-top:30px !important;background:#FFF !important; color: #888; }
/* 公共dl样式 */
.dl-content dt { float: left; padding-left: 5px; overflow: hidden; clear: left;
diff --git a/service/Public/Home/Default/Js/Search.js b/service/Public/Home/Default/Js/Search.js
index 49fb76192..e3dcbb065 100755
--- a/service/Public/Home/Default/Js/Search.js
+++ b/service/Public/Home/Default/Js/Search.js
@@ -143,7 +143,7 @@ $(function()
data:data,
success:function(result)
{
- if(result.code == 0 && result.data.data.length > 0)
+ if(result.code == 0)
{
for(var i in result.data.data)
{
@@ -161,6 +161,20 @@ $(function()
$('.data-list').append(html);
}
$('.search-pages-submit').attr('data-page', data.page+1);
+ $('.search-pages-submit').attr('disabled', (result.data.page_total <= 1));
+ $('.search-pages-submit').show();
+ $('.table-no').hide();
+ } else if(result.code == -100) {
+ if($('.data-list li').length == 0)
+ {
+ $('.table-no').show();
+ $('.search-pages-submit').hide();
+ } else {
+ $('.table-no').hide();
+ $('.search-pages-submit').show();
+ $('.search-pages-submit').attr('disabled', true);
+ }
+ Prompt(result.msg);
} else {
Prompt(result.msg);
}