...
|
...
|
@@ -14,6 +14,11 @@ 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 limitNum = 60; // 商品每页显示数目
|
|
|
const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime'];
|
...
|
...
|
@@ -29,6 +34,15 @@ 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))}`;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取商品分类列表数据
|
|
|
*/
|
...
|
...
|
@@ -137,6 +151,49 @@ function getListData(params, channel) { |
|
|
});
|
|
|
}
|
|
|
|
|
|
function getListDataPre(params, channel) {
|
|
|
let cKey = _getCacheKey(Object.assign({channel: channel}, params), 'list');
|
|
|
let getOriginData = () => {
|
|
|
return this.getListData(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 render cache data save fail:${err.toString()}`));
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
if (config.useCache) {
|
|
|
return cache.get(cKey).catch(err => {
|
|
|
logger.debug(`get list render cache data fail:${err.toString()}`);
|
|
|
|
|
|
return getOriginData();
|
|
|
}).then(cdata => {
|
|
|
let hasCache = false;
|
|
|
|
|
|
if (cdata) {
|
|
|
try {
|
|
|
hasCache = true;
|
|
|
cdata = JSON.parse(cdata);
|
|
|
} catch (e) {
|
|
|
logger.debug('list render cache data parse fail.');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (hasCache) {
|
|
|
return cdata;
|
|
|
} else {
|
|
|
return getOriginData();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return getOriginData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取新品到着数据
|
|
|
*/
|
...
|
...
|
@@ -215,6 +272,49 @@ 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 {
|
|
|
hasCache = true;
|
|
|
cdata = JSON.parse(cdata);
|
|
|
} catch (e) {
|
|
|
logger.debug('list_new render cache data parse fail.');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (hasCache) {
|
|
|
return cdata;
|
|
|
} else {
|
|
|
return getOriginData();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return getOriginData();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 根据品牌域名查询品牌信息
|
|
|
*/
|
...
|
...
|
@@ -588,7 +688,9 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
this.shopApi = new ShopApiModel(ctx);
|
|
|
|
|
|
this.getListData = getListData.bind(this);
|
|
|
this.getListDataPre = getListDataPre.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);
|
...
|
...
|
|