...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
namespace Plugin;
|
|
|
use Plugin\Paging;
|
|
|
use LibModels\Web\Product\BrandData;
|
|
|
use Api\Yohobuy;
|
|
|
/**
|
|
|
* 搜索辅助类
|
|
|
*/
|
...
|
...
|
@@ -62,13 +63,13 @@ class HelperSearch |
|
|
unset(self::$params['page']);
|
|
|
unset(self::$params['/sale']);
|
|
|
unset(self::$params['sale']);
|
|
|
$filter = $data['data']['filter'];
|
|
|
$filter = $data['product']['filter'];
|
|
|
//产品列表
|
|
|
$result['goods'] = self::getProductList($data['data']['product_list'], $options['imgSize']);
|
|
|
$result['goods'] = self::getProductList($data['product']['product_list'], $options['imgSize']);
|
|
|
//总页数
|
|
|
$result['page_total'] = $data['data']['page_total'];
|
|
|
$result['page_total'] = $data['product']['page_total'];
|
|
|
//当前页
|
|
|
$result['page'] = $data['data']['page'];
|
|
|
$result['page'] = $data['product']['page'];
|
|
|
self::$page = $result['page'];
|
|
|
//清除选中
|
|
|
$result['filters']['checkedConditions']['clearUrl'] = self::current();
|
...
|
...
|
@@ -98,25 +99,33 @@ class HelperSearch |
|
|
//可选每页显示数量
|
|
|
$result['opts']['pageCounts'] = self::viewNum();
|
|
|
$result['opts']['curPage'] = self::$page;
|
|
|
$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['opts']['pageCount'] = $data['product']['page_total'];
|
|
|
$result['opts']['nextHref'] = ($next = self::next($data['product']['page_total'],$data['product']['filter'])) ? $next['href'] : '';
|
|
|
$result['hasNextPage'] = self::next($data['product']['page_total']);
|
|
|
//分类条件
|
|
|
$result['filters']['sort'] = isset($filter['group_sort']) ? self::searchSort($filter['group_sort']) : array();
|
|
|
$result['filters']['sort'] = isset($data['sort']) ? self::searchSort($data['sort']['sort']) : array();
|
|
|
//左侧分类分类
|
|
|
$result['leftContent'][]['allSort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort']) : array();
|
|
|
$result['leftContent'][]['allSort'] = isset($data['sort']) ? self::groupSort($data['sort']['sort']) : array();
|
|
|
//一周新品上架
|
|
|
$result['leftContent'][]['newSales'] = isset($filter['recent']) ? self::recentShelve($filter['recent']) : array();
|
|
|
$result['leftContent'][]['newSales'] = isset($data['recent']) ? self::recentShelve($data['recent']['recent']) : array();
|
|
|
//全部折扣
|
|
|
$result['leftContent'][]['allDiscount'] = isset($filter['discount']) ? self::getDiscount($filter['discount']) : array();
|
|
|
$result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array();
|
|
|
//总记录数
|
|
|
$result['totalCount'] = $data['data']['total'];
|
|
|
$result['totalCount'] = $data['product']['total'];
|
|
|
//品牌店铺信息
|
|
|
$result['shopEntry'] = isset($data['shop']) && !empty($data['shop']) ? self::shop($data['shop'], $data['sort']['sort']) : array();
|
|
|
//分页
|
|
|
$result['pager'] = self::pager($result['totalCount'],$options['viewNum']);
|
|
|
//选中条件
|
|
|
$result['filters']['checkedConditions']['conditions'] = self::getSelected();
|
|
|
if (self::getSelected()) {
|
|
|
$result['filters']['checkedConditions']['conditions'] = self::getSelected();
|
|
|
}
|
|
|
//没有选中
|
|
|
else{
|
|
|
$result['filters']['checkedConditions'] = array();
|
|
|
}
|
|
|
if (isset($options['controller']) && $options['controller'] == 'Search') {
|
|
|
self::setSearchNav($data['data']['total']);
|
|
|
self::setSearchNav($data['product']['total']);
|
|
|
}
|
|
|
$result['pathNav'] = self::$listnav;
|
|
|
return $result;
|
...
|
...
|
@@ -128,7 +137,8 @@ class HelperSearch |
|
|
* @author sefon 2015-12-21 17:24:04
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function getProductList($product,$imgSize){
|
|
|
public static function getProductList($product,$imgSize)
|
|
|
{
|
|
|
$goods = array();
|
|
|
foreach($product as $key => $val){
|
|
|
//NEW
|
...
|
...
|
@@ -171,7 +181,8 @@ class HelperSearch |
|
|
* @param $filter
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function standard($filter) {
|
|
|
public static function standard($filter)
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
$result = array();
|
|
|
foreach ($filter as $key => $val) {
|
...
|
...
|
@@ -199,7 +210,7 @@ class HelperSearch |
|
|
'href' => self::buildUrl(array_merge($params, array(
|
|
|
'parameter_' . $val['standard_id'] => $pval['standard_id']
|
|
|
))) ,
|
|
|
'selected' => isset(self::$params['parameter_' . $val['standard_id']]) && self::$params['parameter_' . $val['standard_id']] == $pval['standard_id'] ? true : false
|
|
|
'checked' => isset(self::$params['parameter_' . $val['standard_id']]) && self::$params['parameter_' . $val['standard_id']] == $pval['standard_id'] ? true : false
|
|
|
);
|
|
|
}
|
|
|
if (!empty($sub) && count($sub) > 1) {
|
...
|
...
|
@@ -216,7 +227,8 @@ class HelperSearch |
|
|
* 性别
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function gender($filter) {
|
|
|
public static function gender($filter)
|
|
|
{
|
|
|
if (empty($filter) || !isset($filter['gender']) || empty($filter['gender'])) {
|
|
|
return array();
|
|
|
}
|
...
|
...
|
@@ -241,8 +253,9 @@ class HelperSearch |
|
|
$result[] = array(
|
|
|
'name' => $val,
|
|
|
'href' => self::buildUrl(array_merge($params, array(
|
|
|
'gender' => $key
|
|
|
'gender' => $key,
|
|
|
))) ,
|
|
|
'checked' => isset(self::$params['gender']) && self::$params['gender'] == $key ? true : false
|
|
|
);
|
|
|
}
|
|
|
return $result;
|
...
|
...
|
@@ -342,7 +355,8 @@ class HelperSearch |
|
|
* @param array $filter
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function brand($filter) {
|
|
|
public static function brand($filter)
|
|
|
{
|
|
|
$options = self::$options;
|
|
|
//品牌列表返回空
|
|
|
if (isset($options['brandName'])) {
|
...
|
...
|
@@ -388,8 +402,8 @@ class HelperSearch |
|
|
'id' => $v['id'],
|
|
|
'href' => $url,
|
|
|
'name' => $v['brand_name'],
|
|
|
'key' => $v['brand_name'],
|
|
|
'active' => in_array($v['id'], $brandIds) ? true : false
|
|
|
'key' => strtolower($v['brand_name']),
|
|
|
'checked' => in_array($v['id'], $brandIds) ? true : false
|
|
|
);
|
|
|
if (is_numeric($v['brand_alif'])) {
|
|
|
$this_brand['index'] = '0-9';
|
...
|
...
|
@@ -421,7 +435,7 @@ class HelperSearch |
|
|
//品牌列表排序, 添加品牌索引
|
|
|
$index_key = array();
|
|
|
foreach ($brandList as $key => $val) {
|
|
|
if ($key && !in_array($key, $index_key)) {
|
|
|
if ($key && !in_array($key, $index_key) && !is_numeric($key)) {
|
|
|
$index['index'] = strtolower(($key));
|
|
|
$index['name'] = $key;
|
|
|
$result['brandIndex'][] = $index;
|
...
|
...
|
@@ -446,7 +460,8 @@ class HelperSearch |
|
|
* @param array $filter
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function size($filter) {
|
|
|
public static function size($filter)
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
$sizeId = isset($params['size']) && !empty($params['size']) ? $params['size'] : '';
|
|
|
if (isset($params['size'])) {
|
...
|
...
|
@@ -483,7 +498,8 @@ class HelperSearch |
|
|
* @param array $filter
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function color($filter) {
|
|
|
public static function color($filter)
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
$colorId = isset($params['color']) && !empty(self::$params['color']) ? self::$params['color'] : '';
|
|
|
if (isset($params['color'])) {
|
...
|
...
|
@@ -519,7 +535,8 @@ class HelperSearch |
|
|
* @param array $filter
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function price($filter) {
|
|
|
public static function price($filter)
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
$priceId = isset($params['price']) && !empty(self::$params['price']) ? self::$params['price'] : '';
|
|
|
if (isset($params['price'])) {
|
...
|
...
|
@@ -561,7 +578,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 获取自定义价格要提交的地址
|
|
|
*/
|
|
|
public static function customPrice($filter) {
|
|
|
public static function customPrice($filter)
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
$result = array(
|
|
|
'min' => '',
|
...
|
...
|
@@ -584,7 +602,8 @@ class HelperSearch |
|
|
* @param array $filter
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function style($filter) {
|
|
|
public static function style($filter)
|
|
|
{
|
|
|
$params = self::$params;
|
|
|
$styleIds = isset($params['style']) && !empty($params['style']) ? explode(',', $params['style']) : array();
|
|
|
if (isset($params['style'])) {
|
...
|
...
|
@@ -975,7 +994,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 当前页地址
|
|
|
*/
|
|
|
public static function current(){
|
|
|
public static function current()
|
|
|
{
|
|
|
$url = explode('?', $_SERVER['REQUEST_URI']);
|
|
|
self::$listnav[0]['href'] = $url[0];
|
|
|
return $url[0];
|
...
|
...
|
@@ -983,7 +1003,8 @@ class HelperSearch |
|
|
/**
|
|
|
* 下一页
|
|
|
*/
|
|
|
public static function next($total){
|
|
|
public static function next($total)
|
|
|
{
|
|
|
$param = self::$params;
|
|
|
$page = self::$page;
|
|
|
$next = array();
|
...
|
...
|
@@ -1024,13 +1045,14 @@ class HelperSearch |
|
|
* @param $viewNum
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public static function pager($total,$viewNum){
|
|
|
public static function pager($total, $viewNum){
|
|
|
$Paging = new Paging('Yoho');
|
|
|
return $Paging->setTotal($total)->setSize($viewNum)->view(0);
|
|
|
}
|
|
|
|
|
|
//组织静态资源数据格式
|
|
|
public static function formatNodeContent($code){
|
|
|
public static function formatNodeContent($code)
|
|
|
{
|
|
|
$nodeContent = BrandData::getByNodeContent($code);
|
|
|
if (isset($nodeContent['code']) && $nodeContent['code'] === 200) {
|
|
|
$result = array();
|
...
|
...
|
@@ -1052,13 +1074,16 @@ class HelperSearch |
|
|
|
|
|
/**
|
|
|
* 组织品牌店铺信息
|
|
|
* @param $shop
|
|
|
* @param $shopSort
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function shop($shop)
|
|
|
public static function shop($shop, $shopSort)
|
|
|
{
|
|
|
$url = Helpers::url('','',$shop['brand_domain']);
|
|
|
$shopEntry = array();
|
|
|
$sort = array();
|
|
|
foreach ($shop['sort'] as $msort) {
|
|
|
foreach ($shopSort as $msort) {
|
|
|
if (!isset($msort['sub']) || empty($msort['sub'])) {
|
|
|
continue;
|
|
|
}
|
...
|
...
|
@@ -1112,4 +1137,159 @@ class HelperSearch |
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 并行调接口url获取(搜索产品数据)
|
|
|
* @param
|
|
|
*/
|
|
|
public static function getProductUrl($condition)
|
|
|
{
|
|
|
// 排序数据映射表
|
|
|
$orderMaps = array(
|
|
|
's_t_desc' => 'shelve_time:desc',
|
|
|
's_t_asc' => 'shelve_time:asc',
|
|
|
's_p_asc' => 'sales_price:asc',
|
|
|
's_p_desc' => 'sales_price:desc',
|
|
|
'p_d_desc' => 'discount:desc',
|
|
|
'p_d_asc' => 'discount:asc',
|
|
|
'skn_desc' => 'product_skn:desc',
|
|
|
'skn_asc' => 'product_skn:asc',
|
|
|
'activities_desc' => 'activities.order_by:desc',
|
|
|
'activities_asc' => 'activities.order_by:asc',
|
|
|
's_n_asc' => 'sales_num:asc',
|
|
|
's_n_desc' => 'sales_num:desc',
|
|
|
'activities_id_desc' => 'activities.activity_id:desc',
|
|
|
'activities_id_asc' => 'activities.activity_id:asc',
|
|
|
);
|
|
|
|
|
|
$param = array();
|
|
|
$param['status'] = 1; // 是否上架,1表示在架,2表示不在
|
|
|
$param['sales'] = 'Y'; // 只搜索销售的产品
|
|
|
$param['stocknumber'] = 1; // 过滤掉已售罄的商品
|
|
|
// $param['needFilter'] = 1; // 是否需要返回筛选条件
|
|
|
if (!isset($condition['order'])) {
|
|
|
$param['order'] = $orderMaps['s_t_desc'];
|
|
|
} else {
|
|
|
$param['order'] = $orderMaps[$condition['order']];
|
|
|
}
|
|
|
if (!isset($condition['page'])) {
|
|
|
$param['page'] = 1;
|
|
|
}
|
|
|
|
|
|
if(isset($condition['viewNum'])) {
|
|
|
$param['viewNum'] = $condition['viewNum'];
|
|
|
} else if (!isset($condition['limit'])) {
|
|
|
$param['viewNum'] = 60;
|
|
|
} else {
|
|
|
$param['viewNum'] = $condition['limit'];
|
|
|
unset($condition['limit']);
|
|
|
}
|
|
|
if (!empty($condition)) {
|
|
|
$param += $condition;
|
|
|
}
|
|
|
|
|
|
return Yohobuy::httpBuildQuery(self::getUrl(), $param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 并行调接口url获取(产品分类)
|
|
|
* @param
|
|
|
*/
|
|
|
|
|
|
public static function getClassesUrl($condition)
|
|
|
{
|
|
|
|
|
|
$condition['sales'] = 'Y'; //在销售商品分类
|
|
|
$condition['status'] = 1; //上架商品分类
|
|
|
$condition['stocknumber'] = 1; //过滤掉已售罄
|
|
|
|
|
|
return Yohobuy::httpBuildQuery(self::getUrl('sort'), $condition);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 并行调接口url获取(获取折扣区间)
|
|
|
* @param
|
|
|
*/
|
|
|
|
|
|
public static function getDiscountUrl($param = array())
|
|
|
{
|
|
|
return Yohobuy::httpBuildQuery(self::getUrl('discount'), $param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 并行调接口url获取(获取最新上架)
|
|
|
*/
|
|
|
public static function getRecentShelveUrl($param = array())
|
|
|
{
|
|
|
return Yohobuy::httpBuildQuery(self::getUrl('recent'), $param);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 并行调接口url获取(获取用户浏览记录)
|
|
|
*/
|
|
|
// public static function getReviewUrl($param = array())
|
|
|
// {
|
|
|
// return Yohobuy::httpBuildQuery(self::getUrl('review'), $param);
|
|
|
// }
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取品牌店铺接口地址
|
|
|
* @param $param
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function getShopUrl($param)
|
|
|
{
|
|
|
return Yohobuy::httpBuildQuery(self::getUrl('shop'), $param);
|
|
|
}
|
|
|
/**
|
|
|
* 获取搜索的服务地址
|
|
|
*
|
|
|
* 备注:此处是根据环境来确定使用阿里云内网还是外网的URL
|
|
|
*
|
|
|
* @return string
|
|
|
*/
|
|
|
private static function getUrl($type = 'search')
|
|
|
{
|
|
|
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
|
|
|
switch (APPLICATION_ENV) {
|
|
|
case 'release':
|
|
|
if ($type == 'sort') {
|
|
|
return 'http://100.98.132.63/yohosearch/sortgroup.json';
|
|
|
}
|
|
|
elseif ($type == 'discount') {
|
|
|
return 'http://100.98.132.63/yohosearch/discount.json';
|
|
|
}
|
|
|
elseif ($type == 'recent') {
|
|
|
return 'http://100.98.132.63/yohosearch/recent.json';
|
|
|
}
|
|
|
// elseif ($type == 'review') {
|
|
|
//
|
|
|
// }
|
|
|
elseif ($type == 'shop') {
|
|
|
return 'http://100.98.132.63/yohosearch/shops.json';
|
|
|
}
|
|
|
return 'http://100.98.132.63/yohosearch/search.json';
|
|
|
case 'test':
|
|
|
case 'preview':
|
|
|
case 'developer':
|
|
|
default:
|
|
|
if ($type == 'sort') {
|
|
|
return 'http://101.200.31.165/yohosearch/sortgroup.json';
|
|
|
}
|
|
|
elseif ($type == 'discount') {
|
|
|
return 'http://101.200.31.165/yohosearch/discount.json';
|
|
|
}
|
|
|
elseif ($type == 'recent') {
|
|
|
return 'http://101.200.31.165/yohosearch/recent.json';
|
|
|
}
|
|
|
// elseif ($type == 'review') {
|
|
|
//
|
|
|
// }
|
|
|
elseif ($type == 'shop') {
|
|
|
return 'http://101.200.31.165/yohosearch/shops.json';
|
|
|
}
|
|
|
return 'http://101.200.31.165/yohosearch/search.json';
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|