<?php
namespace app\index\controller;
use app\index\controller\Common;
use app\service\SeoService;
use app\service\SearchService;
use app\service\BreadcrumbService;
* 搜索
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class Search extends Common
{
* 构造方法
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-11-30
* @desc description
*/
public function __construct()
{
parent::__construct();
}
* 首页
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-02-22T16:50:32+0800
*/
public function Index()
{
$ret = SearchService::SearchIsLoginCheck();
if($ret['code'] != 0)
{
IsUserLogin();
}
if(!empty($this->data_post['wd']))
{
return MyRedirect(MyUrl('index/search/index', ['wd'=>StrToAscii($this->data_post['wd'])]));
}
$params = $this->data_request;
$params['user_id'] = empty($this->user) ? 0 : $this->user['id'];
$check_params = $params;
if(!empty($check_params['wd']))
{
$check_params['wd'] = AsciiToStr($check_params['wd']);
}
$ret = SearchService::SearchProhibitCheck($check_params);
if($ret['code'] != 0)
{
$check_params['search_result_data'] = $ret['msg'];
SearchService::SearchAdd($check_params);
MyViewAssign([
'msg' => $ret['msg'],
'params' => $check_params
]);
return MyView('public/tips_error');
}
$map = SearchService::SearchWhereHandle($this->data_request);
$ret = SearchService::GoodsList($map, array_merge($this->data_request, ['is_spec'=>0, 'is_cart'=>0]));
$page_params = [
'number' => $ret['data']['page_size'],
'total' => $ret['data']['total'],
'where' => $this->data_request,
'page' => $ret['data']['page'],
'url' => MyUrl('index/search/index'),
'bt_number' => IsMobile() ? 2 : 4,
];
$page = new \base\Page($page_params);
$page_html = $page->GetPageHtml();
$breadcrumb_data = BreadcrumbService::Data('GoodsSearch', $params);
$list_layout_key = 'user_search_layout_type';
$list_layout_value = MySession($list_layout_key);
if(isset($this->data_request['layout']))
{
$list_layout_value = empty($this->data_request['layout']) ? 0 : intval($this->data_request['layout']);
MySession($list_layout_key, $list_layout_value);
} else {
if(empty($list_layout_value))
{
$list_layout_value = MyC('home_search_goods_show_type', 0, true);
}
}
if(!empty($params['wd']))
{
$params['wd'] = AsciiToStr($params['wd']);
}
if(!empty($params['price']))
{
$arr = explode('-', $params['price']);
if(count($arr) == 2)
{
$params['price_min'] = $arr[0];
$params['price_max'] = $arr[1];
}
}
$assign = [
'is_map' => $map['is_map'],
'params' => $params,
'page_html' => $page_html,
'data_total' => $ret['data']['total'],
'data_list' => $ret['data']['data'],
'map_order_by_list' => SearchService::SearchMapOrderByList($this->data_request),
'breadcrumb_data' => $breadcrumb_data,
'list_layout_value' => $list_layout_value,
'is_load_jrange' => 1,
'range_max_price' => SearchService::SearchGoodsMaxPrice(),
];
$assign['brand_list'] = SearchService::SearchMapHandle(SearchService::CategoryBrandList($map, $this->data_request), 'bid', 'id', $this->data_request);
$assign['search_map_info'] = SearchService::SearchMapInfo($this->data_request);
$assign['category_list'] = SearchService::SearchMapHandle(SearchService::GoodsCategoryList($this->data_request), 'cid', 'id', $this->data_request);
$assign['screening_price_list'] = SearchService::SearchMapHandle(SearchService::ScreeningPriceList($this->data_request), 'peid', 'id', $this->data_request);
$assign['goods_produce_region_list'] = SearchService::SearchMapHandle(SearchService::SearchGoodsProduceRegionList($map, $this->data_request), 'poid', 'id', $this->data_request);
$assign['goods_params_list'] = SearchService::SearchMapHandle(SearchService::SearchGoodsParamsValueList($map, $this->data_request), 'psid', 'id', $this->data_request, ['is_ascii'=>true, 'field'=>'value']);
$assign['goods_spec_list'] = SearchService::SearchMapHandle(SearchService::SearchGoodsSpecValueList($map, $this->data_request), 'scid', 'id', $this->data_request, ['is_ascii'=>true, 'field'=>'value']);
$params['user_id'] = empty($this->user) ? 0 : $this->user['id'];
$params['search_result_data'] = $ret['data'];
SearchService::SearchAdd($params);
$seo_title = empty($params['wd']) ? '' : $params['wd'];
if(!empty($assign['search_map_info']))
{
$seo_info = empty($assign['search_map_info']['category']) ? (empty($assign['search_map_info']['brand']) ? [] : $assign['search_map_info']['brand']) : $assign['search_map_info']['category'];
if(!empty($seo_info))
{
$seo_title = empty($seo_info['seo_title']) ? $seo_info['name'] : $seo_info['seo_title'];
if(!empty($seo_info['seo_keywords']))
{
$assign['home_seo_site_keywords'] = $seo_info['seo_keywords'];
}
if(!empty($seo_info['seo_desc']))
{
$assign['home_seo_site_description'] = $seo_info['seo_desc'];
}
}
}
$assign['home_seo_site_title'] = SeoService::BrowserSeoTitle(empty($seo_title) ? MyLang('search.base_nav_title') : $seo_title, 1);
MyViewAssign($assign);
$this->PluginsHook();
return MyView();
}
* 钩子处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-04-22
* @desc description
*/
private function PluginsHook()
{
$hook_arr = [
'plugins_view_search_top',
'plugins_view_search_bottom',
'plugins_view_search_inside_top',
'plugins_view_search_inside_bottom',
'plugins_view_search_data_top',
'plugins_view_search_data_bottom',
'plugins_view_search_map_top',
'plugins_view_search_nav_top',
'plugins_view_search_nav_inside_begin',
'plugins_view_search_nav_inside_end',
'plugins_view_search_map_inside_begin',
'plugins_view_search_map_inside_base_bottom',
'plugins_view_search_map_inside_end',
];
$assign = [];
foreach($hook_arr as $hook_name)
{
$assign[$hook_name.'_data'] = MyEventTrigger($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => false,
]);
}
MyViewAssign($assign);
}
}
?>