vr-shopxo-source/app/index/controller/Search.php

223 lines
7.5 KiB
PHP
Raw Normal View History

2018-12-28 10:58:37 +00:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\index\controller;
2019-03-11 09:57:15 +00:00
use app\service\SeoService;
2021-01-10 05:18:35 +00:00
use app\service\SearchService;
2018-12-28 10:58:37 +00:00
/**
* 搜索
* @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();
2021-01-10 05:18:35 +00:00
}
2018-12-28 10:58:37 +00:00
/**
* 首页
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-02-22T16:50:32+0800
*/
public function Index()
{
2019-06-01 18:02:00 +00:00
$keywords = input('post.wd');
if(!empty($keywords))
2018-12-28 10:58:37 +00:00
{
2021-07-18 15:42:10 +00:00
return MyRedirect(MyUrl('index/search/index', ['wd'=>StrToAscii($keywords)]));
2021-06-28 06:54:51 +00:00
}
// 搜素条件
$map = SearchService::SearchWhereHandle($this->data_request);
// 获取商品列表
$ret = SearchService::GoodsList($map, $this->data_request);
// 分页
$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();
// 关键字处理
$params = $this->data_request;
if(!empty($params['wd']))
{
$params['wd'] = AsciiToStr($params['wd']);
}
// 基础参数赋值
2022-07-01 03:00:15 +00:00
MyViewAssign('is_map', $map['is_map']);
MyViewAssign('params', $params);
MyViewAssign('page_html', $page_html);
MyViewAssign('data_total', $ret['data']['total']);
MyViewAssign('data_list', $ret['data']['data']);
2018-12-28 10:58:37 +00:00
2021-06-28 06:54:51 +00:00
// 品牌列表
$brand_list = SearchService::SearchMapHandle(SearchService::CategoryBrandList($map, $this->data_request), 'bid', 'id', $this->data_request);
2021-07-18 15:42:10 +00:00
MyViewAssign('brand_list', $brand_list);
2021-06-28 06:54:51 +00:00
// 指定数据
$search_map_info = SearchService::SearchMapInfo($this->data_request);
2021-07-18 15:42:10 +00:00
MyViewAssign('search_map_info', $search_map_info);
2018-12-28 10:58:37 +00:00
2021-06-28 06:54:51 +00:00
// 商品分类
$category_list = SearchService::SearchMapHandle(SearchService::GoodsCategoryList($this->data_request), 'cid', 'id', $this->data_request);
2021-07-18 15:42:10 +00:00
MyViewAssign('category_list', $category_list);
2021-01-10 05:18:35 +00:00
2021-06-28 06:54:51 +00:00
// 筛选价格区间
$screening_price_list = SearchService::SearchMapHandle(SearchService::ScreeningPriceList($this->data_request), 'peid', 'id', $this->data_request);
2021-07-18 15:42:10 +00:00
MyViewAssign('screening_price_list', $screening_price_list);
2021-01-10 05:18:35 +00:00
2021-06-28 06:54:51 +00:00
// 商品参数
$goods_params_list = SearchService::SearchMapHandle(SearchService::SearchGoodsParamsValueList($map, $this->data_request), 'psid', 'id', $this->data_request, ['is_ascii'=>true, 'field'=>'value']);
2021-07-18 15:42:10 +00:00
MyViewAssign('goods_params_list', $goods_params_list);
2018-12-28 10:58:37 +00:00
2021-06-28 06:54:51 +00:00
// 商品规格
$goods_spec_list = SearchService::SearchMapHandle(SearchService::SearchGoodsSpecValueList($map, $this->data_request), 'scid', 'id', $this->data_request, ['is_ascii'=>true, 'field'=>'value']);
2021-07-18 15:42:10 +00:00
MyViewAssign('goods_spec_list', $goods_spec_list);
2018-12-28 10:58:37 +00:00
// 排序方式
MyViewAssign('map_order_by_list', SearchService::SearchMapOrderByList($this->data_request));
2022-07-06 14:28:40 +00:00
// 面包屑导航
$breadcrumb_data = SearchService::SearchBreadcrumbData($params);
MyViewAssign('breadcrumb_data', $breadcrumb_data);
// 搜索记录
$params['user_id'] = empty($this->user) ? 0 : $this->user['id'];
$params['search_result_data'] = $ret['data'];
SearchService::SearchAdd($params);
2019-03-11 09:57:15 +00:00
2021-06-28 06:54:51 +00:00
// seo
$this->SetSeo($search_map_info, $params);
2019-07-29 07:44:55 +00:00
2021-06-28 06:54:51 +00:00
// 钩子
$this->PluginsHook();
2021-07-18 15:42:10 +00:00
return MyView();
2018-12-28 10:58:37 +00:00
}
2019-06-02 13:45:10 +00:00
/**
* seo设置
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-01-11
* @desc description
* @param [array] $data [条件基础数据]
* @param [array] $params [输入参数]
2019-06-02 13:45:10 +00:00
*/
private function SetSeo($data = [], $params = [])
2019-06-02 13:45:10 +00:00
{
// 默认关键字
$seo_title = empty($params['wd']) ? '' : $params['wd'];
// 分类、品牌
$seo_data = empty($data['category']) ? (empty($data['brand']) ? [] : $data['brand']) : $data['category'];
if(!empty($seo_data))
2019-06-02 13:45:10 +00:00
{
$seo_title = empty($seo_data['seo_title']) ? $seo_data['name'] : $seo_data['seo_title'];
// 关键字和描述
if(!empty($seo_data['seo_keywords']))
2019-06-02 13:45:10 +00:00
{
2021-07-18 15:42:10 +00:00
MyViewAssign('home_seo_site_keywords', $seo_data['seo_keywords']);
}
if(!empty($seo_data['seo_desc']))
{
2021-07-18 15:42:10 +00:00
MyViewAssign('home_seo_site_description', $seo_data['seo_desc']);
}
2019-06-02 13:45:10 +00:00
}
2021-07-18 15:42:10 +00:00
MyViewAssign('home_seo_site_title', SeoService::BrowserSeoTitle(empty($seo_title) ? '商品搜索' : $seo_title, 1));
2019-06-02 13:45:10 +00:00
}
2019-07-28 10:52:31 +00:00
/**
* 钩子处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-04-22
* @desc description
*/
private function PluginsHook()
{
2021-01-10 05:18:35 +00:00
$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',
];
foreach($hook_arr as $hook_name)
{
2021-07-18 15:42:10 +00:00
MyViewAssign($hook_name.'_data', MyEventTrigger($hook_name,
2021-01-10 05:18:35 +00:00
[
'hook_name' => $hook_name,
'is_backend' => false,
]));
}
2019-07-28 10:52:31 +00:00
}
2018-12-28 10:58:37 +00:00
}
?>