Authored by 周少峰

healpersearch 修改

... ... @@ -63,5 +63,6 @@ class CacheConfig
const KEY_WEB_HOME_NAVBAR_DATA = 'key_web_home_navbar_data';//web的导航数据
const KEY_WEB_HOME_CHANNEL_DATA = 'key_web_home_channel_data';//web首页频道数据[boys, girls, kids, lifestyle]
const KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA = 'key_web_home_newarrival_data';//web频道最新上架数据[boys, girls, kids, lifestyle]
const KEY_WEB_PRODUCT_SEARCH_DATA = 'key_web_product_search_data'; // web搜索的数据
}
... ...
... ... @@ -73,11 +73,17 @@ class HelperSearch
//排序方式、显示数量等其他选项
$result['opts'] = isset($data['product']['filter']) ? self::getOpts() : array();
//下一页
if (isset($data['product']['page_total'])) {
$result['hasNextPage'] = self::next($data['product']['page_total']);
}
//全部折扣
$result['leftContent'][]['allDiscount'] = isset($data['discount']) ? self::getDiscount($data['discount']['discount']) : array();
//分类条件
$result['filters']['sort'] = isset($data['sort']) ? self::searchSort($data['sort']['sort']) : array();
if ($data['discount']['discount'] && !empty($data['discount']['discount'])) {
$result['leftContent'][]['allDiscount'] = self::getDiscount($data['discount']['discount']);
}
//分类条件(搜索页面)
if (isset($data['sort']) && isset($options['controller']) && $options['controller'] != 'Search') {
$result['filters']['sort'] = self::searchSort($data['sort']['sort']);
}
//左侧分类分类
$result['leftContent'][]['allSort'] = isset($data['sort']) ? self::groupSort($data['sort']['sort']) : array();
//一周新品上架
... ... @@ -309,9 +315,6 @@ class HelperSearch
{
$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'];
... ... @@ -959,9 +962,6 @@ class HelperSearch
public static function getDiscount(array $list = array())
{
$params = self::$params;
if (empty($list)) {
return array();
}
$query = array();
$total = 0;
foreach ($list as $k => $v) {
... ...
... ... @@ -5,6 +5,7 @@ use Api\Yohobuy;
use Plugin\Helpers;
use Plugin\HelperSearch;
use \LibModels\Web\Product\SearchData;
use Configs\CacheConfig;
/**
* sale首页模板数据模型
... ... @@ -165,19 +166,41 @@ class SearchModel
{
$urlList = array();
$searchCondition = self::searchCondition($customCondition, $customOptions);
if (USE_CACHE) {
$key = CacheConfig::KEY_WEB_PRODUCT_SEARCH_DATA;
if (!empty($condition)) {
$key .= http_build_query($searchCondition['condition'], null, '&');
}
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
// 组合搜索商品url
$urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['condition']);
$urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['sortCondition']);
// 组合搜索店铺url
if (isset($searchCondition['condition']['query'])) {
$param['keyword'] = $searchCondition['condition']['query'];
$urlList['shop'] = HelperSearch::getShopUrl($param);
}
$result = Yohobuy::getMulti($urlList, array(), true);
$data = Yohobuy::getMulti($urlList, array(), true);
// 组织模板数据
$data = HelperSearch::getList($result, $searchCondition['options']);
return $data;
$result = HelperSearch::getList($data, $searchCondition['options']);
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result, 1800); // 缓存30分钟
}
}
return $result;
}
/**
* 根据product_sn查询产品图片信息
... ...