...
|
...
|
@@ -13,10 +13,10 @@ class HelperSearch |
|
|
*/
|
|
|
public static $params = array();
|
|
|
|
|
|
private static $from = '';
|
|
|
|
|
|
public static $options = array();
|
|
|
//当前页
|
|
|
public static $page = 1;
|
|
|
public static $siteDomain = '.yohobuy.com';
|
|
|
|
|
|
/**
|
|
|
* 选中的条件
|
...
|
...
|
@@ -29,19 +29,16 @@ class HelperSearch |
|
|
*/
|
|
|
public static $listnav = array();
|
|
|
|
|
|
|
|
|
private static function setFrom($from = '')
|
|
|
{
|
|
|
if ($from) {
|
|
|
self::$from = $from;
|
|
|
}
|
|
|
}
|
|
|
//设置导航
|
|
|
private static function setListNav($option = array())
|
|
|
private static function setListNav()
|
|
|
{
|
|
|
if (isset(self::$options['controller']) && self::$options['controller'] == 'Search') {
|
|
|
|
|
|
}
|
|
|
$options = self::$options;
|
|
|
$cookieChannel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
|
|
|
if (isset($option['brandName']) && !empty($option['brandName'])) {
|
|
|
$initNav = $option['brandName'];
|
|
|
if (isset($options['brandName']) && !empty($options['brandName'])) {
|
|
|
$initNav = $options['brandName'];
|
|
|
}else{
|
|
|
$initNav = '列表';
|
|
|
}
|
...
|
...
|
@@ -64,6 +61,7 @@ class HelperSearch |
|
|
{
|
|
|
$result = array();
|
|
|
self::$params = $_GET;
|
|
|
self::$options = $options;
|
|
|
unset(self::$params['/']);
|
|
|
unset(self::$params['page']);
|
|
|
unset(self::$params['/sale']);
|
...
|
...
|
@@ -80,10 +78,8 @@ class HelperSearch |
|
|
$result['filters']['checkedConditions']['clearUrl'] = self::current();
|
|
|
//频道
|
|
|
$result['filters']['channel'] = self::gender($filter);
|
|
|
//分类
|
|
|
$result['filters']['sort'] = array();
|
|
|
//品牌
|
|
|
$result['filters']['brand'] = self::brand($filter, $options);
|
|
|
$result['filters']['brand'] = self::brand($filter);
|
|
|
//价格
|
|
|
$result['filters']['price'] = self::price($filter);
|
|
|
$result['filters']['customPrice'] = self::customPrice($filter);
|
...
|
...
|
@@ -109,8 +105,10 @@ class HelperSearch |
|
|
$result['opts']['pageCount'] = $data['data']['page_total'];
|
|
|
$result['opts']['nextHref'] = ($next = self::next($data['data']['page_total'],$data['data']['filter'])) ? $next['href'] : '';
|
|
|
$result['hasNextPage'] = self::next($data['data']['page_total']);
|
|
|
//分类
|
|
|
$result['leftContent'][]['allSort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
|
|
|
//分类条件
|
|
|
$result['filters']['sort'] = isset($filter['group_sort']) ? self::searchSort($filter['group_sort']) : array();
|
|
|
//左侧分类分类
|
|
|
$result['leftContent'][]['allSort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort']) : array();
|
|
|
//一周新品上架
|
|
|
$result['leftContent'][]['newSales'] = isset($filter['recent']) ? self::recentShelve($filter['recent']) : array();
|
|
|
//全部折扣
|
...
|
...
|
@@ -121,6 +119,9 @@ class HelperSearch |
|
|
$result['pager'] = self::pager($result['totalCount'],$options['viewNum']);
|
|
|
//选中条件
|
|
|
$result['filters']['checkedConditions']['conditions'] = self::getSelected();
|
|
|
if (isset($options['controller']) && $options['controller'] == 'Search') {
|
|
|
self::setSearchNav($data['data']['total']);
|
|
|
}
|
|
|
$result['pathNav'] = self::$listnav;
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
@@ -193,6 +194,9 @@ class HelperSearch |
|
|
'name' => $pval['standard_name'],
|
|
|
'href' => self::buildUrl($tmpParams)
|
|
|
);
|
|
|
if (self::checkSearch('parameter_' . $val['standard_id'])) {
|
|
|
return array();
|
|
|
}
|
|
|
}
|
|
|
$sub[] = array(
|
|
|
'name' => $pval['standard_name'],
|
...
|
...
|
@@ -222,9 +226,6 @@ class HelperSearch |
|
|
}
|
|
|
$params = self::$params;
|
|
|
$gender = isset($params['gender']) ? $params['gender'] : '';
|
|
|
if (isset($params['gender'])) {
|
|
|
unset($params['gender']);
|
|
|
}
|
|
|
//设置选中
|
|
|
if ($gender == '1,3' || $gender == '2,3') {
|
|
|
self::$selected['gender'] = array(
|
...
|
...
|
@@ -232,6 +233,12 @@ class HelperSearch |
|
|
'href' => self::buildUrl($params)
|
|
|
);
|
|
|
}
|
|
|
if (isset($params['gender'])) {
|
|
|
unset($params['gender']);
|
|
|
}
|
|
|
if (self::checkSearch('gender')) {
|
|
|
return array();
|
|
|
}
|
|
|
$result = array();
|
|
|
foreach ($filter['gender'] as $key => $val) {
|
|
|
$result[] = array(
|
...
|
...
|
@@ -247,12 +254,15 @@ class HelperSearch |
|
|
/**
|
|
|
* 组织搜索列表页面的左侧分类
|
|
|
* @param array $sort
|
|
|
* @param array $option
|
|
|
* @return array
|
|
|
*/
|
|
|
|
|
|
public static function groupSort($sort, $option = array())
|
|
|
public static function groupSort($sort)
|
|
|
{
|
|
|
$option = self::$options;
|
|
|
if (!isset($option['controller']) || $option['controller'] != 'Search') {
|
|
|
return array();
|
|
|
}
|
|
|
//设置导航
|
|
|
self::setListNav($option);
|
|
|
$params = self::$params;
|
...
|
...
|
@@ -297,13 +307,51 @@ class HelperSearch |
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
public static function searchSort($sort)
|
|
|
{
|
|
|
$result = array();
|
|
|
$options = self::$options;
|
|
|
if (!isset($options['controller']) || $options['controller'] != 'Search') {
|
|
|
return $result;
|
|
|
}
|
|
|
$params = self::$params;
|
|
|
foreach ($sort as $key => $val) {
|
|
|
$result[$key]['id'] = $val['sort_id'];
|
|
|
$result[$key]['name'] = $val['sort_name'];
|
|
|
if (isset($params['msort']) && $params['msort'] == $val['sort_id']) {
|
|
|
unset($params['msort']);
|
|
|
self::$selected['sort'] = array(
|
|
|
'name' => $val['sort_name'],
|
|
|
'href' => self::buildUrl($params)
|
|
|
);
|
|
|
}
|
|
|
if (isset($val['sub']) && !empty($val['sub'])) {
|
|
|
foreach ($val['sub'] as $k => $v) {
|
|
|
$result[$key]['sub'][$k]['href'] = self::buildUrl(array_merge($params, array('msort' => $val['sort_id'], 'misort' => $v['sort_id'])));
|
|
|
$result[$key]['sub'][$k]['name'] = $v['sort_name'];
|
|
|
if (isset($params['misort']) && $params['misort'] == $v['sort_id']) {
|
|
|
unset($params['misort']);
|
|
|
self::$selected['sort'] = array(
|
|
|
'name' => $v['sort_name'],
|
|
|
'href' => self::buildUrl($params)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if (self::checkSearch('msrot') || self::checkSearch('misort')) {
|
|
|
return array();
|
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
/**
|
|
|
* 品牌,可以多选
|
|
|
* @param array $filter
|
|
|
* @param array $options
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function brand($filter, $options = array()) {
|
|
|
public static function brand($filter) {
|
|
|
$options = self::$options;
|
|
|
//品牌列表返回空
|
|
|
if (isset($options['brandName'])) {
|
|
|
return array();
|
...
|
...
|
@@ -311,11 +359,15 @@ class HelperSearch |
|
|
$result = array(
|
|
|
'default' => array() ,
|
|
|
'brandIndex' => array(
|
|
|
'0~9',
|
|
|
'A~G',
|
|
|
'H~N',
|
|
|
'O~T',
|
|
|
'U~Z') ,
|
|
|
array(
|
|
|
'index' => 'all',
|
|
|
'name' => '全部'
|
|
|
),
|
|
|
array(
|
|
|
'index' => '0-9',
|
|
|
'name' => '0 ~ 9'
|
|
|
)
|
|
|
),
|
|
|
'brandsShow' => array()
|
|
|
);
|
|
|
$params = self::$params;
|
...
|
...
|
@@ -341,12 +393,18 @@ class HelperSearch |
|
|
)));
|
|
|
}
|
|
|
$this_brand = array(
|
|
|
'brand_id' => $v['id'],
|
|
|
'name' => $v['brand_name'],
|
|
|
'alif' => $v['brand_alif'],
|
|
|
'id' => $v['id'],
|
|
|
'href' => $url,
|
|
|
'name' => $v['brand_name'],
|
|
|
'key' => $v['brand_name'],
|
|
|
'active' => in_array($v['id'], $brandIds) ? true : false
|
|
|
);
|
|
|
if (is_numeric($v['brand_alif'])) {
|
|
|
$this_brand['index'] = '0-9';
|
|
|
}
|
|
|
else {
|
|
|
$this_brand['index'] = strtolower($v['brand_alif']);
|
|
|
}
|
|
|
//默认品牌
|
|
|
if (count($result['default']) < 10) {
|
|
|
$result['default'][] = $this_brand;
|
...
|
...
|
@@ -367,9 +425,20 @@ class HelperSearch |
|
|
'href' => self::buildUrl($params)
|
|
|
);
|
|
|
}
|
|
|
//品牌列表排序
|
|
|
//搜索页已选中,返回空
|
|
|
if (self::checkSearch('brand')) {
|
|
|
return array();
|
|
|
}
|
|
|
ksort($brandList);
|
|
|
//品牌列表排序, 添加品牌索引
|
|
|
$index_key = array();
|
|
|
foreach ($brandList as $key => $val) {
|
|
|
if ($key && !in_array($key, $index_key)) {
|
|
|
$index['index'] = strtolower(($key));
|
|
|
$index['name'] = $key;
|
|
|
$result['brandIndex'][] = $index;
|
|
|
$index_key[] = $index;
|
|
|
}
|
|
|
if (is_array($val)) {
|
|
|
foreach ($val as $v) {
|
|
|
$result['brandsShow'][] = $v;
|
...
|
...
|
@@ -402,6 +471,9 @@ class HelperSearch |
|
|
'href' => self::buildUrl($params)
|
|
|
);
|
|
|
}
|
|
|
if (self::checkSearch('size')) {
|
|
|
return array();
|
|
|
}
|
|
|
$result[] = array(
|
|
|
'name' => $v['size_name'],
|
|
|
'href' => self::buildUrl(array_merge($params, array(
|
...
|
...
|
@@ -443,6 +515,9 @@ class HelperSearch |
|
|
))) ,
|
|
|
);
|
|
|
}
|
|
|
if (self::checkSearch('color')) {
|
|
|
return array();
|
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -474,6 +549,9 @@ class HelperSearch |
|
|
);
|
|
|
}
|
|
|
}
|
|
|
if (self::checkSearch('price')) {
|
|
|
return array();
|
|
|
}
|
|
|
//返回价格条件
|
|
|
foreach ($filter['price'] as $key => $val) {
|
|
|
$val = trim($val,'¥');
|
...
|
...
|
@@ -556,6 +634,10 @@ class HelperSearch |
|
|
'href' => $url,
|
|
|
);
|
|
|
}
|
|
|
//搜索页已选中,返回空
|
|
|
if (self::checkSearch('style')) {
|
|
|
return array();
|
|
|
}
|
|
|
$data[0] = array(
|
|
|
'attr' => 'style',
|
|
|
'name' => '风格',
|
...
|
...
|
@@ -942,7 +1024,13 @@ class HelperSearch |
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
//分页
|
|
|
|
|
|
/**
|
|
|
* 分页
|
|
|
* @param $total
|
|
|
* @param $viewNum
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public static function pager($total,$viewNum){
|
|
|
$Paging = new Paging('Yoho');
|
|
|
return $Paging->setTotal($total)->setSize($viewNum)->view(0);
|
...
|
...
|
@@ -968,4 +1056,66 @@ class HelperSearch |
|
|
return $result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 组织品牌店铺信息
|
|
|
*/
|
|
|
public static function shop($shop)
|
|
|
{
|
|
|
$shopEntry = array();
|
|
|
$sort = array();
|
|
|
foreach ($shop['sort'] as $msort) {
|
|
|
if (!isset($msort['sub']) || empty($msort['sub'])) {
|
|
|
continue;
|
|
|
}
|
|
|
foreach ($msort['sub'] as $mkey=>$misort) {
|
|
|
if (count($sort) >= 10) {
|
|
|
break 2;
|
|
|
}
|
|
|
$sortInfo['href'] = 'http://' . $shop['brand_domain'] . self::$siteDomain.'/?msort=' . $msort['sort_id'] . '&misort=' . $misort['sort_id'];
|
|
|
$sortInfo['name'] = $misort['sort_name'];
|
|
|
$sort[] = $sortInfo;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
$shopEntry['home'] = $shop['brand_domain'].'yohobuy.com';
|
|
|
$shopEntry['logo'] = Images::getSourceUrl($shop['brand_ico'],'brandLogo');
|
|
|
$shopEntry['shopName'] = $shop['brand_name'];
|
|
|
$shopEntry['sort'] = $sort;
|
|
|
return $shopEntry;
|
|
|
}
|
|
|
|
|
|
public static function checkSearch($param)
|
|
|
{
|
|
|
if (isset(self::$params[$param]) && isset(self::$options['controller']) && self::$options['controller'] == 'Search') {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置搜索页导航
|
|
|
* @param $total
|
|
|
*/
|
|
|
public static function setSearchNav($total)
|
|
|
{
|
|
|
self::$listnav[0] = array(
|
|
|
'href' => '/',
|
|
|
'name' => '首页'
|
|
|
);
|
|
|
$param = self::$params;
|
|
|
$options = self::$options;
|
|
|
if (isset($options['controller']) && $options['controller'] == 'Search' && isset($param['query'])) {
|
|
|
self::$listnav[1] = array(
|
|
|
'href' => '',
|
|
|
'name' => "‘".$param['query']."’ 共".$total."个结果"
|
|
|
);
|
|
|
}else{
|
|
|
self::$listnav[1] = array(
|
|
|
'href' => '',
|
|
|
'name' => '所有商品'
|
|
|
);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
} |
...
|
...
|
|