Authored by 刘传洋

bug

... ... @@ -81,9 +81,10 @@ exports.getListData = (params, channel) => {
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.list = Object.assign(searchHandler.handlePathNavData(result[1].data.sort, params, 'sort'), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
finalResult.list = Object.assign(
searchHandler.handlePathNavData(result[1].data.sort, params, 'sort', channel), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
}
// 获取商品数据和顶部筛选条件
... ... @@ -150,9 +151,10 @@ exports.getListNewData = (params, channel) => {
// 获取左侧类目数据
if (result[1].code === 200) {
finalResult.list = Object.assign(searchHandler.handlePathNavData(result[1].data.sort, params, 'new'), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
finalResult.list = Object.assign(
searchHandler.handlePathNavData(result[1].data.sort, params, 'new', channel), {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
});
}
// 获取商品数据和顶部筛选条件
... ... @@ -247,7 +249,7 @@ exports.getBrandData = (params, extra, channel) => {
if (result[1].code === 200) {
Object.assign(finalResult.brand, {
leftContent: searchHandler.handleSortData(result[1].data.sort, params)
}, searchHandler.handlePathNavData(extra, params, 'brand'));
}, searchHandler.handlePathNavData(extra, params, 'brand', channel));
}
// 获取商品数据和顶部筛选条件
... ... @@ -443,7 +445,7 @@ exports.getShopData = (shopId, channel, params, shopInfo) => {
Object.assign(finalResult,
result[0], // 头部数据
searchHandler.handlePathNavData(shopInfo, params, 'shop') // 面包屑导航
searchHandler.handlePathNavData(shopInfo, params, 'shop', channel) // 面包屑导航
);
_.set(finalResult, 'headerData.header', true);
... ... @@ -578,7 +580,7 @@ exports.getShopListData = (channel, params, uid) => {
};
// 面包屑导航
Object.assign(finalResult, searchHandler.handlePathNavData({}, params, 'shop'));
Object.assign(finalResult, searchHandler.handlePathNavData({}, params, 'shop', channel));
// 店铺装修
if (result[1].code === 200) {
... ...
... ... @@ -507,7 +507,7 @@ exports.getSaleSpecialData = (id, params, channel) => {
let resData = {},
apiList = [
headerModel.requestHeaderData(channel),
searchApi.getSortList()
searchApi.getSortList(params)
];
if (special && special.data) {
... ...
... ... @@ -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;
});
}
});
}
};
/**
... ...
... ... @@ -829,11 +829,18 @@ exports.handleFilterDataAll = (data, params) => {
* 根据页面设置面包屑导航
* @type {[type]}
*/
exports.handlePathNavData = (data, params, page) => {
exports.handlePathNavData = (data, params, page, channel) => {
let rootName = '首页';
if (channel && _.isString(channel)) {
rootName = channel.toUpperCase() + rootName;
}
let pathNav = [{
href: '/',
name: '首页', // TODO 从根据cookie获取频道
pathTitle: '首页'
name: rootName, // '首页', // TODO 从根据cookie获取频道
pathTitle: rootName // '首页'
}];
switch (page) {
... ... @@ -921,6 +928,7 @@ exports.handlePathNavData = (data, params, page) => {
* 分页
* @param {[type]} total 总页数
* @param {[type]} params 筛选条件
* @param {[noNextBtn]} 列表是否有下一页的按钮,如果有则实际查询数比传递参数的少一个,入60 => 59
* @return {[type]} [description]
*/
exports.handlePagerData = (total, params, noNextBtn) => {
... ... @@ -936,7 +944,21 @@ exports.handlePagerData = (total, params, noNextBtn) => {
let currentPage = parseInt(_.get(params, 'page', 1), 10); // 当前页
let perPageCount = parseInt(_.get(params, 'limit', true === noNextBtn ? 60 : 59), 10); // 每页商品数
let totalPage = parseInt(total / perPageCount, 10) + 1; // 总页数
let totalPage = Math.ceil(total / perPageCount); // 总页数
if (true !== noNextBtn) {
switch (perPageCount) {
case 200:
perPageCount = 199;
break;
case 100:
perPageCount = 99;
break;
case 60:
perPageCount = 59;
break;
}
}
if (currentPage === 1) {
// 当前页为 1,一定没有上一页
... ...