...
|
...
|
@@ -16,6 +16,7 @@ const images = require('../../../utils/images.js'); |
|
|
const cache = global.yoho.cache;
|
|
|
const logger = global.yoho.logger;
|
|
|
const md5 = require('md5');
|
|
|
const config = require('../../../config/common');
|
|
|
|
|
|
const getSortByConditionAsync = (condition) => {
|
|
|
return api.get('sortgroup.json', condition);
|
...
|
...
|
@@ -42,6 +43,13 @@ const getSearchCackeKey = params => { |
|
|
return md5(ks.join('_'));
|
|
|
};
|
|
|
|
|
|
const getProductListOrig = (finalParams) => {
|
|
|
|
|
|
return yohoApi.get('', finalParams).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表
|
|
|
* @return
|
...
|
...
|
@@ -58,39 +66,49 @@ const getProductList = (params) => { |
|
|
|
|
|
Object.assign(finalParams, params);
|
|
|
|
|
|
let cKey = getSearchCackeKey(finalParams);
|
|
|
if (!config.useCache) {
|
|
|
return getProductListOrig(finalParams);
|
|
|
} else {
|
|
|
let cKey = getSearchCackeKey(finalParams);
|
|
|
|
|
|
return cache.get(cKey).catch().then(cdata => {
|
|
|
let hasCache = false;
|
|
|
return cache.get(cKey).catch().then(cdata => {
|
|
|
let hasCache = false;
|
|
|
|
|
|
if (cdata) {
|
|
|
if (cdata) {
|
|
|
|
|
|
try {
|
|
|
cdata = JSON.parse(cdata);
|
|
|
} catch (e) {
|
|
|
logger.debug('getProductList cache data parse fail.');
|
|
|
}
|
|
|
try {
|
|
|
cdata = JSON.parse(cdata);
|
|
|
} catch (e) {
|
|
|
logger.debug('getProductList cache data parse fail.');
|
|
|
}
|
|
|
|
|
|
if (cdata.filter && cdata.standard) {
|
|
|
hasCache = true;
|
|
|
finalParams.need_filter = 'no';
|
|
|
if (cdata.filter && cdata.standard) {
|
|
|
hasCache = true;
|
|
|
finalParams.need_filter = 'no';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return yohoApi.get('', finalParams).then(result => {
|
|
|
|
|
|
if (hasCache && result && result.data) {
|
|
|
Object.assign(result.data, cdata);
|
|
|
} else {
|
|
|
if (result && result.data && result.data.filter) {
|
|
|
cache.set(cKey, Object.assign({}, {
|
|
|
filter: result.data.filter,
|
|
|
standard: result.data.standard
|
|
|
}), 3600);
|
|
|
return getProductListOrig(finalParams).then(result => {
|
|
|
if (hasCache && result && result.data) {
|
|
|
Object.assign(result.data, cdata);
|
|
|
} else {
|
|
|
if (result && result.data && result.data.filter) {
|
|
|
cache.set(cKey, Object.assign({}, {
|
|
|
filter: result.data.filter,
|
|
|
standard: result.data.standard
|
|
|
}), 3600);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const getSortListOrig = (finalParams) => {
|
|
|
return yohoApi.get('', finalParams).then(ret => {
|
|
|
return ret;
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -108,31 +126,34 @@ const getSortList = (params) => { |
|
|
|
|
|
Object.assign(finalParams, params);
|
|
|
|
|
|
let cKey = getSearchCackeKey(finalParams);
|
|
|
if (!config.useCache) {
|
|
|
return getSortListOrig(finalParams);
|
|
|
} else {
|
|
|
let cKey = getSearchCackeKey(finalParams);
|
|
|
|
|
|
return cache.get(cKey).catch().then(cdata => {
|
|
|
let cdataObj;
|
|
|
return cache.get(cKey).catch().then(cdata => {
|
|
|
let cdataObj;
|
|
|
|
|
|
if (cdata) {
|
|
|
try {
|
|
|
cdataObj = JSON.parse(cdata);
|
|
|
} catch (e) {
|
|
|
logger.debug('getSortList cache data parse fail.');
|
|
|
if (cdata) {
|
|
|
try {
|
|
|
cdataObj = JSON.parse(cdata);
|
|
|
} catch (e) {
|
|
|
logger.debug('getSortList cache data parse fail.');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (cdataObj) {
|
|
|
return cdataObj;
|
|
|
} else {
|
|
|
return yohoApi.get('', finalParams).then(ret => {
|
|
|
|
|
|
if (ret && ret.code === 200) {
|
|
|
cache.set(cKey, ret, 3600);
|
|
|
}
|
|
|
return ret;
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
if (cdataObj) {
|
|
|
return cdataObj;
|
|
|
} else {
|
|
|
return getSortListOrig(finalParams).then(ret => {
|
|
|
if (ret && ret.code === 200) {
|
|
|
cache.set(cKey, ret, 3600);
|
|
|
}
|
|
|
return ret;
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
|