|
|
<?php
|
|
|
|
|
|
namespace Plugin;
|
|
|
use Plugin\Images;
|
|
|
use Plugin\Paging;
|
|
|
/**
|
|
|
* 搜索辅助类
|
|
|
*/
|
...
|
...
|
@@ -10,11 +10,10 @@ class HelperSearch |
|
|
/**
|
|
|
* 请求时用的所有参数
|
|
|
*/
|
|
|
private static $params = array();
|
|
|
public static $params = array();
|
|
|
|
|
|
//当前页面
|
|
|
private static $current_url = '';
|
|
|
private static $page = 1;
|
|
|
//当前页
|
|
|
public static $page = 1;
|
|
|
|
|
|
/**
|
|
|
* 选中的条件
|
...
|
...
|
@@ -25,140 +24,109 @@ class HelperSearch |
|
|
* list分类面包屑
|
|
|
* @var array
|
|
|
*/
|
|
|
public static $listnav = array(
|
|
|
array(
|
|
|
public static $listnav = array();
|
|
|
|
|
|
|
|
|
//设置导航
|
|
|
private static function setListNav($option = array())
|
|
|
{
|
|
|
$cookieChannel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
|
|
|
if (isset($option['brandName']) && !empty($option['brandName'])) {
|
|
|
$initNav = $option['brandName'];
|
|
|
}else{
|
|
|
$initNav = '列表';
|
|
|
}
|
|
|
self::$listnav[0] = array(
|
|
|
'href' => '',
|
|
|
'name' => '首页'
|
|
|
),
|
|
|
array(
|
|
|
'name' => $cookieChannel
|
|
|
);
|
|
|
self::$listnav[1] = array(
|
|
|
'href' => '',
|
|
|
'name' => '列表'
|
|
|
)
|
|
|
);
|
|
|
|
|
|
'name' => $initNav
|
|
|
);
|
|
|
}
|
|
|
/**
|
|
|
* 组织搜索模板数据
|
|
|
* @param array $data
|
|
|
* @param array $options
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getList($data = array() , $options = array()) {
|
|
|
if (empty($data)) {
|
|
|
return array();
|
|
|
}
|
|
|
public static function getList($data = array() , $options = array())
|
|
|
{
|
|
|
$result = array();
|
|
|
self::$params = $_GET;
|
|
|
unset(self::$params['/']);
|
|
|
unset(self::$params['page']);
|
|
|
unset(self::$params['/sale']);
|
|
|
unset(self::$params['sale']);
|
|
|
$result = array();
|
|
|
if (!isset($data['data']) || !isset($data['data']['product_list']) || !is_array($data['data']['product_list'])) {
|
|
|
return array();
|
|
|
}
|
|
|
$result['product_list'] = self::getProductList($data['data']['product_list'], $options['imgSize'], $options['minImgSize'], $options['gender']);
|
|
|
$filter = $data['data']['filter'];
|
|
|
//产品列表
|
|
|
$result['goods'] = self::getProductList($data['data']['product_list'], $options['imgSize']);
|
|
|
//总页数
|
|
|
$result['page_total'] = $data['data']['page_total'];
|
|
|
$result['total'] = $data['data']['total'];
|
|
|
//当前页
|
|
|
$result['page'] = $data['data']['page'];
|
|
|
//设置当前页
|
|
|
self::$page = $result['page'];
|
|
|
//搜索条件
|
|
|
if (isset($data['data']['filter']) && !empty($data['data']['filter'])) {
|
|
|
$filter = $data['data']['filter'];
|
|
|
$result['filter']['left_sort'] = isset($filter['minsort']) ? self::minsort($filter['minsort']) : array();
|
|
|
$result['filter']['group_sort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
|
|
|
$result['filter']['size'] = self::size($filter);
|
|
|
$result['filter']['color'] = self::color($filter);
|
|
|
$result['filter']['price'] = self::price($filter);
|
|
|
$result['filter']['brand'] = self::brand($filter);
|
|
|
$result['filter']['parameters'] = self::standard($filter);
|
|
|
$result['filter']['rowNum4'] = self::rowNum();
|
|
|
$result['filter']['rowNum6'] = self::rowNum(6);
|
|
|
$result['filter']['viewNum'] = self::viewNum();
|
|
|
$result['filter']['priceSubmit'] = self::priceSubmit();
|
|
|
$result['filter']['gender'] = self::gender($filter);
|
|
|
$result['filter']['selected'] = self::getSelected();
|
|
|
$result['filter']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
|
|
|
$result['filter']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
|
|
|
$result['filter']['clear'] =self::current();
|
|
|
$result['filter']['next'] = self::next($data['data']['page_total'],$data['data']['filter']);
|
|
|
$result['filter']['listnav'] = self::$listnav;
|
|
|
$result['filter']['discount'] = self::getDiscount($filter['discount']);
|
|
|
$result['filter']['recent'] = self::recentShelve($filter['recent']);
|
|
|
$result['filter']['seniorChose'] = self::seniorChose($filter);
|
|
|
}
|
|
|
//清除选中
|
|
|
$result['filters']['checkedConditions']['clearUrl'] = self::current();
|
|
|
//频道
|
|
|
$result['filters']['channel'] = self::gender($filter);
|
|
|
//分类
|
|
|
$result['filters']['sort'] = array();
|
|
|
//品牌
|
|
|
$result['filters']['brand'] = self::brand($filter);
|
|
|
//价格
|
|
|
$result['filters']['price'] = self::price($filter);
|
|
|
//颜色
|
|
|
$result['filters']['color'] = self::color($filter);
|
|
|
//尺寸
|
|
|
$result['filters']['size'] = self::size($filter);
|
|
|
//高级选项
|
|
|
$result['filters']['seniorChose'] = self::seniorChose($filter);
|
|
|
//排序方式
|
|
|
$result['opts']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
|
|
|
//特殊:新品、特价、限量
|
|
|
$result['opts']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
|
|
|
//每行显示5个产品
|
|
|
$result['opts']['fivePerLine'] = true;
|
|
|
//每行显示6个产品
|
|
|
$result['opts']['sixPerLineHref'] = true;
|
|
|
//每页显示的数量
|
|
|
$result['opts']['countPerPage'] = $options['viewNum'];
|
|
|
//可选每页显示数量
|
|
|
$result['opts']['pageCounts'] = self::viewNum();
|
|
|
$result['opts']['curPage'] = self::$page;
|
|
|
$result['opts']['pageCount'] = $data['data']['page_total'];
|
|
|
$result['opts']['nextHref'] = self::next($data['data']['page_total'],$data['data']['filter']);
|
|
|
$result['hasNextPage'] = array(
|
|
|
'href' => self::next($data['data']['page_total'],$data['data']['filter']),
|
|
|
'src' => 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'
|
|
|
);
|
|
|
//分类
|
|
|
$result['leftContent'][]['allSort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
|
|
|
//一周新品上架
|
|
|
$result['leftContent'][]['newSales'] = self::recentShelve($filter['recent']);
|
|
|
//全部折扣
|
|
|
$result['leftContent'][]['allDiscount'] = self::getDiscount($filter['discount']);
|
|
|
//总记录数
|
|
|
$result['totalCount'] = $data['data']['total'];
|
|
|
//分页
|
|
|
$result['pager'] = self::pager($result['totalCount'],$options['viewNum']);
|
|
|
//echo $result['pager']; exit;
|
|
|
//选中条件
|
|
|
$result['filters']['checkedConditions']['conditions'] = self::getSelected();
|
|
|
$result['pathNav'] = self::$listnav;
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 组织列表模板数据
|
|
|
*
|
|
|
*/
|
|
|
public static function getTemplateData($result, $options){
|
|
|
//模板数据
|
|
|
$data = array(
|
|
|
'brandBanner' => array(),
|
|
|
'pathNav' => $result['filter']['listnav'],
|
|
|
'shopEntry' => array(),
|
|
|
'filters' => array(
|
|
|
'checkedConditions' => array(
|
|
|
'conditions' => $result['filter']['selected'],
|
|
|
'clearUrl' => $result['filter']['clear']
|
|
|
),
|
|
|
'channel' => $result['filter']['gender'],
|
|
|
'sort' => array() ,
|
|
|
'brand' => $result['filter']['brand'],
|
|
|
'price' => $result['filter']['price'],
|
|
|
'color' => $result['filter']['color'],
|
|
|
'size' => $result['filter']['size'],
|
|
|
'seniorChose' => $result['filter']['seniorChose']
|
|
|
),
|
|
|
'opts' => array(
|
|
|
'sortType' => $result['filter']['sortType'],
|
|
|
'checks' => $result['filter']['checks'],
|
|
|
'fivePerLine' => true,
|
|
|
'sixPerLineHref' => '',
|
|
|
'countPerPage' => $options['viewNum'],
|
|
|
'pageCounts' => $result['filter']['viewNum'],
|
|
|
'curPage' => $result['page'],
|
|
|
'pageCount' => $result['page_total'],
|
|
|
'nextHref' => $result['filter']['next']
|
|
|
),
|
|
|
'hasNextPage' => array(
|
|
|
'href' => $result['filter']['next'],
|
|
|
'src' => 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'
|
|
|
),
|
|
|
'goods' => $result['product_list'],
|
|
|
'leftContent' => array(
|
|
|
array(
|
|
|
'allSort' => array(
|
|
|
//'updateNum' => $result['filter']['group_sort']['all']['num'],
|
|
|
'list' => $result['filter']['group_sort']['list']
|
|
|
)
|
|
|
),
|
|
|
array(
|
|
|
'advNav' => array()
|
|
|
),
|
|
|
array(
|
|
|
'advPic' => array()
|
|
|
),
|
|
|
array(
|
|
|
'newSales' => $result['filter']['recent']
|
|
|
),
|
|
|
array('allDiscount' => $result['filter']['discount'])
|
|
|
),
|
|
|
'totalCount' => $result['total'],
|
|
|
|
|
|
);
|
|
|
return $data;
|
|
|
}
|
|
|
/**
|
|
|
* TODO 组织商品列表信息
|
|
|
* @param $product 接口返回商品列表
|
|
|
* @author sefon 2015-12-21 17:24:04
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getProductList($product,$imgSize){
|
|
|
$result = array();
|
|
|
$goods = array();
|
|
|
foreach($product as $key => $val){
|
|
|
//NEW
|
|
|
$isNew = $val['is_new'] == 'Y' ? true : false;
|
...
|
...
|
@@ -171,14 +139,13 @@ class HelperSearch |
|
|
//再到着
|
|
|
//年终大促
|
|
|
// 年中大促
|
|
|
|
|
|
foreach($val['goods_list'] as $k => $v){
|
|
|
$goods_list[$k]['url'] = Helpers::getUrlBySkc($val['product_id'], $v['goods_id'], $val['cn_alphabet']);
|
|
|
}
|
|
|
if (!empty($val['default_images'])) {
|
|
|
$val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]);
|
|
|
}
|
|
|
$result[] = array(
|
|
|
$goods[] = array(
|
|
|
'tags' => array(
|
|
|
'isNew' => $isNew,
|
|
|
'isLimit' => $isLimit
|
...
|
...
|
@@ -192,7 +159,7 @@ class HelperSearch |
|
|
'skn' => $val['product_skn']
|
|
|
);
|
|
|
}
|
|
|
return $result;
|
|
|
return $goods;
|
|
|
}
|
|
|
/**
|
|
|
* 版型等其它筛选项
|
...
|
...
|
@@ -284,6 +251,7 @@ class HelperSearch |
|
|
* @return array
|
|
|
*/
|
|
|
public static function groupSort($sort, $option = array()) {
|
|
|
self::setListNav();
|
|
|
$params = self::$params;
|
|
|
$gender = isset($params['gender']) ? $params['gender'] : '';
|
|
|
|
...
|
...
|
@@ -385,16 +353,18 @@ class HelperSearch |
|
|
/**
|
|
|
* 品牌,可以多选
|
|
|
* @param array $brand
|
|
|
* @param array $options
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function brand($filter) {
|
|
|
public static function brand($filter, $options = array()) {
|
|
|
if (isset($options['brandName'])) {
|
|
|
return array();
|
|
|
}
|
|
|
$params = self::$params;
|
|
|
$brand_ids = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
|
|
|
|
|
|
if (isset($params['brand'])) {
|
|
|
unset($params['brand']);
|
|
|
}
|
|
|
|
|
|
$result = array(
|
|
|
'default' => array() ,
|
|
|
'brandIndex' => array(
|
...
|
...
|
@@ -412,14 +382,11 @@ class HelperSearch |
|
|
'U~Z' => array() ,
|
|
|
)
|
|
|
);
|
|
|
|
|
|
$brand_keys = array_reverse(array_keys($result['list']));
|
|
|
if (isset($filter['brand']) && !empty($filter['brand'])) {
|
|
|
|
|
|
//有商品结果时
|
|
|
$brand = $filter['brand'];
|
|
|
foreach ($brand as $v) {
|
|
|
|
|
|
if (!isset($v['brand_alif']) && isset($v['brand_name_en'])) {
|
|
|
$v['brand_alif'] = substr($v['brand_name_en'], 0, 1);
|
|
|
}
|
...
|
...
|
@@ -429,7 +396,6 @@ class HelperSearch |
|
|
if (!isset($v['brand_domain'])) {
|
|
|
$v['brand_domain'] = '';
|
|
|
}
|
|
|
|
|
|
//选中的筛选条件
|
|
|
if (in_array($v['id'], $brand_ids)) {
|
|
|
$selected_brand = explode(',', self::$params['brand']);
|
...
|
...
|
@@ -442,9 +408,7 @@ class HelperSearch |
|
|
'href' => self::buildurl($selected_params)
|
|
|
);
|
|
|
}
|
|
|
|
|
|
$selected_brand = isset(self::$params['brand']) && !empty(self::$params['brand']) ? explode(',', self::$params['brand']) : array();
|
|
|
|
|
|
if (empty($selected_brand)) {
|
|
|
$url = self::buildurl(array_merge($params, array(
|
|
|
'brand' => $v['id']
|
...
|
...
|
@@ -463,7 +427,6 @@ class HelperSearch |
|
|
'brand' => implode(',', $selected_brand)
|
|
|
)));
|
|
|
}
|
|
|
|
|
|
$this_brand = array(
|
|
|
'brand_id' => $v['id'],
|
|
|
'name' => $v['brand_name'],
|
...
|
...
|
@@ -471,7 +434,6 @@ class HelperSearch |
|
|
'href' => $url,
|
|
|
'active' => in_array($v['id'], $brand_ids) ? true : false
|
|
|
);
|
|
|
|
|
|
if (count($result['default']) < 10) {
|
|
|
$result['default'][] = $this_brand;
|
|
|
}
|
...
|
...
|
@@ -493,11 +455,9 @@ class HelperSearch |
|
|
}
|
|
|
}
|
|
|
else if (isset($filter['paramNames']) && isset($filter['paramNames']['brand'])) {
|
|
|
|
|
|
//无商品结果时且选择了品牌
|
|
|
$brand = $filter['paramNames']['brand'];
|
|
|
foreach ($brand as $v) {
|
|
|
|
|
|
//选中的筛选条件
|
|
|
if (in_array($v['id'], $brand_ids)) {
|
|
|
$selected_brand = explode(',', self::$params['brand']);
|
...
|
...
|
@@ -764,7 +724,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 高级选项
|
|
|
*/
|
|
|
public static function seniorChose($filter){
|
|
|
public static function seniorChose($filter)
|
|
|
{
|
|
|
$style = self::style($filter);
|
|
|
$other = self::standard($filter);
|
|
|
$result = array_merge($style,$other);
|
...
|
...
|
@@ -774,9 +735,9 @@ class HelperSearch |
|
|
/**
|
|
|
* 每页显示数量
|
|
|
*/
|
|
|
public static function viewNum() {
|
|
|
public static function viewNum()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
|
|
|
$view_num = array(
|
|
|
60,
|
|
|
100,
|
...
|
...
|
@@ -797,8 +758,9 @@ class HelperSearch |
|
|
/**
|
|
|
* 显示行数
|
|
|
*/
|
|
|
public static function rowNum($num = 5) {
|
|
|
$params = self::$params;
|
|
|
public static function rowNum($num = 5)
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
|
|
|
$params['rowNum'] = $num;
|
|
|
|
...
|
...
|
@@ -808,7 +770,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 是否特价
|
|
|
*/
|
|
|
public static function specialoffer() {
|
|
|
public static function specialoffer()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
if (isset($params['specialoffer']) && !empty($params['specialoffer'])) {
|
|
|
unset($params['specialoffer']);
|
...
|
...
|
@@ -829,7 +792,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 是否限量
|
|
|
*/
|
|
|
public static function limited() {
|
|
|
public static function limited()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
if (isset($params['limited']) && !empty($params['limited'])) {
|
|
|
unset($params['limited']);
|
...
|
...
|
@@ -849,7 +813,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 是否新品
|
|
|
*/
|
|
|
public static function isnew() {
|
|
|
public static function isnew()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
|
|
|
if (isset($params['isNew']) && !empty($params['isNew'])) {
|
...
|
...
|
@@ -870,7 +835,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 排序是否最新
|
|
|
*/
|
|
|
public static function orderTime() {
|
|
|
public static function orderTime()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
if (isset($params['order'])) {
|
|
|
unset($params['order']);
|
...
|
...
|
@@ -888,7 +854,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 排序是否默认
|
|
|
*/
|
|
|
public static function orderDefault() {
|
|
|
public static function orderDefault()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
if (isset($params['order'])) {
|
|
|
unset($params['order']);
|
...
|
...
|
@@ -904,7 +871,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 价格排序
|
|
|
*/
|
|
|
public static function orderPrice() {
|
|
|
public static function orderPrice()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
if (isset($params['order'])) {
|
|
|
unset($params['order']);
|
...
|
...
|
@@ -946,7 +914,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 折扣排序
|
|
|
*/
|
|
|
public static function orderDiscount() {
|
|
|
public static function orderDiscount()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
if (isset($params['order'])) {
|
|
|
unset($params['order']);
|
...
|
...
|
@@ -988,7 +957,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 获取自定义价格要提交的地址
|
|
|
*/
|
|
|
public static function priceSubmit() {
|
|
|
public static function priceSubmit()
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
$price = array();
|
|
|
if (isset($params['price'])) {
|
...
|
...
|
@@ -1030,7 +1000,8 @@ class HelperSearch |
|
|
* @param array $params
|
|
|
* @return string
|
|
|
*/
|
|
|
private static function buildurl($params) {
|
|
|
private static function buildurl($params)
|
|
|
{
|
|
|
if (empty($params)) {
|
|
|
return self::current();
|
|
|
}
|
...
|
...
|
@@ -1054,7 +1025,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 获取选中的条件
|
|
|
*/
|
|
|
public static function getSelected() {
|
|
|
public static function getSelected()
|
|
|
{
|
|
|
$result = array();
|
|
|
$is_array_key = array(
|
|
|
'brand',
|
...
|
...
|
@@ -1078,7 +1050,8 @@ class HelperSearch |
|
|
* @param array $list
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getDiscount(array $list = array()) {
|
|
|
public static function getDiscount(array $list = array())
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
|
|
|
if (empty($list)) {
|
...
|
...
|
@@ -1105,7 +1078,7 @@ class HelperSearch |
|
|
}
|
|
|
$result = array(
|
|
|
//'updateNum' => $total,
|
|
|
'list' => $list
|
|
|
'list' => array_values($list)
|
|
|
);
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
@@ -1113,7 +1086,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 最新上架
|
|
|
*/
|
|
|
public static function recentShelve($list = array()){
|
|
|
public static function recentShelve($list = array())
|
|
|
{
|
|
|
if (empty($list)) {
|
|
|
return array();
|
|
|
}
|
...
|
...
|
@@ -1153,11 +1127,7 @@ class HelperSearch |
|
|
*/
|
|
|
public static function current(){
|
|
|
$url = explode('?', $_SERVER['REQUEST_URI']);
|
|
|
self::$current_url = $url[0];
|
|
|
self::$listnav[0] = array(
|
|
|
'href' => '$url[0]',
|
|
|
'name' => '首页'
|
|
|
);
|
|
|
self::$listnav[0]['href'] = $url[0];
|
|
|
return $url[0];
|
|
|
}
|
|
|
/**
|
...
|
...
|
@@ -1175,7 +1145,7 @@ class HelperSearch |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 组织产品
|
|
|
* 组织产品的图片
|
|
|
* @param $product
|
|
|
* @param $options
|
|
|
* @return array
|
...
|
...
|
@@ -1192,4 +1162,9 @@ class HelperSearch |
|
|
}
|
|
|
return $result;
|
|
|
}
|
|
|
//分页
|
|
|
public static function pager($total,$view_num){
|
|
|
$Paging = new Paging('Yoho');
|
|
|
return $Paging->setTotal($total)->setSize($view_num)->view(0);
|
|
|
}
|
|
|
} |
...
|
...
|
|