Authored by 周少峰

产品from参数,搜索的品牌分类不变,开启缓存

... ... @@ -292,12 +292,12 @@ class ChannelConfig
//from统计模块标识
public static $itemFromStats = array(
'search' => array('domain' =>'search','module'=>'s'),//搜索页search.yohobuy.com
'search_index' => array('domain' =>'search','module'=>'s'),//搜索页search.yohobuy.com
'list_sale' => array('domain' =>'list','module'=>'s'),//list.yohobuy.com/sale
'list' => array('domain' =>'list','module'=>'c'),//list.yohobuy.com
'list_index' => array('domain' =>'list','module'=>'c'),//list.yohobuy.com
'list_new' => array('domain' =>'list','module'=>'n'),//list.yohobuy.com/new
'brand' => array('domain' =>'brand','module'=>'b'),//xxx.yohobuy.com[品牌域名]
'sale' => array('domain' =>'sale','module' => 's'),//sale.yohobuy.com
'index_brand' => array('domain' =>'brand','module'=>'b'),//xxx.yohobuy.com[品牌域名]
'sale_index' => array('domain' =>'sale','module' => 's'),//sale.yohobuy.com
);
}
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@ use LibModels\Web\Product\BrandData;
use LibModels\Web\Product\SearchData;
use Api\Yohobuy;
use Api\Sign;
use Configs\ChannelConfig;
/**
* 搜索辅助类
*/
... ... @@ -105,8 +106,8 @@ class HelperSearch
}
}
//品牌店铺信息
if (isset($data['shop']) && !empty($data['shop'])) {
$result['shopEntry'] = self::shop($data['shop'], $data['sort']['sort']);
if (isset($data['shop']) && !empty($data['shop']) && isset($data['shopSort'])) {
$result['shopEntry'] = self::shop($data['shop'], $data['shopSort']);
}
//分页
if (isset($result['totalCount'])) {
... ... @@ -167,7 +168,7 @@ class HelperSearch
'isNew' => $isNew,
'isLimit' => $isLimit
),
'url' => sprintf('%s?channel=%s&from=%s-n_%s', $goods_list[0]['url'], 'product' , 'product', ++$key),
'url' => self::fromPram($goods_list[0]['url'],++$key),
'thumb' => $val['default_images'],
'name' => $val['product_name'],
'salePrice' => $val['sales_price'],
... ... @@ -176,8 +177,6 @@ class HelperSearch
'showColBtn' => true,
'coled' => true
);
print_r($_COOKIE);
print_r($good); exit;
//市场价不等于售价时显示
if ($val['market_price'] != $val['sales_price']) {
$good['marketPrice'] = $val['market_price'];
... ... @@ -1374,12 +1373,24 @@ class HelperSearch
/**
* 商品链接from参数
* @param $url
* @param $position
* @param bool $abEnabled
* @return string
*/
public static function fromPram($url, $abEnabled = false)
public static function fromPram($url, $position, $abEnabled = false)
{
$options = self::$options;
$itemFrom = ChannelConfig::$itemFromStats;
$controller = isset(self::$options['controller']) ? strtolower(self::$options['controller']) : '';
$action = isset(self::$options['action']) ? strtolower(self::$options['action']) : '';
$itemIndex = $controller."_".$action;
//获取domain-module-$keyword_page_position{ab}
$ab = (isset($_COOKIE['ab_5']) && $abEnabled == true) ? '_'.$_COOKIE['ab_5'] : '';
$url .= "?from={$domain}-{$module}-{$module_id}_{$page}_{$position}{$ab}";
$page = self::$page;
$keyword = isset(self::$options['query']) ? self::$options['query'] : '';
if (isset($itemFrom[$itemIndex])) {
$url .= "?from={$itemFrom[$itemIndex]['domain']}-{$itemFrom[$itemIndex]['module']}-{$keyword}_{$page}_{$position}{$ab}";
}
return $url;
}
}
... ...
... ... @@ -167,17 +167,17 @@ 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;
// }
// }
if (USE_CACHE) {
$key = CacheConfig::KEY_WEB_PRODUCT_SEARCH_DATA;
if (!empty($searchCondition['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
... ... @@ -188,19 +188,27 @@ class SearchModel
$urlList['shop'] = HelperSearch::getShopUrl($param);
}
$data = Yohobuy::getMulti($urlList, array(), true);
//获取品牌商品分类
if (isset($data['shop']) && !empty($data['shop'])) {
$shopSortParam['brand'] = $data['shop']['id'];
$shopSort = SearchData::getClassesData($shopSortParam);
if (isset($shopSort['code']) && $shopSort['code'] == 200) {
$data['shopSort'] = $shopSort['data']['sort'];
}
}
// 组织模板数据
$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分钟
// }
// }
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result, 1800); // 缓存30分钟
}
}
return $result;
}
/**
... ...
... ... @@ -53,8 +53,11 @@ class ListController extends WebAction
*/
public function saleAction()
{
$options['controller'] = $this->_request->controller;
$options['action'] = $this->_request->action;
$options['reviewNum'] = 6;
$condition = array();
$list = SearchModel::getListData($condition,array('reviewNum'=>6));
$list = SearchModel::getListData($condition,$options);
$data = array(
//初始化js
'productListPage' => true,
... ...
... ... @@ -7,6 +7,7 @@ class SearchController extends WebAction
{
//当前控制器
$options['controller'] = $this->_request->controller;
$options['action'] = $this->_request->action;
//浏览记录数
$options['reviewNum'] = 7;
$searchData = SearchModel::searchData(array(),$options);
... ...
... ... @@ -5,7 +5,7 @@ define('SITE_MAIN', 'http://web.dev.yohobuy.com'); // 网站主域名
define('OLD_MAIN', 'http://www.yohobuy.com'); // 网站旧域名
define('COOKIE_DOMAIN', '.yohobuy.com'); // COOKIE作用域
define('SUB_DOMAIN', '.yohobuy.com'); // 子域名后缀
define('USE_CACHE', false); // 缓存的开关
define('USE_CACHE', true); // 缓存的开关
define('APPLICATION_PATH', dirname(__DIR__)); // 应用目录
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); // 根目录
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
... ...