...
|
...
|
@@ -6,9 +6,9 @@ |
|
|
*/
|
|
|
|
|
|
'use strict';
|
|
|
const logger = global.yoho.logger;
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
const utils = '../../../utils';
|
|
|
const api = global.yoho.API;
|
|
|
const Promise = require('bluebird');
|
|
|
const saleApi = require('./sale-api');
|
|
|
const searchApi = require('./search-api');
|
|
|
const publicHandler = require('./public-handler');
|
...
|
...
|
@@ -75,37 +75,31 @@ exports.getSaleGoodsData = (params) => { |
|
|
delete finalResult.goods[key].tags.isSale;// 屏蔽 sale 标签
|
|
|
delete finalResult.goods[key].discount; // 屏蔽折扣信息
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('search sale api code no 200');
|
|
|
}
|
|
|
|
|
|
// 处理 VIP 商品数据
|
|
|
if (result[1].code === 200) {
|
|
|
let userInfo = result[1].data.vip_info ? camelCase(result[1].data.vip_info) : {};
|
|
|
|
|
|
if (_.isEmpty(userInfo)) {
|
|
|
logger.info('no user info');
|
|
|
}
|
|
|
let vipInfo = _.get(result, '[1].data.vip_info', {});
|
|
|
|
|
|
if (params.saleType === '2') {
|
|
|
_.forEach(finalResult.goods, (value, key) => {
|
|
|
|
|
|
switch (userInfo.curLevel) {
|
|
|
switch (vipInfo.cur_level) {
|
|
|
case '1':
|
|
|
finalResult.goods[key].salesPrice = value.vip1Price;
|
|
|
finalResult.goods[key].sales_price = value.vip1_price;
|
|
|
finalResult.goods[key].vip1 = true;
|
|
|
break;
|
|
|
case '2':
|
|
|
finalResult.goods[key].salesPrice = value.vip2Price;
|
|
|
finalResult.goods[key].sales_price = value.vip2_price;
|
|
|
finalResult.goods[key].vip2 = true;
|
|
|
break;
|
|
|
case '3':
|
|
|
finalResult.goods[key].salesPrice = value.vip3Price;
|
|
|
finalResult.goods[key].sales_price = value.vip3_price;
|
|
|
finalResult.goods[key].vip3 = true;
|
|
|
break;
|
|
|
default:
|
|
|
finalResult.goods[key].vip = true;
|
|
|
delete finalResult.goods[key].salesPrice;
|
|
|
delete finalResult.goods[key].sales_price;
|
|
|
break;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -168,16 +162,12 @@ exports.getSaleIndexData = (channel) => { |
|
|
if (result[1].data.length > 0) {
|
|
|
finalResult.brandSale = saleHandler.handleSaleActivityData(result[1].data, channel);
|
|
|
}
|
|
|
} else {
|
|
|
logger.error('discount activities api code no 200');
|
|
|
}
|
|
|
|
|
|
// 资源位数据处理
|
|
|
if (result[2].code === 200 && !_.isEmpty(result[2].data)) {
|
|
|
finalResult.topBanner = saleHandler.handleSaleBannerData(result[2].data);
|
|
|
finalResult.activityEnter = saleHandler.handleSaleBannerSmallData(result[2].data);
|
|
|
} else {
|
|
|
logger.error('content code api code no 200 or no data');
|
|
|
}
|
|
|
|
|
|
// 分类处理
|
...
|
...
|
@@ -192,21 +182,21 @@ exports.getSaleIndexData = (channel) => { |
|
|
{forVip: true}
|
|
|
)
|
|
|
);
|
|
|
} else {
|
|
|
logger.error('index vip category api code no 200');
|
|
|
}
|
|
|
|
|
|
// 断码区分类处理
|
|
|
if (result[4].code === 200) {
|
|
|
let breakingSizeSort = saleHandler.handleSaleBreakingSizeData(result[4].data);
|
|
|
|
|
|
return api.all([saleApi.getSaleGoodsList({
|
|
|
channel: channel,
|
|
|
saleType: '5', // app 与 pc 有冲突,为 PC 加一个 5 的选项
|
|
|
limit: '1',
|
|
|
breakSize: breakingSizeSort.breakSize,
|
|
|
breakSort: breakingSizeSort.breakSort
|
|
|
})]).then(subResult => {
|
|
|
return api.all([
|
|
|
saleApi.getSaleGoodsList({
|
|
|
channel: channel,
|
|
|
saleType: '5', // app 与 pc 有冲突,为 PC 加一个 5 的选项
|
|
|
limit: '1',
|
|
|
breakSize: breakingSizeSort.breakSize,
|
|
|
breakSort: breakingSizeSort.breakSort
|
|
|
})
|
|
|
]).then(subResult => {
|
|
|
if (subResult[0].code === 200) {
|
|
|
finalResult.saleCategory.push(
|
|
|
saleHandler.handleSaleCategoryData(
|
...
|
...
|
@@ -224,14 +214,10 @@ exports.getSaleIndexData = (channel) => { |
|
|
finalResult.saleCategory.push(
|
|
|
saleHandler.handleSaleCategoryData(result[5].data.filter.group_sort, '3', channel)
|
|
|
);
|
|
|
} else {
|
|
|
logger.error('newSale category api code no 200');
|
|
|
}
|
|
|
return finalResult;
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
logger.error('breakYards category api code no 200');
|
|
|
}
|
|
|
return finalResult;
|
|
|
});
|
...
|
...
|
@@ -275,8 +261,6 @@ exports.getSaleOthersData = (params, channel) => { |
|
|
if (!_.isEmpty(result[1].data.filter)) {
|
|
|
// 顶部筛选条件
|
|
|
finalResult.filters = publicHandler.handleSaleFilterData(result[1].data.filter, params);
|
|
|
} else {
|
|
|
logger.error('data filter is empty');
|
|
|
}
|
|
|
|
|
|
// 处理排序数据
|
...
|
...
|
@@ -291,12 +275,10 @@ exports.getSaleOthersData = (params, channel) => { |
|
|
};
|
|
|
|
|
|
_.forEach(finalResult.goods, (value, key) => {
|
|
|
delete finalResult.goods[key].tags.isNew; // 屏蔽 new 标签
|
|
|
delete finalResult.goods[key].tags.isSale;// 屏蔽 sale 标签
|
|
|
delete finalResult.goods[key].tags.is_new; // 屏蔽 new 标签
|
|
|
delete finalResult.goods[key].tags.is_sale;// 屏蔽 sale 标签
|
|
|
delete finalResult.goods[key].discount; // 屏蔽折扣信息
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('goods list api code no 200');
|
|
|
}
|
|
|
|
|
|
// 获取焦点图数据
|
...
|
...
|
@@ -307,8 +289,6 @@ exports.getSaleOthersData = (params, channel) => { |
|
|
delete finalResult.topBanner.list[key].href;
|
|
|
});
|
|
|
}
|
|
|
} else {
|
|
|
logger.error('content code api code no 200');
|
|
|
}
|
|
|
|
|
|
// 获取分类筛选数据
|
...
|
...
|
@@ -317,46 +297,36 @@ exports.getSaleOthersData = (params, channel) => { |
|
|
// 获取左侧类目数据
|
|
|
finalResult.leftContent = publicHandler.handleSaleSortData(result[3].data.filter.group_sort, params);
|
|
|
|
|
|
} else {
|
|
|
logger.error('left content category api code no 200');
|
|
|
}
|
|
|
|
|
|
if (!_.isEmpty(result[4])) {
|
|
|
// 处理 VIP 商品数据
|
|
|
if (result[4].code === 200 && parseInt(params.saleType, 10) === 2) {
|
|
|
let userInfo = result[4].data.vip_info ? camelCase(result[4].data.vip_info) : {};
|
|
|
|
|
|
if (_.isEmpty(userInfo)) {
|
|
|
logger.info('no user info');
|
|
|
}
|
|
|
let vipInfo = _.get(result, '[4].data.vip_info', {});
|
|
|
|
|
|
_.forEach(finalResult.goods, (value, key) => {
|
|
|
|
|
|
switch (userInfo.curLevel) {
|
|
|
switch (vipInfo.cur_level) {
|
|
|
case '1':
|
|
|
finalResult.goods[key].salesPrice = value.vip1Price;
|
|
|
finalResult.goods[key].sales_price = value.vip1_price;
|
|
|
finalResult.goods[key].vip1 = true;
|
|
|
break;
|
|
|
case '2':
|
|
|
finalResult.goods[key].salesPrice = value.vip2Price;
|
|
|
finalResult.goods[key].sales_price = value.vip2_price;
|
|
|
finalResult.goods[key].vip2 = true;
|
|
|
break;
|
|
|
case '3':
|
|
|
finalResult.goods[key].salesPrice = value.vip3Price;
|
|
|
finalResult.goods[key].sales_price = value.vip3_price;
|
|
|
finalResult.goods[key].vip3 = true;
|
|
|
break;
|
|
|
default:
|
|
|
finalResult.goods[key].vip = true;
|
|
|
delete finalResult.goods[key].salesPrice;
|
|
|
delete finalResult.goods[key].sales_price;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('user api code no 200 or no vip category');
|
|
|
}
|
|
|
} else {
|
|
|
logger.info('no user info get from api');
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
...
|
...
|
@@ -386,13 +356,15 @@ exports.getSaleDiscountData = (params, channel) => { |
|
|
}
|
|
|
]
|
|
|
};
|
|
|
} else {
|
|
|
logger.error('discount activity data[0] web_url empty');
|
|
|
}
|
|
|
}
|
|
|
return api.all([
|
|
|
saleApi.getSaleGoodsList({channel: channel, saleType: '3', limit: '1',
|
|
|
productPool: result[1].data[0].product_pool}),
|
|
|
saleApi.getSaleGoodsList({
|
|
|
channel: channel,
|
|
|
saleType: '3',
|
|
|
limit: '1',
|
|
|
productPool: result[1].data[0].product_pool
|
|
|
}),
|
|
|
saleApi.getSaleGoodsList(Object.assign(params, {productPool: result[1].data[0].product_pool}))
|
|
|
]).then(subResult => {
|
|
|
|
...
|
...
|
@@ -406,8 +378,6 @@ exports.getSaleDiscountData = (params, channel) => { |
|
|
opts: publicHandler.handleSaleOptsData(params, subResult[0].data.total)
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('category api no 200');
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -416,18 +386,14 @@ exports.getSaleDiscountData = (params, channel) => { |
|
|
finalResult.saleList.goods = productProcess.processProductList(subResult[1].data.product_list);
|
|
|
finalResult.saleList.totalCount = subResult[1].data.total;
|
|
|
_.forEach(finalResult.saleList.goods, (value, key) => {
|
|
|
delete finalResult.saleList.goods[key].tags.isNew; // 屏蔽 new 标签
|
|
|
delete finalResult.saleList.goods[key].tags.isSale;// 屏蔽 sale 标签
|
|
|
delete finalResult.saleList.goods[key].tags.is_new; // 屏蔽 new 标签
|
|
|
delete finalResult.saleList.goods[key].tags.is_sale;// 屏蔽 sale 标签
|
|
|
delete finalResult.saleList.goods[key].discount; // 屏蔽折扣信息
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('discount goods list api code no 200');
|
|
|
}
|
|
|
|
|
|
return finalResult;
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('discount activity api code no 200');
|
|
|
}
|
|
|
return finalResult;
|
|
|
});
|
...
|
...
|
@@ -453,8 +419,6 @@ exports.getSalebreakingYardsData = (params, channel) => { |
|
|
_.forEach(finalResult.topBanner.list, (value, key) => {
|
|
|
delete finalResult.topBanner.list[key].href;
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('content code api code no 200');
|
|
|
}
|
|
|
|
|
|
// 断码区产品筛选需要断码区尺码数据,改为串行处理
|
...
|
...
|
@@ -485,8 +449,6 @@ exports.getSalebreakingYardsData = (params, channel) => { |
|
|
if (subResult[0].code === 200) {
|
|
|
finalResult.leftContent =
|
|
|
publicHandler.handleSaleSortData(subResult[0].data.filter.group_sort, params);
|
|
|
} else {
|
|
|
logger.error('breakYards left content api code no 200');
|
|
|
}
|
|
|
|
|
|
// 处理商品数据
|
...
|
...
|
@@ -511,17 +473,15 @@ exports.getSalebreakingYardsData = (params, channel) => { |
|
|
};
|
|
|
|
|
|
_.forEach(finalResult.goods, (value, key) => {
|
|
|
delete finalResult.goods[key].tags.isNew; // 屏蔽 new 标签
|
|
|
delete finalResult.goods[key].tags.isSale;// 屏蔽 sale 标签
|
|
|
delete finalResult.goods[key].tags.is_new; // 屏蔽 new 标签
|
|
|
delete finalResult.goods[key].tags.is_sale;// 屏蔽 sale 标签
|
|
|
delete finalResult.goods[key].discount; // 屏蔽折扣信息
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('breakYards goods list code no 200');
|
|
|
}
|
|
|
return finalResult;
|
|
|
});
|
|
|
} else {
|
|
|
logger.error('breakYards size api code no 200');
|
|
|
return Promise.reject();
|
|
|
}
|
|
|
});
|
|
|
};
|
...
|
...
|
|