...
|
...
|
@@ -15,11 +15,7 @@ const shopHandler = require('./shop-handler'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
const crypto = global.yoho.crypto;
|
|
|
const _ = require('lodash');
|
|
|
const Fn = require('lodash/fp');
|
|
|
const md5 = require('md5');
|
|
|
const cache = global.yoho.cache;
|
|
|
const config = global.yoho.config;
|
|
|
const logger = global.yoho.logger;
|
|
|
const redis = global.yoho.redis;
|
|
|
|
|
|
// const limitNum = 60; // 商品每页显示数目
|
...
|
...
|
@@ -36,15 +32,6 @@ const positionId = 10; |
|
|
// 获取分类左侧广告id
|
|
|
const sortAdsId = 79;
|
|
|
|
|
|
const CACHE_TIME_S = 60;
|
|
|
|
|
|
function _getCacheKey(params, page) {
|
|
|
let sortByKey = Fn.pipe(Fn.toPairs, Fn.sortBy(0), Fn.flatten);
|
|
|
let genKey = Fn.pipe(Fn.cloneDeep, sortByKey, Fn.join('_'));
|
|
|
|
|
|
return `render_cache_${page}_${md5(genKey(params))}`;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品分类列表数据
|
|
|
*/
|
...
|
...
|
@@ -198,6 +185,8 @@ function getListNewData(params, channel) { |
|
|
};
|
|
|
let dps = {};
|
|
|
|
|
|
const baseUrl = `/${_.toLower(channel)}-new`; // 查询参数静态化base uri
|
|
|
|
|
|
_.forEach(needParams, (value) => {
|
|
|
if (params[value]) {
|
|
|
dps[value] = params[value];
|
...
|
...
|
@@ -206,15 +195,13 @@ function getListNewData(params, channel) { |
|
|
|
|
|
// 获取左侧类目数据
|
|
|
if (result[1].code === 200) {
|
|
|
finalResult.list = Object.assign(
|
|
|
searchHandler.handlePathNavData(result[1].data, params, 'new', channel), {
|
|
|
leftContent: searchHandler.handleSortData(result[1].data, dps, params)
|
|
|
});
|
|
|
finalResult.list = listHandler.handlePathNavData(result[1].data, params, 'new', channel, baseUrl);
|
|
|
finalResult.list.leftContent = listHandler.handleSortData(result[1].data, dps, params, baseUrl);
|
|
|
}
|
|
|
|
|
|
// 获取商品数据和顶部筛选条件
|
|
|
if (result[2].code === 200) {
|
|
|
let filters = Object.assign(searchHandler.handleFilterDataAll(result[2].data, params),
|
|
|
let filters = Object.assign(listHandler.handleFilterData(result[2].data, params, baseUrl),
|
|
|
finalResult.list.leftContent.sort);
|
|
|
|
|
|
filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
|
...
|
...
|
@@ -222,15 +209,15 @@ function getListNewData(params, channel) { |
|
|
|
|
|
Object.assign(finalResult.list, {
|
|
|
filters: filters,
|
|
|
opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
|
|
|
opts: listHandler.handleOptsData(params, result[2].data.total, result[2].data.filter, baseUrl),
|
|
|
totalCount: result[2].data.total,
|
|
|
footPager: searchHandler.handlePagerData(result[2].data.total, params),
|
|
|
footPager: listHandler.handlePagerData(result[2].data.total, params, false, baseUrl),
|
|
|
goods: productProcess.processProductList(result[2].data.product_list,
|
|
|
Object.assign({
|
|
|
showDiscount: false, showNew: false,
|
|
|
from: {type: 'listNew', params: params}
|
|
|
}, params)),
|
|
|
hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
|
|
|
hasNextPage: listHandler.handleNextPage(params, result[2].data.total, baseUrl),
|
|
|
|
|
|
// 最近浏览记录
|
|
|
latestWalk: 7
|
...
|
...
|
@@ -239,7 +226,7 @@ function getListNewData(params, channel) { |
|
|
|
|
|
// 新品上架
|
|
|
if (result[3] && result[3].code === 200) {
|
|
|
Object.assign(finalResult.list.leftContent, searchHandler.handleWeekNew(result[3].data, dps));
|
|
|
Object.assign(finalResult.list.leftContent, listHandler.handleWeekNew(result[3].data, dps, baseUrl));
|
|
|
}
|
|
|
|
|
|
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.list, 'goods'))};
|
...
|
...
|
@@ -251,49 +238,6 @@ function getListNewData(params, channel) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
function getListNewDataPre(params, channel) {
|
|
|
let cKey = _getCacheKey(Object.assign({channel: channel}, params), 'listnew');
|
|
|
let getOriginData = () => {
|
|
|
return this.getListNewData(params, channel).then(result => {
|
|
|
|
|
|
// 查询结果为空则不cache
|
|
|
if (config.useCache && !_.isEmpty(_.get(result, 'list.goods', []))) {
|
|
|
cache.set(cKey, result, CACHE_TIME_S)
|
|
|
.catch(err => logger.debug(`list_new render cache data save fail:${err.toString()}`));
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
if (config.useCache) {
|
|
|
return cache.get(cKey).catch(err => {
|
|
|
logger.debug(`get list_new render cache data fail:${err.toString()}`);
|
|
|
|
|
|
return getOriginData();
|
|
|
}).then(cdata => {
|
|
|
let hasCache = false;
|
|
|
|
|
|
if (cdata) {
|
|
|
try {
|
|
|
cdata = JSON.parse(cdata);
|
|
|
hasCache = true;
|
|
|
} catch (e) {
|
|
|
logger.debug('list_new render cache data parse fail.');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (hasCache) {
|
|
|
return cdata;
|
|
|
} else {
|
|
|
return getOriginData();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return getOriginData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据品牌域名查询品牌信息
|
|
|
*/
|
...
|
...
|
@@ -668,7 +612,6 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
|
|
|
this.getListData = getListData.bind(this);
|
|
|
this.getListNewData = getListNewData.bind(this);
|
|
|
this.getListNewDataPre = getListNewDataPre.bind(this);
|
|
|
this.getBrandInfo = getBrandInfo.bind(this);
|
|
|
this.getBrandData = getBrandData.bind(this);
|
|
|
this.getBrandAbout = getBrandAbout.bind(this);
|
...
|
...
|
|