...
|
...
|
@@ -8,18 +8,43 @@ |
|
|
const _ = require('lodash');
|
|
|
|
|
|
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 log = require(`${global.library}/logger`);
|
|
|
|
|
|
|
|
|
const serviceApi = new ServiceAPI();
|
|
|
const searchApi = new SearchAPI();
|
|
|
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
|
|
|
// 创意生活
|
|
|
// const CODE_LIFESTYLE_CHANNEL_1 = '380c38155fd8beee10913a3f5b462da6';
|
|
|
const getShelveTime = duration => {
|
|
|
let today = new Date(),
|
|
|
todayMil = today.getTime().toString().substr(0, 10),
|
|
|
startDayMil = (today.setMonth(today.getMonth() - duration)).toString().substr(0, 10);
|
|
|
|
|
|
// const CODE_LIFESTYLE_CHANNEL_2 = '665f7c2fb9d037ee820766953ee34bf7';
|
|
|
return `${startDayMil},${todayMil}`;
|
|
|
|
|
|
// `
|
|
|
};
|
|
|
|
|
|
// 获取可用的标题
|
|
|
const getText = data => {
|
|
|
let text = data.split(' ')[0];
|
|
|
const regResult = /\w+/.exec(text);
|
|
|
|
|
|
if (data === 'GIRL KIDS' || data === 'BOY KIDS') {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
if (regResult) {
|
|
|
text = text.replace(regResult[0], '');
|
|
|
}
|
|
|
|
|
|
return text;
|
|
|
};
|
|
|
|
|
|
const channelMap = {
|
|
|
boys: {
|
...
|
...
|
@@ -32,14 +57,228 @@ const channelMap = { |
|
|
},
|
|
|
kids: {
|
|
|
code: 'd71f4b27f2a7229fbb31a4bc490a6f36',
|
|
|
gender: 'kids'
|
|
|
gender: '2,3'
|
|
|
},
|
|
|
lifestyle: {
|
|
|
code: '8a341ca7eacc069ba80f02dec80eaf34',
|
|
|
gender: 'lifestyle'
|
|
|
|
|
|
// code: '380c38155fd8beee10913a3f5b462da6',
|
|
|
// code: '665f7c2fb9d037ee820766953ee34bf7',
|
|
|
gender: '2,3'
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const sortMap = {
|
|
|
boys: [
|
|
|
{sort: 147, viewNum: 5}, // 休闲运动鞋
|
|
|
{sort: 129, viewNum: 5}, // 休闲裤
|
|
|
{sort: 152, viewNum: 5}, // 双肩包
|
|
|
{misort: 11, viewNum: 5}, // T恤
|
|
|
{sort: 115, viewNum: 5}, // 衬衫
|
|
|
{sort: 130, viewNum: 5}, // 牛仔裤
|
|
|
{misort: 60, viewNum: 5}, // 帽子
|
|
|
{sort: 124, viewNum: 5}, // 夹克
|
|
|
{sort: 119, viewNum: 5}, // 卫衣
|
|
|
{sort: 162, viewNum: 5}, // 手表
|
|
|
{sort: 148, viewNum: 5}, // 靴子
|
|
|
{misort: 65, viewNum: 5}, // 首饰
|
|
|
{sort: 151, viewNum: 5}, // 时装鞋
|
|
|
{misort: 61, viewNum: 5}, // 太阳镜
|
|
|
{misort: 39, viewNum: 5}, // 袜子
|
|
|
{sort: 346, viewNum: 5}, // 运动裤
|
|
|
{sort: 131, viewNum: 5}, // 短裤
|
|
|
{misort: 66, viewNum: 5}, // 配饰
|
|
|
{misort: 309, viewNum: 5}, // 内裤
|
|
|
{misort: 30, viewNum: 5}, // 打底裤/紧身裤
|
|
|
{sort: 342, viewNum: 5} // 邮差包
|
|
|
],
|
|
|
girls: [
|
|
|
{misort: 16, viewNum: 4}, // 卫衣
|
|
|
{misort: 12, viewNum: 4}, // 衬衫
|
|
|
{misort: 44, viewNum: 4}, // 休闲/运动鞋
|
|
|
{misort: 11, viewNum: 4}, // T恤
|
|
|
{misort: 21, viewNum: 4}, // 夹克
|
|
|
{misort: 257, viewNum: 4}, // 毛衣/针织
|
|
|
{misort: 22, viewNum: 4}, // 大衣/风衣
|
|
|
{misort: 26, viewNum: 4}, // 休闲裤
|
|
|
{misort: 27, viewNum: 4}, // 牛仔裤
|
|
|
{misort: 31, viewNum: 4}, // 连衣裙
|
|
|
{misort: 32, viewNum: 4}, // 半身裙
|
|
|
{misort: 48, viewNum: 4}, // 时装鞋
|
|
|
{misort: 49, viewNum: 4}, // 双肩包
|
|
|
{misort: 50, viewNum: 4}, // 手拎包/单肩包
|
|
|
{misort: 60, viewNum: 4}, // 帽子
|
|
|
{misort: 65, viewNum: 4}, // 首饰
|
|
|
{misort: 59, viewNum: 4}, // 手表
|
|
|
{misort: 61, viewNum: 4}, // 太阳镜
|
|
|
{misort: 66, viewNum: 4} // 配饰
|
|
|
],
|
|
|
kids: [
|
|
|
{misort: 366, viewNum: 4}, // T恤
|
|
|
{misort: 367, viewNum: 4}, // 衬衫
|
|
|
{misort: 396, viewNum: 4}, // 卫衣
|
|
|
{misort: 400, viewNum: 4}, // // 毛衣/针织
|
|
|
{misort: 404, viewNum: 4}, // 夹克
|
|
|
{misort: 369, viewNum: 4}, // 休闲裤
|
|
|
{misort: 388, viewNum: 4}, // 牛仔裤
|
|
|
{misort: 371, viewNum: 4}, // 连衣裙
|
|
|
{misort: 370, viewNum: 4}, // 半身裙
|
|
|
{misort: 368, viewNum: 4}, // 休闲/运动鞋
|
|
|
{misort: 392, viewNum: 4}, // 双肩包
|
|
|
{misort: 414, viewNum: 4}, // 帽子
|
|
|
{misort: 372, viewNum: 4}, // 短裤
|
|
|
{misort: 384, viewNum: 4}, // 打底裤/紧身裤
|
|
|
{misort: 382, viewNum: 4}, // 凉鞋/拖鞋
|
|
|
{misort: 402, viewNum: 4}, // 马甲
|
|
|
{misort: 386, viewNum: 4}, // 背心
|
|
|
{misort: 406, viewNum: 4}, // 大衣/风衣
|
|
|
{misort: 430, viewNum: 4}, // 羽绒服
|
|
|
{misort: 423, viewNum: 4}, // 棉衣
|
|
|
{misort: 417, viewNum: 4} // 套装
|
|
|
],
|
|
|
lifestyle: [
|
|
|
{sort: 171, viewNum: 5}, // 耳机
|
|
|
{sort: 398, viewNum: 5}, // 只能装备
|
|
|
{sort: 185, viewNum: 5}, // 相机
|
|
|
{misort: 259, viewNum: 5}, // 美妆
|
|
|
{sort: 267, viewNum: 5}, // 杯子/水壶
|
|
|
{sort: 313, viewNum: 5}, // 手机/ipad壳套
|
|
|
{sort: 211, viewNum: 5}, // 数码配件
|
|
|
{sort: 292, viewNum: 5}, // 玩偶
|
|
|
{sort: 272, viewNum: 5}, // 储物收纳
|
|
|
{sort: 183, viewNum: 5}, // 启用家居
|
|
|
{sort: 273, viewNum: 5}, // 厨具/餐具
|
|
|
{sort: 271, viewNum: 5} // 靠枕/靠垫/抱枕
|
|
|
]
|
|
|
};
|
|
|
|
|
|
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;
|
|
|
};
|
|
|
|
|
|
const getBannerList = data => {
|
|
|
let list = [];
|
|
|
|
...
|
...
|
@@ -56,6 +295,30 @@ const getBannerList = data => { |
|
|
return list;
|
|
|
};
|
|
|
|
|
|
|
|
|
const getDebrisSlide = data => {
|
|
|
let floorData = {
|
|
|
debrisSlider: {
|
|
|
left: [],
|
|
|
center: [],
|
|
|
right: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
_.mapKeys(data, (value, key) => {
|
|
|
_.forEach(value, slideData => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.href = slideData.url;
|
|
|
obj.img = slideData.img;
|
|
|
|
|
|
floorData.debrisSlider[key].push(obj);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return floorData;
|
|
|
};
|
|
|
|
|
|
const getadbannerData = data => {
|
|
|
const obj = {
|
|
|
adbanner: {
|
...
|
...
|
@@ -80,25 +343,35 @@ const getSlideData = srcData => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
slideData.slide.list = getBannerList(srcData.big_image);
|
|
|
slideData.slide.pagination = getBannerList(srcData.list);
|
|
|
if (srcData.big_image) {
|
|
|
slideData.slide.list = getBannerList(srcData.big_image);
|
|
|
}
|
|
|
|
|
|
if (srcData.list) {
|
|
|
slideData.slide.pagination = getBannerList(srcData.list);
|
|
|
}
|
|
|
|
|
|
if (_.isArray(srcData)) {
|
|
|
slideData.slide.list = getBannerList(srcData);
|
|
|
}
|
|
|
|
|
|
return slideData;
|
|
|
};
|
|
|
|
|
|
|
|
|
const getNewReportFloorData = args => {
|
|
|
let item = args[0].data;
|
|
|
let secondItem = args[1].data;
|
|
|
let thirdItem = args[2].data;
|
|
|
let forthItem = args[3];
|
|
|
const title = args[0].data.text;
|
|
|
let item = args[1].data;
|
|
|
let secondItem = args[2].data;
|
|
|
let thirdItem = args[3].data;
|
|
|
let forthItem = args[4];
|
|
|
|
|
|
let list = [];
|
|
|
let obj = {};
|
|
|
|
|
|
const data = {
|
|
|
newReport: {
|
|
|
name: '最新速报',
|
|
|
name: title,
|
|
|
list: []
|
|
|
}
|
|
|
};
|
...
|
...
|
@@ -139,15 +412,20 @@ const getNewReportFloorData = args => { |
|
|
return floorDatas;
|
|
|
};
|
|
|
|
|
|
const setChannelType = (obj, type) => {
|
|
|
obj[type + 'Channel'] = true;
|
|
|
};
|
|
|
|
|
|
// 优选品牌
|
|
|
const getPreBrandTopData = args => {
|
|
|
let item = args[0].data;
|
|
|
const getPreBrandTopData = (args, type) => {
|
|
|
const title = args[0].data.text;
|
|
|
let item = args[1].data;
|
|
|
|
|
|
const data = {
|
|
|
preferenceBrands: {
|
|
|
name: '优选品牌',
|
|
|
name: title,
|
|
|
imgBrand: [],
|
|
|
brandUrl: helpers.urlFormat('getbrandFloorDataAjax')
|
|
|
brandUrl: helpers.urlFormat('getbrandFloorDataAjax?channelType=' + type)
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
@@ -160,11 +438,13 @@ const getPreBrandTopData = args => { |
|
|
data.preferenceBrands.imgBrand.push(o);
|
|
|
});
|
|
|
|
|
|
setChannelType(data.preferenceBrands, type);
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
// 热门品类
|
|
|
const getHotGoodsFloorData = (args) => {
|
|
|
const getHotGoodsFloorData = (args, type) => {
|
|
|
let item = args[0];
|
|
|
let nextItem = args[1];
|
|
|
|
...
|
...
|
@@ -175,7 +455,6 @@ const getHotGoodsFloorData = (args) => { |
|
|
category = [],
|
|
|
brands = [],
|
|
|
types = [],
|
|
|
navs = {},
|
|
|
products = [];
|
|
|
|
|
|
const data = {
|
...
|
...
|
@@ -184,16 +463,16 @@ const getHotGoodsFloorData = (args) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
_.forEach(item.data.menuNav.list, (it) => {
|
|
|
_.forEach(item.data.menuNav.list, it => {
|
|
|
let obj = {};
|
|
|
|
|
|
|
|
|
obj.name = it.name;
|
|
|
obj.href = it.url;
|
|
|
category.push(obj);
|
|
|
});
|
|
|
|
|
|
_.forEach(item.data.menuNav.blocks, (it) => {
|
|
|
_.forEach(item.data.menuNav.blocks, it => {
|
|
|
let obj = {};
|
|
|
|
|
|
obj.name = it.title;
|
...
|
...
|
@@ -209,7 +488,7 @@ const getHotGoodsFloorData = (args) => { |
|
|
obj.href = it.url;
|
|
|
obj.img = it.img;
|
|
|
|
|
|
if (idx === 0 || idx === 4) {
|
|
|
if (idx === 0 || (idx === 4 && type === 'boys')) {
|
|
|
brands.push(obj);
|
|
|
} else {
|
|
|
types.push(obj);
|
...
|
...
|
@@ -226,28 +505,29 @@ const getHotGoodsFloorData = (args) => { |
|
|
products.push(obj);
|
|
|
});
|
|
|
|
|
|
navs.name = item.data.navs.list[0].name;
|
|
|
navs.href = item.data.navs.list[0].url;
|
|
|
object.name = item.data.name;
|
|
|
object.keyword = keyword;
|
|
|
object.category = category;
|
|
|
object.brands = brands;
|
|
|
object.types = types;
|
|
|
object.navs = navs;
|
|
|
object.navs = getNavs(item.data.navs.list);
|
|
|
object.products = products;
|
|
|
list.push(object);
|
|
|
|
|
|
data.recommend.tplrecommend = list;
|
|
|
|
|
|
setChannelType(data.recommend, type);
|
|
|
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
// 人气单品
|
|
|
const getSingleHotFloorData = args => {
|
|
|
|
|
|
const getBoysSingleHot = (args, type) => {
|
|
|
const len = 10;
|
|
|
const data = {
|
|
|
singlehot: {
|
|
|
name: '人气单品',
|
|
|
name: args[0].data.text,
|
|
|
imgHot: []
|
|
|
}
|
|
|
};
|
...
|
...
|
@@ -262,14 +542,14 @@ const getSingleHotFloorData = args => { |
|
|
let obj = {};
|
|
|
|
|
|
if (i === 1) {
|
|
|
val = args[0].data[0]; // 第二个是大图
|
|
|
val = args[1].data[0]; // 第二个是大图
|
|
|
} else if (i === len - 1) {
|
|
|
val = args[0].data[1]; // 最后一个是大图
|
|
|
val = args[1].data[1]; // 最后一个是大图
|
|
|
} else {
|
|
|
if (pos > 1) { // 小图
|
|
|
pos = pos - 1;
|
|
|
}
|
|
|
val = args[1].data[pos];
|
|
|
val = args[2].data[pos];
|
|
|
}
|
|
|
obj.href = val.url;
|
|
|
obj.img = val.src;
|
...
|
...
|
@@ -277,23 +557,236 @@ const getSingleHotFloorData = args => { |
|
|
}
|
|
|
|
|
|
data.singlehot.imgHot = list;
|
|
|
setChannelType(data.singlehot, type);
|
|
|
floorDatas.push(data);
|
|
|
|
|
|
if (args[2].template_name === 'single_image') {
|
|
|
adData = getadbannerData(args[2].data[0]);
|
|
|
if (args[3].template_name === 'single_image') {
|
|
|
adData = getadbannerData(args[3].data[0]);
|
|
|
floorDatas.push(adData);
|
|
|
}
|
|
|
|
|
|
return floorDatas;
|
|
|
};
|
|
|
|
|
|
const getGirlsSingleHot = args => {
|
|
|
let goods = args[2].data;
|
|
|
let skns = '';
|
|
|
|
|
|
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
});
|
|
|
|
|
|
return searchApi.get('/search.json', {
|
|
|
client_type: 'web',
|
|
|
query: skns,
|
|
|
order: 'shelve_time:desc',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
|
|
attribute_not: '2',
|
|
|
stocknumber: 1,
|
|
|
page: 1,
|
|
|
viewNum: 60
|
|
|
});
|
|
|
};
|
|
|
|
|
|
|
|
|
// 人气单品
|
|
|
const getSingleHotFloorData = (args, type) => {
|
|
|
if (type === 'boys') {
|
|
|
return getBoysSingleHot(args, type);
|
|
|
} else {
|
|
|
return getGirlsSingleHot(args, type);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const getAsyncSingleHot = (args, queryResult, type) => {
|
|
|
const data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
|
|
navs: [],
|
|
|
imgHot: [],
|
|
|
brands: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
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);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_.forEach(queryResult.data.product_list, (it, index) => {
|
|
|
let obj = {};
|
|
|
const formatData = formatProduct(it, true, true, true, 280, 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);
|
|
|
}
|
|
|
|
|
|
data.singlehot.imgHot.push(obj);
|
|
|
});
|
|
|
|
|
|
data.singlehot.navs = getNavs(args[1].data);
|
|
|
setChannelType(data.singlehot, type);
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
const processFloorDataWithQueryReusult = (rawData, floorData, 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);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 组装最新上架楼层数据
|
|
|
*
|
|
|
* @param string data
|
|
|
* return obj
|
|
|
*/
|
|
|
const getNewGoodsFloorData = args => {
|
|
|
const data = {
|
|
|
newArrivls: {
|
|
|
name: args[0].data.text,
|
|
|
navs: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
data.newArrivls.navs = getNavs(args[1].data);
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取最新上架商品数据
|
|
|
*
|
|
|
* @param string $channel
|
|
|
* @return array
|
|
|
*/
|
|
|
exports.getNewArrival = channel => {
|
|
|
let rel = [],
|
|
|
sortList = sortMap[channel],
|
|
|
params = {
|
|
|
order: 'shelve_time:desc',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
|
|
attribute_not: 2,
|
|
|
stocknumber: 3,
|
|
|
shelve_time: getShelveTime(20)
|
|
|
};
|
|
|
|
|
|
params.gender = channelMap[channel].gender;
|
|
|
|
|
|
|
|
|
_.forEach(sortList, (item) => {
|
|
|
let data = Object.assign(item, params);
|
|
|
|
|
|
rel.push(httpBuildQuery(data));
|
|
|
});
|
|
|
|
|
|
return Promise.all(rel).then(res => {
|
|
|
let data = [],
|
|
|
result = [];
|
|
|
|
|
|
_.forEach(sortList, (it, index) => {
|
|
|
if (res[index].data.product_list.length === sortList[index].viewNum) {
|
|
|
data = data.concat(res[index].data.product_list);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
_.forEach(data, (item) => {
|
|
|
result.push(formatProduct(item, true, true, true, 280, 373));
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
|
|
|
const getCategoryFloorData = args => {
|
|
|
const data = {
|
|
|
category: {
|
|
|
name: args[0].data.text,
|
|
|
navs: getNavs(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;';
|
|
|
} else {
|
|
|
obj.w = '185';
|
|
|
obj.h = '510';
|
|
|
}
|
|
|
|
|
|
data.category.list.push(obj);
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
const getAccordionFloorData = args => {
|
|
|
let data = {
|
|
|
accordion: {
|
|
|
name: args[0].data.text,
|
|
|
navs: getNavs(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);
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
const requestContent = type => {
|
|
|
|
|
|
let data = sign.apiSign({
|
|
|
/* eslint-disable */
|
|
|
client_type: 'web',
|
|
|
/* eslint-disable */
|
|
|
client_type: 'web',
|
|
|
/* eslint-enable */
|
|
|
content_code: channelMap[type || 'boys'].code,
|
|
|
gender: channelMap[type || 'boys'].gender,
|
...
|
...
|
@@ -301,7 +794,14 @@ const requestContent = type => { |
|
|
limit: 1000
|
|
|
});
|
|
|
|
|
|
return serviceApi.get('/operations/api/v5/resource/home', data);
|
|
|
return serviceApi.get('/operations/api/v5/resource/home', data).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
return res;
|
|
|
} else {
|
|
|
log.error('获取资源位接口返回状态码 不是 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const floorMap = {
|
...
|
...
|
@@ -309,56 +809,138 @@ const floorMap = { |
|
|
hot: getHotGoodsFloorData,
|
|
|
最新速报: getNewReportFloorData,
|
|
|
人气单品: getSingleHotFloorData,
|
|
|
'GIRL KIDS': getSingleHotFloorData,
|
|
|
'BOY KIDS': getSingleHotFloorData,
|
|
|
优选品牌: getPreBrandTopData,
|
|
|
ad: getadbannerData
|
|
|
最新上架: getNewGoodsFloorData,
|
|
|
ad: getadbannerData,
|
|
|
category: getCategoryFloorData,
|
|
|
accordion: getAccordionFloorData,
|
|
|
debrisSlide: getDebrisSlide
|
|
|
};
|
|
|
|
|
|
const processFloorData = rawData => {
|
|
|
|
|
|
|
|
|
const processFloorData = (rawData, type) => {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
|
|
let singlehotFloorTitile = [];
|
|
|
|
|
|
const bigFloorLength = 5;
|
|
|
const normalFloorLength = 3;
|
|
|
const hotCategoryLength = 2;
|
|
|
|
|
|
|
|
|
_.forEach(rawData, (data, index) => {
|
|
|
let floorData = null;
|
|
|
|
|
|
if (data.template_name === 'recommend_content_three') {
|
|
|
if (data.template_name === 'recommend_content_three' ||
|
|
|
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
|
|
|
floorData = floorMap.slide.call(null, data.data);
|
|
|
} else if (data.template_intro === '热门品类') {
|
|
|
floorData = floorMap.hot.call(null, rawData.slice(index, index + 2));
|
|
|
} else if (data.data.text) {
|
|
|
floorData = floorMap[data.data.text] &&
|
|
|
floorMap[data.data.text].call(null, rawData.slice(index + 1, index + 5));
|
|
|
} else if (data.template_intro === '热门品类') { // 处理热门品类
|
|
|
floorData = floorMap.hot.call(null, rawData.slice(index, index + hotCategoryLength), type);
|
|
|
} else if (data.data.text) { // 处理一般楼层
|
|
|
let text = getText(data.data.text);
|
|
|
let lastIndex = index + bigFloorLength < rawData.length ?
|
|
|
index + bigFloorLength : index + (rawData.length - index - 1);
|
|
|
|
|
|
|
|
|
floorData = floorMap[text] &&
|
|
|
floorMap[text].call(null, rawData.slice(index, lastIndex), type);
|
|
|
|
|
|
} else if (data.template_name === 'debrisSlider') { // 处理girls的banner
|
|
|
floorData = floorMap.debrisSlide.call(null, data.data);
|
|
|
}
|
|
|
|
|
|
if (!_.isNil(floorData)) {
|
|
|
// 处理lifestyle分类楼层
|
|
|
if (!floorData && index + normalFloorLength < rawData.length &&
|
|
|
rawData[index + 1].template_name === 'textNav' &&
|
|
|
rawData[index + 2].template_name === 'floor') {
|
|
|
floorData = floorMap.category.call(null, rawData.slice(index, index + normalFloorLength));
|
|
|
}
|
|
|
|
|
|
// 处理手风琴楼层
|
|
|
if (!floorData && index + normalFloorLength < rawData.length &&
|
|
|
rawData[index + 1].template_name === 'textNav' &&
|
|
|
rawData[index + 2].template_name === 'focus') {
|
|
|
floorData = floorMap.accordion.call(null, rawData.slice(index, index + normalFloorLength));
|
|
|
}
|
|
|
|
|
|
|
|
|
// 处理promise
|
|
|
if (floorData && floorData.then && typeof floorData.then === 'function') {
|
|
|
searchPromise.push(floorData);
|
|
|
|
|
|
// 记住楼层位置, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorIndex.push(floorList.length);
|
|
|
|
|
|
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorTitile.push(getText(data.data.text));
|
|
|
} else if (!_.isNil(floorData)) {
|
|
|
_.isArray(floorData) ?
|
|
|
floorList = floorList.concat(floorData) :
|
|
|
floorList.push(floorData);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return floorList;
|
|
|
return {
|
|
|
floors: floorList,
|
|
|
promise: _.reverse(searchPromise),
|
|
|
singlehotFloorTitile: _.reverse(singlehotFloorTitile),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
|
|
};
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取频道页数据
|
|
|
* @param {string} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {object}
|
|
|
*/
|
|
|
exports.getContent = type => {
|
|
|
return Promise.all([headerModel.requestHeaderData(), requestContent(type)]).then(res => {
|
|
|
return Promise.all([headerModel.requestHeaderData(type), requestContent(type)]).then(res => {
|
|
|
|
|
|
let headerData = res[0].data || res[0],
|
|
|
contentData = res[1].data ? res[1].data.list : res[1];
|
|
|
|
|
|
let data = {};
|
|
|
|
|
|
const processResult = processFloorData(contentData, type);
|
|
|
|
|
|
data = headerData;
|
|
|
data.module = 'channel';
|
|
|
data.page = 'channel';
|
|
|
data.pageType = type;
|
|
|
data.footerTop = true;
|
|
|
data.channel = processResult.floors;
|
|
|
|
|
|
|
|
|
if (res[0].code === 200 && res[1].code === 200) {
|
|
|
let headerData = res[0].data,
|
|
|
contentData = res[1].data.list;
|
|
|
return {
|
|
|
rawData: contentData,
|
|
|
floorData: data,
|
|
|
searchPromise: processResult.promise,
|
|
|
singlehotFloorIndex: processResult.singlehotFloorIndex,
|
|
|
singlehotFloorTitile: processResult.singlehotFloorTitile,
|
|
|
channelType: type
|
|
|
};
|
|
|
|
|
|
let data = {};
|
|
|
}).then(result => {
|
|
|
|
|
|
data = headerModel.setHeaderData(headerData, type);
|
|
|
data.module = 'channel';
|
|
|
data.page = type;
|
|
|
data.footerTop = true;
|
|
|
data.channel = processFloorData(contentData);
|
|
|
// 如果有promise则做相应处理
|
|
|
if (result.searchPromise.length) {
|
|
|
return Promise.all(result.searchPromise).then(res => {
|
|
|
_.forEach(res, (data, index) => {
|
|
|
result.floorData.channel
|
|
|
.splice(result.singlehotFloorIndex[index], 0,
|
|
|
processFloorDataWithQueryReusult(result.rawData,
|
|
|
result.floorData, data, result.singlehotFloorTitile[index], result.channelType));
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
return result.floorData;
|
|
|
});
|
|
|
} else {
|
|
|
return result.floorData || result;
|
|
|
}
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -367,26 +949,28 @@ exports.getContent = type => { |
|
|
// 优选品牌楼层floorData-ajax
|
|
|
exports.getbrandFloorDataAjax = type => {
|
|
|
return requestContent(type).then(res => {
|
|
|
if (res.code === 200) {
|
|
|
let contentData = res.data.list;
|
|
|
let contentData = res.data ? res.data.list : [];
|
|
|
|
|
|
let data = {
|
|
|
logoBrand: [],
|
|
|
moreBrand: ''
|
|
|
};
|
|
|
let data = {
|
|
|
logoBrand: [],
|
|
|
moreBrand: ''
|
|
|
};
|
|
|
|
|
|
_.forEach(contentData[6].data, (floorData) => {
|
|
|
let o = {};
|
|
|
_.forEach(contentData, (d, index) => {
|
|
|
if (d.data.text && d.data.text.indexOf('优选品牌') >= 0) {
|
|
|
_.forEach(contentData[index + 2].data, (floorData) => {
|
|
|
let o = {};
|
|
|
|
|
|
o.href = floorData.url;
|
|
|
o.img = helpers.image(floorData.src, 185, 86, 2);
|
|
|
o.href = floorData.url;
|
|
|
o.img = helpers.image(floorData.src, 185, 86, 2);
|
|
|
|
|
|
data.logoBrand.push(o);
|
|
|
});
|
|
|
data.logoBrand.push(o);
|
|
|
});
|
|
|
|
|
|
data.moreBrand = contentData[7].data[0].url;
|
|
|
data.moreBrand = contentData[index + 3].data[0].url;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
}
|
|
|
return data;
|
|
|
});
|
|
|
}; |
...
|
...
|
|