From c8c4880074d5c187310f9960b891478835bdb429 Mon Sep 17 00:00:00 2001 From: gongfuxiang <2499232802@qq.com> Date: Sun, 2 Jun 2019 02:02:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common.php | 47 ++++++++++++ application/index/controller/Search.php | 74 +++++++++++++------ .../index/view/default/public/nav_search.html | 2 +- application/service/GoodsService.php | 16 ++++ 4 files changed, 114 insertions(+), 25 deletions(-) diff --git a/application/common.php b/application/common.php index 292fb9d54..c452fae7a 100755 --- a/application/common.php +++ b/application/common.php @@ -11,6 +11,53 @@ // 应用公共文件 +/** + * 字符串转ascii + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-06-02T01:13:47+0800 + * @param [string] $str [字符串] + * @return [string] [转换后的ascii] + */ +function StrToAscii($str) +{ + $change_after = ''; + if(!empty($str)) + { + $str = mb_convert_encoding($str, 'GB2312'); + for($i=0;$iparams['brand_id'] = intval(input('brand_id', 0)); - - // 分类id - $this->params['category_id'] = intval(input('category_id', 0)); - - // 筛选价格id - $this->params['screening_price_id'] = intval(input('screening_price_id', 0)); - - // 搜索关键字 - $this->params['wd'] = str_replace(['?', ' ', '+', '-'], '', trim(input('wd'))); - - // 排序方式 - $this->params['order_by_field'] = input('order_by_field', 'default'); - $this->params['order_by_type'] = input('order_by_type', 'desc'); - - // 用户信息 - $this->params['user_id'] = isset($this->user['id']) ? $this->user['id'] : 0; } - + /** * 首页 * @author Devil @@ -66,11 +48,14 @@ class Search extends Common */ public function Index() { - if(input('post.')) + $keywords = input('post.wd'); + if(!empty($keywords)) { - $p = empty($this->params['wd']) ? [] : ['wd'=>$this->params['wd']]; - return redirect(MyUrl('index/search/index', $p)); + return redirect(MyUrl('index/search/index', ['wd'=>StrToAscii($keywords)])); } else { + // 参数初始化 + $this->ParamsInit(); + // 品牌列表 $this->assign('brand_list', BrandService::CategoryBrandList(['category_id'=>$this->params['category_id'], 'keywords'=>$this->params['wd']])); @@ -84,12 +69,50 @@ class Search extends Common $this->assign('params', $this->params); // 浏览器名称 - $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle('商品搜索', 1)); + if(!empty($this->params['category_id'])) + { + $seo_name = GoodsService::GoodsCategoryValue($this->params['category_id'], 'name', '商品搜索'); + } else { + $seo_name = empty($this->params['wd']) ? '商品搜索' : $this->params['wd']; + } + $this->assign('home_seo_site_title', SeoService::BrowserSeoTitle($seo_name, 1)); return $this->fetch(); } } + /** + * 参数初始化 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-06-02T01:38:27+0800 + */ + private function ParamsInit() + { + // 参数 + $params = input(); + + // 品牌id + $this->params['brand_id'] = isset($params['brand_id']) ? intval($params['brand_id']) : 0; + + // 分类id + $this->params['category_id'] = isset($params['category_id']) ? intval($params['category_id']) : 0; + + // 筛选价格id + $this->params['screening_price_id'] = isset($params['screening_price_id']) ? intval($params['screening_price_id']) : 0; + + // 搜索关键字 + $this->params['wd'] = empty($params['wd']) ? '' : (IS_AJAX ? trim($params['wd']) : AsciiToStr($params['wd'])); + + // 排序方式 + $this->params['order_by_field'] = empty($params['order_by_field']) ? 'default' : $params['order_by_field']; + $this->params['order_by_type'] = empty($params['order_by_type']) ? 'desc' : $params['order_by_type']; + + // 用户信息 + $this->params['user_id'] = isset($this->user['id']) ? $this->user['id'] : 0; + } + /** * 获取商品列表 * @author Devil @@ -100,6 +123,9 @@ class Search extends Common */ public function GoodsList() { + // 参数初始化 + $this->ParamsInit(); + // 获取商品列表 $this->params['keywords'] = $this->params['wd']; $ret = SearchService::GoodsList($this->params); diff --git a/application/index/view/default/public/nav_search.html b/application/index/view/default/public/nav_search.html index 07d22a787..5bd31fb43 100755 --- a/application/index/view/default/public/nav_search.html +++ b/application/index/view/default/public/nav_search.html @@ -20,7 +20,7 @@ {{if !empty($home_search_keywords)}} {{/if}} diff --git a/application/service/GoodsService.php b/application/service/GoodsService.php index 8635b2a5f..002c8b65b 100755 --- a/application/service/GoodsService.php +++ b/application/service/GoodsService.php @@ -2163,5 +2163,21 @@ class GoodsService } return DataReturn('删除失败', -100); } + + /** + * 获取商品分类字段字段数据 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @datetime 2019-06-02T01:51:31+0800 + * @param [int] $category_id [商品分类id] + * @param [string] $field [指定字段值] + * @param [string] $default [默认值] + */ + public static function GoodsCategoryValue($category_id, $field, $default = null) + { + $value = Db::name('GoodsCategory')->where(['id'=>intval($category_id)])->value($field); + return ($value === null) ? $default : $value; + } } ?> \ No newline at end of file