...
|
...
|
@@ -13,9 +13,7 @@ const ServiceAPI = require(`${global.library}/api`).ServiceAPI; |
|
|
const SearchAPI = require(`${global.library}/api`).SearchAPI;
|
|
|
const sign = require(`${global.library}/sign`);
|
|
|
const helpers = require(`${global.library}/helpers`);
|
|
|
const images = require(`${global.utils}/images`);
|
|
|
|
|
|
// const processProduct = require(`${global.utils}/product-process`).processProductList;
|
|
|
const processProduct = require(`${global.utils}/product-process`).processProduct;
|
|
|
const log = require(`${global.library}/logger`);
|
|
|
|
|
|
|
...
|
...
|
@@ -52,153 +50,19 @@ const channelMap = dataMap.channel; |
|
|
|
|
|
const sortMap = dataMap.sort;
|
|
|
|
|
|
/**
|
|
|
* 获取导航信息
|
|
|
* @param {[Object]} 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
const getNavs = rawNavs => {
|
|
|
const navs = rawNavs;
|
|
|
let list = [];
|
|
|
|
|
|
_.forEach(navs, it => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.name;
|
|
|
obj.href = it.url;
|
|
|
|
|
|
list.push(obj);
|
|
|
});
|
|
|
|
|
|
return list;
|
|
|
};
|
|
|
|
|
|
// 构建url
|
|
|
const httpBuildQuery = data => {
|
|
|
return searchApi.get('/search.json', data);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 格式化商品信息
|
|
|
*
|
|
|
* @param array $productData 需要格式化的商品数据
|
|
|
* @param bool $showTags 控制是否显示标签
|
|
|
* @param bool $showNew 控制是否显示NEW图标
|
|
|
* @param bool $showSale 控制是否显示SALE图标
|
|
|
* @param int $width 图片的宽度
|
|
|
* @param int $height 图片的高度
|
|
|
* @param bool $isApp 判断是不是APP访问
|
|
|
* @param bool $showPoint 商品价格是否显示小数位,默认显示
|
|
|
* @return array | false
|
|
|
*/
|
|
|
const formatProduct = (productData, showTags, showNew, showSale, width, height, isApp, showPoint) => {
|
|
|
let result = {};
|
|
|
|
|
|
// 默认值
|
|
|
if (!showTags) {
|
|
|
showTags = true;
|
|
|
}
|
|
|
if (!showNew) {
|
|
|
showNew = true;
|
|
|
}
|
|
|
if (!showSale) {
|
|
|
showSale = true;
|
|
|
}
|
|
|
if (!width) {
|
|
|
width = 290;
|
|
|
}
|
|
|
if (!height) {
|
|
|
height = 388;
|
|
|
}
|
|
|
if (!isApp) {
|
|
|
isApp = false;
|
|
|
}
|
|
|
if (!showPoint) {
|
|
|
showPoint = true;
|
|
|
}
|
|
|
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!productData.product_skn || !productData.goods_list[0]) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (parseInt(productData.market_price, 0) === parseInt(productData.sales_price, 0)) {
|
|
|
productData.market_price = false;
|
|
|
}
|
|
|
|
|
|
// 设置默认图片
|
|
|
_.forEach(productData.goods_list, item => {
|
|
|
if (item.is_default === 'Y') {
|
|
|
productData.default_images = item.images_url;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (!productData.default_images) {
|
|
|
productData.default_images = productData.goods_list[0].images_url;
|
|
|
}
|
|
|
|
|
|
result.id = productData.product_skn;
|
|
|
result.product_id = productData.product_id;
|
|
|
result.thumb = images.getImageUrl(productData.default_images, width, height);
|
|
|
result.name = productData.product_name;
|
|
|
result.price = !productData.market_price ? false : productData.market_price;
|
|
|
result.salePrice = productData.sales_price;
|
|
|
if (showPoint) {
|
|
|
result.price += '.00';
|
|
|
result.salePrice += '.00';
|
|
|
}
|
|
|
|
|
|
result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y');
|
|
|
result.url = 'http://item.yohobuy.com/product/pro_' +
|
|
|
productData.product_id + '_' +
|
|
|
productData.goods_list[0].goods_id + '/' +
|
|
|
productData.cn_alphabet + '.html';
|
|
|
|
|
|
// APP访问需要加附加的参数
|
|
|
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
if (isApp) {
|
|
|
result.url += '?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' +
|
|
|
productData.product_skn + '}}';
|
|
|
}
|
|
|
|
|
|
if (showTags) {
|
|
|
result.tags = {};
|
|
|
result.tags.is_new = showNew && productData.is_new && productData.is_new === 'Y'; // 新品
|
|
|
result.tags.is_discount = showSale && productData.is_discount && productData.is_discount === 'Y'; // 在售
|
|
|
result.tags.is_limited = productData.is_limited && productData.is_limited === 'Y'; // 限量
|
|
|
result.tags.is_yohood = productData.is_yohood && productData.is_yohood === 'Y'; // YOHOOD
|
|
|
result.tags.midYear = productData['mid-year'] && productData['mid-year'] === 'Y'; // 年中
|
|
|
result.tags.yearEnd = productData['year-end'] && productData['year-end'] === 'Y'; // 年末
|
|
|
result.tags.is_advance = productData.is_advance && productData.is_advance === 'Y'; // 再到着
|
|
|
|
|
|
if (result.is_soon_sold_out && result.tags.is_discount) {
|
|
|
result.tags.is_new = false;// 打折与即将售完组合显示打折
|
|
|
} else if (result.tags.is_discount &&
|
|
|
(result.tags.is_new || result.tags.is_limited || result.tags.is_yohood || result.tags.is_advance)) {
|
|
|
result.tags.is_discount = false;// 打折与其它组合则隐藏打折
|
|
|
} else if (result.tags.is_yohood && result.tags.is_new) {
|
|
|
result.tags.is_new = false;// YOHOOD和新品组合显示YOHOOD
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取普通banner
|
|
|
* @param {[Object]} data 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
const getBannerList = data => {
|
|
|
|
|
|
return _.map(data, item => {
|
|
|
return Object.assign(item, {
|
|
|
href: item.url,
|
|
|
img: item.src,
|
|
|
name: item.title
|
|
|
});
|
|
|
});
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
@@ -218,12 +82,7 @@ const getDebrisSlide = data => { |
|
|
|
|
|
_.mapKeys(data, (value, key) => {
|
|
|
_.forEach(value, slideData => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.href = slideData.url;
|
|
|
obj.img = slideData.img;
|
|
|
|
|
|
floorData.debrisSlider[key].push(obj);
|
|
|
floorData.debrisSlider[key].push(slideData);
|
|
|
});
|
|
|
});
|
|
|
|
...
|
...
|
@@ -237,19 +96,10 @@ const getDebrisSlide = data => { |
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
const getadbannerData = data => {
|
|
|
const obj = {
|
|
|
adbanner: {
|
|
|
href: '',
|
|
|
img: '',
|
|
|
name: ''
|
|
|
}
|
|
|
};
|
|
|
|
|
|
obj.adbanner.href = data.url;
|
|
|
obj.adbanner.img = data.src;
|
|
|
obj.adbanner.name = data.title;
|
|
|
|
|
|
return obj;
|
|
|
return {
|
|
|
adbanner: data
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -294,7 +144,6 @@ const getNewReportFloorData = args => { |
|
|
let forthItem = args[4];
|
|
|
|
|
|
let list = [];
|
|
|
let obj = {};
|
|
|
|
|
|
const data = {
|
|
|
newReport: {
|
...
|
...
|
@@ -308,24 +157,13 @@ const getNewReportFloorData = args => { |
|
|
let floorDatas = [];
|
|
|
|
|
|
|
|
|
obj.href = item[0].url;
|
|
|
obj.img = item[0].src;
|
|
|
|
|
|
list.push(obj);
|
|
|
list.push(item[0]);
|
|
|
|
|
|
_.forEach(secondItem, (floorData) => {
|
|
|
let o = {};
|
|
|
|
|
|
o.href = floorData.url;
|
|
|
o.img = floorData.src;
|
|
|
|
|
|
list.push(o);
|
|
|
list.push(floorData);
|
|
|
});
|
|
|
|
|
|
obj.href = thirdItem[0].url;
|
|
|
obj.img = thirdItem[0].src;
|
|
|
|
|
|
list.push(obj);
|
|
|
list.push(thirdItem[0]);
|
|
|
|
|
|
data.newReport.list = list;
|
|
|
|
...
|
...
|
@@ -368,14 +206,7 @@ const getPreBrandTopData = (args, type) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
_.forEach(item, (topData) => {
|
|
|
let o = {};
|
|
|
|
|
|
o.href = topData.url;
|
|
|
o.img = topData.src;
|
|
|
|
|
|
data.preferenceBrands.imgBrand.push(o);
|
|
|
});
|
|
|
data.preferenceBrands.imgBrand = item;
|
|
|
|
|
|
setChannelType(data.preferenceBrands, type);
|
|
|
|
...
|
...
|
@@ -407,54 +238,27 @@ const getHotGoodsFloorData = (args, type) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
_.forEach(item.data.menuNav.list, it => {
|
|
|
let obj = {};
|
|
|
category = item.data.menuNav.list;
|
|
|
|
|
|
|
|
|
obj.name = it.name;
|
|
|
obj.href = it.url;
|
|
|
category.push(obj);
|
|
|
});
|
|
|
|
|
|
_.forEach(item.data.menuNav.blocks, it => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.img;
|
|
|
keyword.push(obj);
|
|
|
});
|
|
|
keyword = item.data.menuNav.blocks;
|
|
|
|
|
|
_.forEach(item.data.imgs, (it, idx) => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.img;
|
|
|
|
|
|
if (idx === 0 || (idx === 4 && type === 'boys')) {
|
|
|
brands.push(obj);
|
|
|
brands.push(it);
|
|
|
} else {
|
|
|
types.push(obj);
|
|
|
types.push(it);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
_.forEach(nextItem.data, (it) => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.src;
|
|
|
|
|
|
products.push(obj);
|
|
|
});
|
|
|
products = nextItem.data;
|
|
|
|
|
|
object.name = item.data.name;
|
|
|
object.keyword = keyword;
|
|
|
object.category = category;
|
|
|
object.brands = brands;
|
|
|
object.types = types;
|
|
|
object.navs = getNavs(item.data.navs.list);
|
|
|
object.navs = item.data.navs.list;
|
|
|
object.products = products;
|
|
|
list.push(object);
|
|
|
|
...
|
...
|
@@ -489,7 +293,6 @@ const getBoysSingleHot = (args, type) => { |
|
|
for (let i = 0; i < len; i++) {
|
|
|
let pos = i;
|
|
|
let val = {};
|
|
|
let obj = {};
|
|
|
|
|
|
if (i === 1) {
|
|
|
val = args[1].data[0]; // 第二个是大图
|
...
|
...
|
@@ -501,9 +304,7 @@ const getBoysSingleHot = (args, type) => { |
|
|
}
|
|
|
val = args[2].data[pos];
|
|
|
}
|
|
|
obj.href = val.url;
|
|
|
obj.img = val.src;
|
|
|
list.push(obj);
|
|
|
list.push(val);
|
|
|
}
|
|
|
|
|
|
data.singlehot.imgHot = list;
|
...
|
...
|
@@ -568,7 +369,7 @@ const getSingleHotFloorData = (args, type) => { |
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const getAsyncSingleHot = (args, queryResult, type) => {
|
|
|
const getSingehotViaResult = (args, queryResult, type) => {
|
|
|
const data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
...
|
...
|
@@ -579,40 +380,28 @@ const getAsyncSingleHot = (args, queryResult, type) => { |
|
|
};
|
|
|
|
|
|
if (args[3].template_name === 'app_icon_list') {
|
|
|
_.forEach(args[3].data, it => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.href = it.url;
|
|
|
obj.name = it.title;
|
|
|
obj.img = it.src;
|
|
|
|
|
|
data.singlehot.brands.push(obj);
|
|
|
});
|
|
|
data.singlehot.brands = args[3].data;
|
|
|
}
|
|
|
|
|
|
if (queryResult.data) {
|
|
|
_.forEach(queryResult.data.product_list || [], (it, index) => {
|
|
|
let obj = {};
|
|
|
const formatData = formatProduct(it, true, true, true, 280, 373);
|
|
|
const formatData = processProduct(it, {
|
|
|
width: 280,
|
|
|
height: 373
|
|
|
});
|
|
|
|
|
|
if (index > 12) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
obj.price = formatData.salePrice;
|
|
|
obj.href = formatData.url;
|
|
|
obj.img = formatData.thumb;
|
|
|
obj.name = formatData.name;
|
|
|
|
|
|
if (index < 3) {
|
|
|
obj.tip = 'TOP' + (index + 1);
|
|
|
formatData.tip = 'TOP' + (index + 1);
|
|
|
}
|
|
|
|
|
|
data.singlehot.imgHot.push(obj);
|
|
|
data.singlehot.imgHot.push(formatData);
|
|
|
});
|
|
|
}
|
|
|
data.singlehot.navs = getNavs(args[1].data);
|
|
|
data.singlehot.navs = args[1].data;
|
|
|
setChannelType(data.singlehot, type);
|
|
|
return data;
|
|
|
};
|
...
|
...
|
@@ -626,14 +415,14 @@ const getAsyncSingleHot = (args, queryResult, type) => { |
|
|
* @param {Type} type 人气单品楼层的类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const processFloorDataWithQueryReusult = (rawData, floorData, queryResult, title, type) => {
|
|
|
const processFloorDataWithQueryReusult = (rawData, queryResult, title, type) => {
|
|
|
let data = {};
|
|
|
|
|
|
_.forEach(rawData, (subData, index) => {
|
|
|
const text = subData.data.text && getText(subData.data.text);
|
|
|
|
|
|
if (text === title) {
|
|
|
data = getAsyncSingleHot(rawData.slice(index, index + 4), queryResult, type);
|
|
|
data = getSingehotViaResult(rawData.slice(index, index + 4), queryResult, type);
|
|
|
}
|
|
|
});
|
|
|
|
...
|
...
|
@@ -654,7 +443,7 @@ const getNewGoodsFloorData = args => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
data.newArrivls.navs = getNavs(args[1].data);
|
|
|
data.newArrivls.navs = args[1].data;
|
|
|
|
|
|
return data;
|
|
|
};
|
...
|
...
|
@@ -700,7 +489,10 @@ exports.getNewArrival = channel => { |
|
|
});
|
|
|
|
|
|
_.forEach(data, (item) => {
|
|
|
result.push(formatProduct(item, true, true, true, 280, 373));
|
|
|
result.push(processProduct(item, {
|
|
|
width: 280,
|
|
|
height: 373
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
return result;
|
...
|
...
|
@@ -712,27 +504,23 @@ const getCategoryFloorData = args => { |
|
|
const data = {
|
|
|
category: {
|
|
|
name: args[0].data.text,
|
|
|
navs: getNavs(args[1].data),
|
|
|
navs: args[1].data,
|
|
|
list: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
_.forEach(args[2].data, (it, index) => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.href = it.url;
|
|
|
obj.img = it.src;
|
|
|
|
|
|
// 设置图片大小
|
|
|
if (index === 1) {
|
|
|
obj.w = '377;';
|
|
|
obj.h = '504;';
|
|
|
it.w = '377;';
|
|
|
it.h = '504;';
|
|
|
} else {
|
|
|
obj.w = '185';
|
|
|
obj.h = '510';
|
|
|
it.w = '185';
|
|
|
it.h = '510';
|
|
|
}
|
|
|
|
|
|
data.category.list.push(obj);
|
|
|
data.category.list.push(it);
|
|
|
});
|
|
|
|
|
|
return data;
|
...
|
...
|
@@ -742,20 +530,12 @@ const getAccordionFloorData = args => { |
|
|
let data = {
|
|
|
accordion: {
|
|
|
name: args[0].data.text,
|
|
|
navs: getNavs(args[1].data),
|
|
|
navs: args[1].data,
|
|
|
slide: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
_.forEach(args[2].data, it => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
|
|
obj.img = it.src;
|
|
|
obj.href = it.url;
|
|
|
|
|
|
data.accordion.slide.push(obj);
|
|
|
});
|
|
|
data.accordion.slide = args[2].data;
|
|
|
|
|
|
return data;
|
|
|
};
|
...
|
...
|
@@ -912,8 +692,12 @@ exports.getContent = type => { |
|
|
_.forEach(res, (data, index) => {
|
|
|
result.floorData.channel
|
|
|
.splice(result.singlehotFloorIndex[index], 0,
|
|
|
processFloorDataWithQueryReusult(result.rawData,
|
|
|
result.floorData, data, result.singlehotFloorTitle[index], result.channelType));
|
|
|
processFloorDataWithQueryReusult(
|
|
|
result.rawData,
|
|
|
data,
|
|
|
result.singlehotFloorTitle[index],
|
|
|
result.channelType
|
|
|
));
|
|
|
});
|
|
|
|
|
|
return result.floorData;
|
...
|
...
|
|