From f52243c52a6e74db1fcf68bf2d11f614e66499a0 Mon Sep 17 00:00:00 2001 From: devil Date: Sat, 8 Aug 2020 19:58:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=94=AF=E6=8C=81=E7=A9=BA?= =?UTF-8?q?=E6=A0=BC=E5=A4=9A=E4=B8=AA=E5=85=B3=E9=94=AE=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/service/SearchService.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/application/service/SearchService.php b/application/service/SearchService.php index 27ea940ef..7ea71ffe2 100755 --- a/application/service/SearchService.php +++ b/application/service/SearchService.php @@ -73,9 +73,14 @@ class SearchService ]; // 关键字 + $where_keywords = []; if(!empty($params['keywords'])) { - $where[] = ['g.title|g.model|g.simple_desc|g.seo_title|g.seo_keywords|g.seo_keywords', 'like', '%'.$params['keywords'].'%']; + $keywords = explode(' ', $params['keywords']); + foreach($keywords as $kv) + { + $where_keywords[] = ['g.title|g.model|g.simple_desc|g.seo_title|g.seo_keywords|g.seo_keywords', 'like', '%'.$kv.'%']; + } } // 品牌 @@ -112,7 +117,9 @@ class SearchService } // 获取商品总数 - $result['total'] = GoodsService::CategoryGoodsTotal($where); + $result['total'] = (int) Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->where($where)->where(function($query) use($where_keywords) { + $query->whereOr($where_keywords); + })->count('DISTINCT g.id'); // 获取商品列表 if($result['total'] > 0) @@ -130,7 +137,16 @@ class SearchService $page = max(1, isset($params['page']) ? intval($params['page']) : 1); $n = 20; $m = intval(($page-1)*$n); - $goods = GoodsService::CategoryGoodsList(['where'=>$where, 'm'=>$m, 'n'=>$n, 'order_by'=>$order_by]); + + // 查询数据 + $data = Db::name('Goods')->alias('g')->join(['__GOODS_CATEGORY_JOIN__'=>'gci'], 'g.id=gci.goods_id')->field('g.*')->where($where)->where(function($query) use($where_keywords) { + $query->whereOr($where_keywords); + })->group('g.id')->order($order_by)->limit($m, $n)->select(); + + // 数据处理 + $goods = GoodsService::GoodsDataHandle($data); + + // 返回数据 $result['data'] = $goods['data']; $result['page_total'] = ceil($result['total']/$n); } -- GitLab