Authored by yyq

search api

... ... @@ -25,22 +25,22 @@ const getSortByConditionAsync = (condition) => {
const adsUrl = '/shops/api/v1/ads/getList';
// 判断用户是否收藏品牌
const isFavoriteBrandUrl = '/shops/service/v1/favorite/';
// const isFavoriteBrandUrl = '/shops/service/v1/favorite/';
// 根据品牌查询相关文章
const relateArticleUrl = 'guang/service/v2/article/getArticleByBrand';
const getSearchCackeKey = params => {
let ks = [];
let ks= [];
_.forEach(params, (val, key) => {
if(params.hasOwnProperty(key) && !_.includes(['page', 'limit', 'need_filter', 'order'], key)) {
if (params.hasOwnProperty(key) && !_.includes(['page', 'limit', 'need_filter', 'order'], key)) {
ks.push(val);
}
});
return md5(ks.join('_'));
}
};
/**
* 获取商品列表
... ... @@ -58,31 +58,31 @@ const getProductList = (params) => {
Object.assign(finalParams, params);
let cKey= getSearchCackeKey(finalParams);
let cKey = getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let hasCache = false;
let hasCache= false;
if(cdata) {
if (cdata) {
try {
cdata= JSON.parse(cdata);
} catch(e) {
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);
if (hasCache && result && result.data) {
Object.assign(result.data, cdata);
} else {
if(result && result.data && result.data.filter) {
if (result && result.data && result.data.filter) {
cache.set(cKey, Object.assign({}, {
filter: result.data.filter,
standard: result.data.standard
... ... @@ -108,20 +108,20 @@ const getSortList = (params) => {
Object.assign(finalParams, params);
let cKey= getSearchCackeKey(finalParams);
let cKey = getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let cdataObj;
if(cdata) {
if (cdata) {
try {
cdataObj= JSON.parse(cdata);
} catch(e) {
cdataObj = JSON.parse(cdata);
} catch (e) {
logger.debug('getSortList cache data parse fail.');
}
}
if(cdataObj) {
if (cdataObj) {
return cdataObj;
} else {
return yohoApi.get('', finalParams).then(ret => {
... ... @@ -224,18 +224,20 @@ const getBrandShop = (query) => {
Object.assign(finalParams, {keyword: query});
let cKey= getSearchCackeKey(finalParams);
let cKey = getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let retObj;
try {
if(cdata) retObj = JSON.parse(cdata);
} catch(e) {
if (cdata) {
retObj = JSON.parse(cdata);
}
} catch (e) {
logger.debug('getBrandShop cache data parse fail.');
}
if(retObj) {
if (retObj) {
return retObj;
} else {
return yohoApi.get('', finalParams).then(ret => {
... ... @@ -244,7 +246,7 @@ const getBrandShop = (query) => {
cache.set(cKey, ret.data);
return ret.data;
}
});return
});
}
});
};
... ... @@ -254,25 +256,25 @@ const getBrandShop = (query) => {
* @return
*/
const getShopsByBrandId = bid => {
let finalParams= {
let finalParams = {
method: 'app.shop.queryShopsByBrandId',
brand_id: bid
}
};
let cKey= getSearchCackeKey(finalParams);
let cKey = getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let cdataObj;
if(cdata) {
if (cdata) {
try {
cdataObj= JSON.parse(cdata);
} catch(e) {
cdataObj = JSON.parse(cdata);
} catch (e) {
logger.debug('getShopsByBrandId cache data parse fail.');
}
}
if(cdataObj) {
if (cdataObj) {
return cdataObj;
} else {
return yohoApi.get('', finalParams).then(ret => {
... ... @@ -287,10 +289,9 @@ const getShopsByBrandId = bid => {
};
const shopFormat = shopDatas => {
let shopEntry = [];
_.forEach(shopDatas, val => {
_.forEach(shopDatas, val => {
let sorts = [];
let shopId = val.shop && (val.shop.brand_id || val.shop.id) || ''; // 接口中品牌下的店铺为brand_id,品牌为id
let url = helpers.urlFormat('', {shopId: shopId}, val.shop.brand_domain);
... ... @@ -302,6 +303,7 @@ const shopFormat = shopDatas => {
}
let isFull = false;
for (let misort of ss.sub) {
if (sorts.length >= 10) {
isFull = true;
... ... @@ -359,9 +361,10 @@ const getShopList = params => {
}).then(shops => { // 获取品牌/品牌店下所有的分类
if (_.isArray(shops)) {
brandShops = shops;
let promises = [];
for (let s of shops) {
promises.push(getSortList({
brand: s.brand_id
... ... @@ -376,8 +379,8 @@ const getShopList = params => {
}
}).then(sorts => { // 数组则为品牌店列表,否则为品牌
let shopData = [];
if (_.isArray(sorts)) {
_.forEach(sorts, (val, index) => {
... ... @@ -421,7 +424,7 @@ const getBrandData = (params) => {
domain: params.domain || ''
};
return yohoApi.get(isFavoriteBrandUrl, finalParams);
return yohoApi.get('', finalParams);
};
/**
... ...