...
|
...
|
@@ -13,1332 +13,1338 @@ const helpers = global.yoho.helpers; |
|
|
const config = global.yoho.config;
|
|
|
|
|
|
const processProduct = require(`${global.utils}/product-process`).processProduct;
|
|
|
const searchApi = require('./search-api');
|
|
|
|
|
|
|
|
|
const api = global.yoho.API;
|
|
|
const serviceApi = global.yoho.ServiceAPI;
|
|
|
|
|
|
const SearchApi = require('./search-api');
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
|
|
|
// 获取可用的标题
|
|
|
const _getText = data => {
|
|
|
let text = data.split(' ')[0];
|
|
|
const regResult = /\w+/.exec(text);
|
|
|
const titleWithoutChinese = /^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$/;
|
|
|
|
|
|
// 对于不含中文的标题,直接返回
|
|
|
if (titleWithoutChinese.test(data)) {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
if (regResult) {
|
|
|
|
|
|
// 去掉标题中的英文部分
|
|
|
text = text.replace(regResult[0], '');
|
|
|
}
|
|
|
|
|
|
return text;
|
|
|
const needQuery = {
|
|
|
'GIRL KIDS': true,
|
|
|
'BOY KIDS': true,
|
|
|
人气单品: true,
|
|
|
ACCESSORIES: true
|
|
|
};
|
|
|
|
|
|
const channelMap = dataMap.channel;
|
|
|
|
|
|
const sortMap = dataMap.sort;
|
|
|
|
|
|
/**
|
|
|
* 新人专享
|
|
|
* @param {[Object]} data 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
const _getNewUserFloorData = data => {
|
|
|
let floorData = {
|
|
|
newUserFloor: {
|
|
|
name: _getText(data.title.name),
|
|
|
navs: {},
|
|
|
bannerImage: {
|
|
|
url: data.banner_image[0].url,
|
|
|
src: helpers.image(data.banner_image[0].src, 1150, 368),
|
|
|
title: data.banner_image[0].title
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (data.title.more_name) {
|
|
|
floorData.newUserFloor.navs.name = data.title.more_name;
|
|
|
}
|
|
|
if (data.title.more_url) {
|
|
|
floorData.newUserFloor.navs.url = data.title.more_url;
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
|
|
|
this.searchApi = new SearchApi(ctx);
|
|
|
|
|
|
this.floorMap = {
|
|
|
slide: this._getSlideData.bind(this),
|
|
|
hot: this._getHotGoodsFloorData.bind(this),
|
|
|
最新速报: this._getNewReportFloorData.bind(this),
|
|
|
人气单品: this._getSingleHotFloorData.bind(this),
|
|
|
'GIRL KIDS': this._getSingleHotFloorData.bind(this),
|
|
|
'BOY KIDS': this._getSingleHotFloorData.bind(this),
|
|
|
ACCESSORIES: this._getSingleHotFloorData.bind(this),
|
|
|
优选品牌: this._getPreBrandTopData.bind(this),
|
|
|
最新上架: this._getNewGoodsFloorData.bind(this),
|
|
|
ad: this._getadbannerData.bind(this),
|
|
|
category: this._getCategoryFloorData.bind(this),
|
|
|
accordion: this._getAccordionFloorData.bind(this),
|
|
|
debrisSlide: this._getDebrisSlide.bind(this),
|
|
|
jacket: this._getJacketData.bind(this),
|
|
|
sevenCategory: this._getClothesCategory.bind(this),
|
|
|
floorTitle: this._getFloorTitleData.bind(this),
|
|
|
newuser: this._getNewUserFloorData.bind(this)
|
|
|
};
|
|
|
}
|
|
|
if (data.list) {
|
|
|
let proList = [];
|
|
|
|
|
|
// 大于15就取前15个产品数
|
|
|
proList = data.list.length > 15 ? data.list.slice(0, 15) : data.list;
|
|
|
|
|
|
// 5个以内为false
|
|
|
floorData.newUserFloor.hasSwitch = proList.length > 5 ? true : false;
|
|
|
|
|
|
_.forEach(proList, value => {
|
|
|
value.thumb = helpers.image(value.goods_list[0].images_url, 185, 247);
|
|
|
value.for_newuser = true;
|
|
|
value.url = helpers.getUrlBySkc(value.product_skn);
|
|
|
});
|
|
|
floorData.newUserFloor.list = proList;
|
|
|
}
|
|
|
// 获取可用的标题
|
|
|
_getText(data) {
|
|
|
let text = data.split(' ')[0];
|
|
|
const regResult = /\w+/.exec(text);
|
|
|
const titleWithoutChinese = /^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$/;
|
|
|
|
|
|
// 对于不含中文的标题,直接返回
|
|
|
if (titleWithoutChinese.test(data)) {
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
return floorData;
|
|
|
};
|
|
|
if (regResult) {
|
|
|
|
|
|
/**
|
|
|
* 获取带小图的banner
|
|
|
* @param {[Object]} data 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
const _getDebrisSlide = data => {
|
|
|
let floorData = {
|
|
|
debrisSlider: {
|
|
|
left: [],
|
|
|
center: [],
|
|
|
right: []
|
|
|
// 去掉标题中的英文部分
|
|
|
text = text.replace(regResult[0], '');
|
|
|
}
|
|
|
};
|
|
|
|
|
|
_.mapKeys(data, (value, key) => {
|
|
|
_.forEach(value, slideData => {
|
|
|
floorData.debrisSlider[key].push(slideData);
|
|
|
});
|
|
|
});
|
|
|
return text;
|
|
|
}
|
|
|
|
|
|
return floorData;
|
|
|
};
|
|
|
/**
|
|
|
* 新人专享
|
|
|
* @param {[Object]} data 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
_getNewUserFloorData(data) {
|
|
|
let floorData = {
|
|
|
newUserFloor: {
|
|
|
name: this._getText(data.title.name),
|
|
|
navs: {},
|
|
|
bannerImage: {
|
|
|
url: data.banner_image[0].url,
|
|
|
src: helpers.image(data.banner_image[0].src, 1150, 368),
|
|
|
title: data.banner_image[0].title
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (data.title.more_name) {
|
|
|
floorData.newUserFloor.navs.name = data.title.more_name;
|
|
|
}
|
|
|
if (data.title.more_url) {
|
|
|
floorData.newUserFloor.navs.url = data.title.more_url;
|
|
|
}
|
|
|
if (data.list) {
|
|
|
let proList = [];
|
|
|
|
|
|
/**
|
|
|
* 获取广告位
|
|
|
* @param {Object} data 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
const _getadbannerData = data => {
|
|
|
// 大于15就取前15个产品数
|
|
|
proList = data.list.length > 15 ? data.list.slice(0, 15) : data.list;
|
|
|
|
|
|
return {
|
|
|
adbanner: data
|
|
|
};
|
|
|
};
|
|
|
// 5个以内为false
|
|
|
floorData.newUserFloor.hasSwitch = proList.length > 5 ? true : false;
|
|
|
|
|
|
/**
|
|
|
* 生成banner模板数据
|
|
|
* @param {Object} srcData 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
const _getSlideData = srcData => {
|
|
|
const slideData = {
|
|
|
slide: {
|
|
|
list: [],
|
|
|
pagination: []
|
|
|
_.forEach(proList, value => {
|
|
|
value.thumb = helpers.image(value.goods_list[0].images_url, 185, 247);
|
|
|
value.for_newuser = true;
|
|
|
value.url = helpers.getUrlBySkc(value.product_skn);
|
|
|
});
|
|
|
floorData.newUserFloor.list = proList;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (srcData.big_image) {
|
|
|
slideData.slide.list = srcData.big_image;
|
|
|
return floorData;
|
|
|
}
|
|
|
|
|
|
if (srcData.list) {
|
|
|
slideData.slide.pagination = srcData.list;
|
|
|
}
|
|
|
/**
|
|
|
* 获取带小图的banner
|
|
|
* @param {[Object]} data 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
_getDebrisSlide(data) {
|
|
|
let floorData = {
|
|
|
debrisSlider: {
|
|
|
left: [],
|
|
|
center: [],
|
|
|
right: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (_.isArray(srcData)) {
|
|
|
slideData.slide.list = srcData;
|
|
|
_.mapKeys(data, (value, key) => {
|
|
|
_.forEach(value, slideData => {
|
|
|
floorData.debrisSlider[key].push(slideData);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return floorData;
|
|
|
}
|
|
|
|
|
|
return slideData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取品牌列表数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getBrandLogosData = (args, showNum) => {
|
|
|
let items = [],
|
|
|
brandLogos = [],
|
|
|
i = 0,
|
|
|
fillNum = 0;
|
|
|
|
|
|
// 品牌数据
|
|
|
_.forEach(args, (floorData) => {
|
|
|
items.push({
|
|
|
href: floorData.url,
|
|
|
img: helpers.image(floorData.src, 185, 86, 2)
|
|
|
});
|
|
|
});
|
|
|
/**
|
|
|
* 获取广告位
|
|
|
* @param {Object} data 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
_getadbannerData(data) {
|
|
|
|
|
|
// 不是每页显示个数的倍数,填充数据
|
|
|
if (items.length % showNum !== 0) {
|
|
|
fillNum = showNum - (items.length % showNum);
|
|
|
for (i = 0; i < fillNum; i++) {
|
|
|
items.push({
|
|
|
href: 'javascript:;', // eslint-disable-line
|
|
|
img: ''
|
|
|
});
|
|
|
}
|
|
|
return {
|
|
|
adbanner: data
|
|
|
};
|
|
|
}
|
|
|
|
|
|
for (i = 0; i < items.length; i++) {
|
|
|
let item = items[i];
|
|
|
|
|
|
let brandLogo = {
|
|
|
pageNum: Math.floor(i / showNum),
|
|
|
href: item.href,
|
|
|
img: item.img
|
|
|
/**
|
|
|
* 生成banner模板数据
|
|
|
* @param {Object} srcData 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
_getSlideData(srcData) {
|
|
|
const slideData = {
|
|
|
slide: {
|
|
|
list: [],
|
|
|
pagination: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (i % showNum === 5 || i === 5) {
|
|
|
if (srcData.big_image) {
|
|
|
slideData.slide.list = srcData.big_image;
|
|
|
}
|
|
|
|
|
|
// 插入切换按钮的位置
|
|
|
brandLogo.isSwitch = true;
|
|
|
} else if (i !== 0 && i % showNum === 0) {
|
|
|
if (srcData.list) {
|
|
|
slideData.slide.pagination = srcData.list;
|
|
|
}
|
|
|
|
|
|
// 插入more的位置,more占的是下一页第一个brand的位置,所以page是i/17
|
|
|
brandLogo.morePageNum = Math.floor(i / (showNum + 1));
|
|
|
brandLogo.isMore = true;
|
|
|
brandLogo.hasNext = true;
|
|
|
} else {
|
|
|
brandLogo.isBrand = true;
|
|
|
if (_.isArray(srcData)) {
|
|
|
slideData.slide.list = srcData;
|
|
|
}
|
|
|
|
|
|
brandLogos.push(brandLogo);
|
|
|
return slideData;
|
|
|
}
|
|
|
brandLogos.push({
|
|
|
morePageNum: Math.floor(i / (showNum + 1)),
|
|
|
isMore: true
|
|
|
});
|
|
|
return brandLogos;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取最新速报模板数据 : 大图+小图+大图+single_image(广告位)/+floor(logo列表)
|
|
|
* @param {Object} srcData 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
const _getNewReportFloorData = (args) => {
|
|
|
const title = args[0].data.text;
|
|
|
let floorId = args[0].template_id;
|
|
|
let item = args[1].data;
|
|
|
let secondItem = args[2].data;
|
|
|
let thirdItem = args[3].data;
|
|
|
let forthItem = args[4] || {};
|
|
|
let brandLogoObj = {showNum: 10};
|
|
|
|
|
|
let list = [];
|
|
|
|
|
|
const data = {
|
|
|
newReport: {
|
|
|
name: title,
|
|
|
floorId: floorId,
|
|
|
list: []
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
|
* 获取品牌列表数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getBrandLogosData(args, showNum) {
|
|
|
let items = [],
|
|
|
brandLogos = [],
|
|
|
i = 0,
|
|
|
fillNum = 0;
|
|
|
|
|
|
// 品牌数据
|
|
|
_.forEach(args, (floorData) => {
|
|
|
items.push({
|
|
|
href: floorData.url,
|
|
|
img: helpers.image(floorData.src, 185, 86, 2)
|
|
|
});
|
|
|
});
|
|
|
|
|
|
let adData;
|
|
|
let floorDatas = [];
|
|
|
|
|
|
list.push(item[0]);
|
|
|
// 不是每页显示个数的倍数,填充数据
|
|
|
if (items.length % showNum !== 0) {
|
|
|
fillNum = showNum - (items.length % showNum);
|
|
|
for (i = 0; i < fillNum; i++) {
|
|
|
items.push({
|
|
|
href: 'javascript:;', // eslint-disable-line
|
|
|
img: ''
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
_.forEach(secondItem, (floorData) => {
|
|
|
list.push(floorData);
|
|
|
});
|
|
|
for (i = 0; i < items.length; i++) {
|
|
|
let item = items[i];
|
|
|
|
|
|
list.push(thirdItem[0]);
|
|
|
let brandLogo = {
|
|
|
pageNum: Math.floor(i / showNum),
|
|
|
href: item.href,
|
|
|
img: item.img
|
|
|
};
|
|
|
|
|
|
data.newReport.list = list;
|
|
|
if (i % showNum === 5 || i === 5) {
|
|
|
|
|
|
floorDatas.push(data);
|
|
|
// 插入切换按钮的位置
|
|
|
brandLogo.isSwitch = true;
|
|
|
} else if (i !== 0 && i % showNum === 0) {
|
|
|
|
|
|
// 广告位
|
|
|
if (forthItem.template_name && forthItem.template_name === 'single_image') {
|
|
|
adData = _getadbannerData(forthItem.data[0]);
|
|
|
floorDatas.push(adData);
|
|
|
}
|
|
|
// 插入more的位置,more占的是下一页第一个brand的位置,所以page是i/17
|
|
|
brandLogo.morePageNum = Math.floor(i / (showNum + 1));
|
|
|
brandLogo.isMore = true;
|
|
|
brandLogo.hasNext = true;
|
|
|
} else {
|
|
|
brandLogo.isBrand = true;
|
|
|
}
|
|
|
|
|
|
// logo列表
|
|
|
if (forthItem.template_name && forthItem.template_name === 'floor') {
|
|
|
// 品牌数据
|
|
|
if (_.get(args[5], 'data[0].url', '')) {
|
|
|
brandLogoObj.moreBrand = args[5].data[0].url || '';
|
|
|
brandLogos.push(brandLogo);
|
|
|
}
|
|
|
|
|
|
brandLogoObj.brandLogos = _getBrandLogosData(forthItem.data, brandLogoObj.showNum);
|
|
|
data.newReport.brandLogoObj = brandLogoObj;
|
|
|
brandLogos.push({
|
|
|
morePageNum: Math.floor(i / (showNum + 1)),
|
|
|
isMore: true
|
|
|
});
|
|
|
return brandLogos;
|
|
|
}
|
|
|
return floorDatas;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取最新速报模板数据 : 大图+小图+大图+single_image(广告位)/+floor(logo列表)
|
|
|
* @param {Object} srcData 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
_getNewReportFloorData(args) {
|
|
|
const title = args[0].data.text;
|
|
|
let floorId = args[0].template_id;
|
|
|
let item = args[1].data;
|
|
|
let secondItem = args[2].data;
|
|
|
let thirdItem = args[3].data;
|
|
|
let forthItem = args[4] || {};
|
|
|
let brandLogoObj = {showNum: 10};
|
|
|
|
|
|
let list = [];
|
|
|
|
|
|
const data = {
|
|
|
newReport: {
|
|
|
name: title,
|
|
|
floorId: floorId,
|
|
|
list: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 给目标对象绑定频道属性
|
|
|
* @param {Object} obj 需要绑定频道属性的对象
|
|
|
* @param {String} type 需要设置的频道类型
|
|
|
* @return undefined
|
|
|
*/
|
|
|
const _setChannelType = (obj, type) => {
|
|
|
obj[type + 'Channel'] = true;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取优选品牌模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getPreBrandTopData = (args, type) => {
|
|
|
const title = args[0].data.text;
|
|
|
let item = args[1].data,
|
|
|
logoItems = args[2] || {},
|
|
|
showNum = type === 'boys' ? 16 : 10;
|
|
|
let adData;
|
|
|
let floorDatas = [];
|
|
|
|
|
|
list.push(item[0]);
|
|
|
|
|
|
let brandLogoObj = {showNum: showNum};
|
|
|
_.forEach(secondItem, (floorData) => {
|
|
|
list.push(floorData);
|
|
|
});
|
|
|
|
|
|
const data = {
|
|
|
preferenceBrands: {
|
|
|
name: title,
|
|
|
imgBrand: []
|
|
|
}
|
|
|
};
|
|
|
list.push(thirdItem[0]);
|
|
|
|
|
|
// logo列表
|
|
|
if (logoItems) {
|
|
|
// 品牌数据
|
|
|
if (_.get(args[3], 'data[0].url', '')) {
|
|
|
brandLogoObj.moreBrand = args[3].data[0].url;
|
|
|
}
|
|
|
brandLogoObj.brandLogos = _getBrandLogosData(args[2].data, showNum);
|
|
|
data.preferenceBrands.brandLogoObj = brandLogoObj;
|
|
|
}
|
|
|
data.preferenceBrands.imgBrand = item;
|
|
|
if (type === 'kids') {
|
|
|
data.preferenceBrands.sliderColor = '#7AD3F8';
|
|
|
}
|
|
|
_setChannelType(data.preferenceBrands, type);
|
|
|
data.newReport.list = list;
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
floorDatas.push(data);
|
|
|
|
|
|
/**
|
|
|
* 获取热门分类模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getHotGoodsFloorData = (args, type) => {
|
|
|
let item = args[0];
|
|
|
let nextItem = args[1];
|
|
|
|
|
|
let list = [];
|
|
|
|
|
|
let object = {},
|
|
|
keyword = [],
|
|
|
category = [],
|
|
|
brands = [],
|
|
|
types = [],
|
|
|
products = [];
|
|
|
|
|
|
const data = {
|
|
|
recommend: {
|
|
|
tplrecommend: []
|
|
|
// 广告位
|
|
|
if (forthItem.template_name && forthItem.template_name === 'single_image') {
|
|
|
adData = this._getadbannerData(forthItem.data[0]);
|
|
|
floorDatas.push(adData);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
category = item.data.menuNav.list;
|
|
|
|
|
|
keyword = item.data.menuNav.blocks;
|
|
|
|
|
|
_.forEach(item.data.imgs, (it, idx) => {
|
|
|
// logo列表
|
|
|
if (forthItem.template_name && forthItem.template_name === 'floor') {
|
|
|
// 品牌数据
|
|
|
if (_.get(args[5], 'data[0].url', '')) {
|
|
|
brandLogoObj.moreBrand = args[5].data[0].url || '';
|
|
|
}
|
|
|
|
|
|
if (idx === 0 || (idx === 4 && type === 'boys')) {
|
|
|
brands.push(it);
|
|
|
} else {
|
|
|
types.push(it);
|
|
|
brandLogoObj.brandLogos = this._getBrandLogosData(forthItem.data, brandLogoObj.showNum);
|
|
|
data.newReport.brandLogoObj = brandLogoObj;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
products = nextItem.data;
|
|
|
|
|
|
object.name = item.data.name;
|
|
|
object.keyword = keyword;
|
|
|
object.category = category;
|
|
|
object.brands = brands;
|
|
|
object.types = types;
|
|
|
object.navs = item.data.navs.list;
|
|
|
object.products = products;
|
|
|
list.push(object);
|
|
|
data.recommend.tplrecommend = list;
|
|
|
|
|
|
_setChannelType(data.recommend, type);
|
|
|
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
return floorDatas;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取japanKorean潮流上装Jacket,title+左大图+右6小图模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getJacketData = (arg) => {
|
|
|
let resData = {
|
|
|
tpltopic: {
|
|
|
bigPic: arg.big_image[0],
|
|
|
types: arg.list
|
|
|
}
|
|
|
};
|
|
|
|
|
|
if (arg.title.title !== '') {
|
|
|
resData.tpltopic.title = arg.title;
|
|
|
/**
|
|
|
* 给目标对象绑定频道属性
|
|
|
* @param {Object} obj 需要绑定频道属性的对象
|
|
|
* @param {String} type 需要设置的频道类型
|
|
|
* @return undefined
|
|
|
*/
|
|
|
_setChannelType(obj, type) {
|
|
|
obj[type + 'Channel'] = true;
|
|
|
}
|
|
|
|
|
|
return resData;
|
|
|
};
|
|
|
/**
|
|
|
* 获取优选品牌模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getPreBrandTopData(args, type) {
|
|
|
const title = args[0].data.text;
|
|
|
let item = args[1].data,
|
|
|
logoItems = args[2] || {},
|
|
|
showNum = type === 'boys' ? 16 : 10;
|
|
|
|
|
|
|
|
|
let brandLogoObj = {showNum: showNum};
|
|
|
|
|
|
const data = {
|
|
|
preferenceBrands: {
|
|
|
name: title,
|
|
|
imgBrand: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取7个品类图
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getClothesCategory = (arg) => {
|
|
|
return {
|
|
|
sevenCategory: {
|
|
|
categorys: arg.list
|
|
|
// logo列表
|
|
|
if (logoItems) {
|
|
|
// 品牌数据
|
|
|
if (_.get(args[3], 'data[0].url', '')) {
|
|
|
brandLogoObj.moreBrand = args[3].data[0].url;
|
|
|
}
|
|
|
brandLogoObj.brandLogos = this._getBrandLogosData(args[2].data, showNum);
|
|
|
data.preferenceBrands.brandLogoObj = brandLogoObj;
|
|
|
}
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取boys人气单品模版数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getBoysSingleHot = (args, type) => {
|
|
|
const len = 10;
|
|
|
const data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
|
|
imgHot: []
|
|
|
data.preferenceBrands.imgBrand = item;
|
|
|
if (type === 'kids') {
|
|
|
data.preferenceBrands.sliderColor = '#7AD3F8';
|
|
|
}
|
|
|
};
|
|
|
this._setChannelType(data.preferenceBrands, type);
|
|
|
|
|
|
let list = [];
|
|
|
let adData;
|
|
|
let floorDatas = [];
|
|
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
let pos = i;
|
|
|
let val = {};
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
if (i === 1) {
|
|
|
val = args[1].data[0]; // 第二个是大图
|
|
|
} else if (i === len - 1) {
|
|
|
val = args[1].data[1]; // 最后一个是大图
|
|
|
} else {
|
|
|
if (pos > 1) { // 小图
|
|
|
pos = pos - 1;
|
|
|
/**
|
|
|
* 获取热门分类模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getHotGoodsFloorData(args, type) {
|
|
|
let item = args[0];
|
|
|
let nextItem = args[1];
|
|
|
|
|
|
let list = [];
|
|
|
|
|
|
let object = {},
|
|
|
keyword = [],
|
|
|
category = [],
|
|
|
brands = [],
|
|
|
types = [],
|
|
|
products = [];
|
|
|
|
|
|
const data = {
|
|
|
recommend: {
|
|
|
tplrecommend: []
|
|
|
}
|
|
|
val = args[2].data[pos];
|
|
|
}
|
|
|
list.push(val);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
_.forEach(list, (item, index) => {
|
|
|
if (index === 1 || index === list.length - 1) {
|
|
|
item.big = true;
|
|
|
}
|
|
|
});
|
|
|
category = item.data.menuNav.list;
|
|
|
|
|
|
data.singlehot.imgHot = list;
|
|
|
_setChannelType(data.singlehot, type);
|
|
|
floorDatas.push(data);
|
|
|
keyword = item.data.menuNav.blocks;
|
|
|
|
|
|
if (args[3].template_name === 'single_image') {
|
|
|
adData = _getadbannerData(args[3].data[0]);
|
|
|
floorDatas.push(adData);
|
|
|
}
|
|
|
_.forEach(item.data.imgs, (it, idx) => {
|
|
|
|
|
|
return floorDatas;
|
|
|
};
|
|
|
if (idx === 0 || (idx === 4 && type === 'boys')) {
|
|
|
brands.push(it);
|
|
|
} else {
|
|
|
types.push(it);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
* 获取girls人气单品模版数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getGirlsSingleHot = (args, type) => {
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
products = nextItem.data;
|
|
|
|
|
|
if (goods) {
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
});
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
object.name = item.data.name;
|
|
|
object.keyword = keyword;
|
|
|
object.category = category;
|
|
|
object.brands = brands;
|
|
|
object.types = types;
|
|
|
object.navs = item.data.navs.list;
|
|
|
object.products = products;
|
|
|
list.push(object);
|
|
|
data.recommend.tplrecommend = list;
|
|
|
|
|
|
return searchApi.getProductList({
|
|
|
client_type: 'web',
|
|
|
query: skns,
|
|
|
order: 'shelve_time:desc',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
|
|
attribute_not: '2',
|
|
|
stocknumber: 1,
|
|
|
page: 1,
|
|
|
gender: channelMap[type].gender,
|
|
|
limit: 60
|
|
|
}, config.apiCache);
|
|
|
};
|
|
|
this._setChannelType(data.recommend, type);
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 人气单品入口
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getSingleHotFloorData = (args, type) => {
|
|
|
if (type === 'boys') {
|
|
|
return _getBoysSingleHot(args, type);
|
|
|
} else {
|
|
|
return _getGirlsSingleHot(args, type);
|
|
|
return data;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 组装最新上架楼层数据
|
|
|
*
|
|
|
* @param string data
|
|
|
* return obj
|
|
|
*/
|
|
|
const _getNewGoodsFloorData = args => {
|
|
|
const data = {};
|
|
|
|
|
|
if (!_.isEmpty(args)) {
|
|
|
data.newArrivls = {
|
|
|
floorId: args[0].template_id,
|
|
|
name: _.replace(args[0].data.text, '最新', '新品'),
|
|
|
navs: []
|
|
|
/**
|
|
|
* 获取japanKorean潮流上装Jacket,title+左大图+右6小图模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getJacketData(arg) {
|
|
|
let resData = {
|
|
|
tpltopic: {
|
|
|
bigPic: arg.big_image[0],
|
|
|
types: arg.list
|
|
|
}
|
|
|
};
|
|
|
|
|
|
data.newArrivls.navs = args[1] ? args[1].data : {};
|
|
|
}
|
|
|
return data;
|
|
|
};
|
|
|
if (arg.title.title !== '') {
|
|
|
resData.tpltopic.title = arg.title;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 文本标题
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getFloorTitleData = (args) => {
|
|
|
let resData = {
|
|
|
floorHeader: {}
|
|
|
};
|
|
|
|
|
|
if (args instanceof Array) {
|
|
|
resData.floorHeader.name = args[0].data.text;
|
|
|
resData.floorHeader.navs = args[1].data;
|
|
|
resData.floorHeader.floorId = args[0].template_id;
|
|
|
} else {
|
|
|
resData.floorHeader.name = args.data.text;
|
|
|
resData.floorHeader.floorId = args.template_id;
|
|
|
return resData;
|
|
|
}
|
|
|
|
|
|
if (resData.floorHeader.name.indexOf('最新上架') >= 0) {
|
|
|
resData = _getNewGoodsFloorData(args);
|
|
|
/**
|
|
|
* 获取7个品类图
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getClothesCategory(arg) {
|
|
|
return {
|
|
|
sevenCategory: {
|
|
|
categorys: arg.list
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
return resData;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 处理异步获取的人气单品数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} originQuery 原始skns
|
|
|
* @param {Object} queryResult 异步获取的数据
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getSingehotViaResult = (args, originQuery, queryResult, type) => {
|
|
|
let data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
|
|
navs: [],
|
|
|
imgHot: [],
|
|
|
brands: []
|
|
|
}
|
|
|
};
|
|
|
/**
|
|
|
* 获取boys人气单品模版数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getBoysSingleHot(args, type) {
|
|
|
const len = 10;
|
|
|
const data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
|
|
imgHot: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
let pos = 0;
|
|
|
let list = [];
|
|
|
let adData;
|
|
|
let floorDatas = [];
|
|
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
let pos = i;
|
|
|
let val = {};
|
|
|
|
|
|
if (i === 1) {
|
|
|
val = args[1].data[0]; // 第二个是大图
|
|
|
} else if (i === len - 1) {
|
|
|
val = args[1].data[1]; // 最后一个是大图
|
|
|
} else {
|
|
|
if (pos > 1) { // 小图
|
|
|
pos = pos - 1;
|
|
|
}
|
|
|
val = args[2].data[pos];
|
|
|
}
|
|
|
list.push(val);
|
|
|
}
|
|
|
|
|
|
_.forEach(list, (item, index) => {
|
|
|
if (index === 1 || index === list.length - 1) {
|
|
|
item.big = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
const getIndex = skn => {
|
|
|
let index;
|
|
|
data.singlehot.imgHot = list;
|
|
|
this._setChannelType(data.singlehot, type);
|
|
|
floorDatas.push(data);
|
|
|
|
|
|
if (args[3].template_name === 'single_image') {
|
|
|
adData = this._getadbannerData(args[3].data[0]);
|
|
|
floorDatas.push(adData);
|
|
|
}
|
|
|
|
|
|
if (originQuery) {
|
|
|
const originQueryArr = originQuery.split(' ');
|
|
|
let setFlag = false;
|
|
|
return floorDatas;
|
|
|
}
|
|
|
|
|
|
_.forEach(originQueryArr, (query, idx) => {
|
|
|
if (!setFlag && query.toString() === skn.toString()) {
|
|
|
index = idx;
|
|
|
setFlag = true;
|
|
|
}
|
|
|
/**
|
|
|
* 获取girls人气单品模版数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getGirlsSingleHot(args, type) {
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
|
|
|
if (goods) {
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
});
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
return index;
|
|
|
};
|
|
|
|
|
|
if (args[3].template_name === 'app_icon_list') {
|
|
|
data.singlehot.brands = args[3].data;
|
|
|
return this.searchApi.getProductList({
|
|
|
client_type: 'web',
|
|
|
query: skns,
|
|
|
order: 'shelve_time:desc',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
|
|
attribute_not: '2',
|
|
|
stocknumber: 1,
|
|
|
page: 1,
|
|
|
gender: channelMap[type].gender,
|
|
|
limit: 60
|
|
|
}, config.apiCache);
|
|
|
}
|
|
|
|
|
|
if (queryResult.data) {
|
|
|
_.forEach(queryResult.data.product_list || [], it => {
|
|
|
const formatData = processProduct(it, {
|
|
|
width: 280,
|
|
|
height: 373,
|
|
|
gender: channelMap[type].gender
|
|
|
});
|
|
|
|
|
|
if (pos > 11) {
|
|
|
return;
|
|
|
}
|
|
|
/**
|
|
|
* 人气单品入口
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getSingleHotFloorData(args, type) {
|
|
|
if (type === 'boys') {
|
|
|
return this._getBoysSingleHot(args, type);
|
|
|
} else {
|
|
|
return this._getGirlsSingleHot(args, type);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (it.product_id) {
|
|
|
formatData.idx = getIndex(it.product_skn);
|
|
|
if (formatData.idx === 0 || formatData.idx) {
|
|
|
data.singlehot.imgHot.push(formatData);
|
|
|
pos += 1;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
/**
|
|
|
* 组装最新上架楼层数据
|
|
|
*
|
|
|
* @param string data
|
|
|
* return obj
|
|
|
*/
|
|
|
_getNewGoodsFloorData(args) {
|
|
|
const data = {};
|
|
|
|
|
|
if (!_.isEmpty(args)) {
|
|
|
data.newArrivls = {
|
|
|
floorId: args[0].template_id,
|
|
|
name: _.replace(args[0].data.text, '最新', '新品'),
|
|
|
navs: []
|
|
|
};
|
|
|
|
|
|
data.newArrivls.navs = args[1] ? args[1].data : {};
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
data.singlehot.imgHot = _.sortBy(data.singlehot.imgHot, item => {
|
|
|
return item.idx;
|
|
|
});
|
|
|
/**
|
|
|
* 文本标题
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getFloorTitleData(args) {
|
|
|
let resData = {
|
|
|
floorHeader: {}
|
|
|
};
|
|
|
|
|
|
pos = 1;
|
|
|
_.forEach(data.singlehot.imgHot, item => {
|
|
|
if (pos < 4 && item) {
|
|
|
item.tip = 'TOP' + pos;
|
|
|
pos += 1;
|
|
|
if (args instanceof Array) {
|
|
|
resData.floorHeader.name = args[0].data.text;
|
|
|
resData.floorHeader.navs = args[1].data;
|
|
|
resData.floorHeader.floorId = args[0].template_id;
|
|
|
} else {
|
|
|
resData.floorHeader.name = args.data.text;
|
|
|
resData.floorHeader.floorId = args.template_id;
|
|
|
}
|
|
|
});
|
|
|
data.singlehot.navs = args[1].data;
|
|
|
_setChannelType(data.singlehot, type);
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 异步获取人气单品
|
|
|
* @param {[Object]} rawData 接口返回的原始数据
|
|
|
* @param {[Object]} floorData 已经经过处理的楼层数据
|
|
|
* @param {String} originQuery 原始的query数据
|
|
|
* @param {Object} queryResult 接口中用于请求人气单品的数据
|
|
|
* @param {String} title 人气单品楼层的标题
|
|
|
* @param {Type} type 人气单品楼层的类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _processFloorDataWithQueryReusult = (rawData, originQuery, queryResult, title, type) => {
|
|
|
let data = {};
|
|
|
|
|
|
_.forEach(rawData, (subData, index) => {
|
|
|
if (resData.floorHeader.name.indexOf('最新上架') >= 0) {
|
|
|
resData = this._getNewGoodsFloorData(args);
|
|
|
}
|
|
|
return resData;
|
|
|
}
|
|
|
|
|
|
if (subData && subData.data && subData.data.text) {
|
|
|
const text = subData.data.text && _getText(subData.data.text);
|
|
|
/**
|
|
|
* 处理异步获取的人气单品数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} originQuery 原始skns
|
|
|
* @param {Object} queryResult 异步获取的数据
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_getSingehotViaResult(args, originQuery, queryResult, type) {
|
|
|
let data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
|
|
navs: [],
|
|
|
imgHot: [],
|
|
|
brands: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
let pos = 0;
|
|
|
|
|
|
if (text === title) {
|
|
|
data = _getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
const getIndex = skn => {
|
|
|
let index;
|
|
|
|
|
|
|
|
|
if (originQuery) {
|
|
|
const originQueryArr = originQuery.split(' ');
|
|
|
let setFlag = false;
|
|
|
|
|
|
const _getCategoryFloorData = args => {
|
|
|
const data = {
|
|
|
category: {
|
|
|
name: args[0].data.text,
|
|
|
navs: args[1].data,
|
|
|
list: []
|
|
|
}
|
|
|
};
|
|
|
_.forEach(originQueryArr, (query, idx) => {
|
|
|
if (!setFlag && query.toString() === skn.toString()) {
|
|
|
index = idx;
|
|
|
setFlag = true;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_.forEach(args[2].data, (it, index) => {
|
|
|
return index;
|
|
|
};
|
|
|
|
|
|
// 设置图片大小
|
|
|
if (index === 1) {
|
|
|
it.w = '377;';
|
|
|
it.h = '504;';
|
|
|
} else {
|
|
|
it.w = '185';
|
|
|
it.h = '510';
|
|
|
if (args[3].template_name === 'app_icon_list') {
|
|
|
data.singlehot.brands = args[3].data;
|
|
|
}
|
|
|
|
|
|
data.category.list.push(it);
|
|
|
});
|
|
|
if (queryResult.data) {
|
|
|
_.forEach(queryResult.data.product_list || [], it => {
|
|
|
const formatData = processProduct(it, {
|
|
|
width: 280,
|
|
|
height: 373,
|
|
|
gender: channelMap[type].gender
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
if (pos > 11) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
const _getAccordionFloorData = args => {
|
|
|
let data = {
|
|
|
accordion: {
|
|
|
name: args[0].data.text,
|
|
|
navs: args[1].data,
|
|
|
slide: []
|
|
|
if (it.product_id) {
|
|
|
formatData.idx = getIndex(it.product_skn);
|
|
|
if (formatData.idx === 0 || formatData.idx) {
|
|
|
data.singlehot.imgHot.push(formatData);
|
|
|
pos += 1;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
data.accordion.slide = args[2].data;
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
data.singlehot.imgHot = _.sortBy(data.singlehot.imgHot, item => {
|
|
|
return item.idx;
|
|
|
});
|
|
|
|
|
|
const _requestContent = (type, params, code) => {
|
|
|
let data = {
|
|
|
client_type: 'web',
|
|
|
content_code: code || channelMap[type || 'boys'].code,
|
|
|
gender: channelMap[type || 'boys'].gender,
|
|
|
page: 1,
|
|
|
limit: 1000
|
|
|
};
|
|
|
|
|
|
Object.assign(data, params);
|
|
|
return serviceApi.get('operations/api/v5/resource/home', data, {
|
|
|
cache: true,
|
|
|
code: 200
|
|
|
}).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
pos = 1;
|
|
|
_.forEach(data.singlehot.imgHot, item => {
|
|
|
if (pos < 4 && item) {
|
|
|
item.tip = 'TOP' + pos;
|
|
|
pos += 1;
|
|
|
}
|
|
|
});
|
|
|
data.singlehot.navs = args[1].data;
|
|
|
this._setChannelType(data.singlehot, type);
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
const floorMap = {
|
|
|
slide: _getSlideData,
|
|
|
hot: _getHotGoodsFloorData,
|
|
|
最新速报: _getNewReportFloorData,
|
|
|
人气单品: _getSingleHotFloorData,
|
|
|
'GIRL KIDS': _getSingleHotFloorData,
|
|
|
'BOY KIDS': _getSingleHotFloorData,
|
|
|
ACCESSORIES: _getSingleHotFloorData,
|
|
|
优选品牌: _getPreBrandTopData,
|
|
|
最新上架: _getNewGoodsFloorData,
|
|
|
ad: _getadbannerData,
|
|
|
category: _getCategoryFloorData,
|
|
|
accordion: _getAccordionFloorData,
|
|
|
debrisSlide: _getDebrisSlide,
|
|
|
jacket: _getJacketData,
|
|
|
sevenCategory: _getClothesCategory,
|
|
|
floorTitle: _getFloorTitleData,
|
|
|
newuser: _getNewUserFloorData
|
|
|
};
|
|
|
/**
|
|
|
* 异步获取人气单品
|
|
|
* @param {[Object]} rawData 接口返回的原始数据
|
|
|
* @param {[Object]} floorData 已经经过处理的楼层数据
|
|
|
* @param {String} originQuery 原始的query数据
|
|
|
* @param {Object} queryResult 接口中用于请求人气单品的数据
|
|
|
* @param {String} title 人气单品楼层的标题
|
|
|
* @param {Type} type 人气单品楼层的类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
_processFloorDataWithQueryReusult(rawData, originQuery, queryResult, title, type) {
|
|
|
let data = {};
|
|
|
|
|
|
_.forEach(rawData, (subData, index) => {
|
|
|
|
|
|
const needQuery = {
|
|
|
'GIRL KIDS': true,
|
|
|
'BOY KIDS': true,
|
|
|
人气单品: true,
|
|
|
ACCESSORIES: true
|
|
|
};
|
|
|
if (subData && subData.data && subData.data.text) {
|
|
|
const text = subData.data.text && this._getText(subData.data.text);
|
|
|
|
|
|
const getQuery = args => {
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
|
|
|
if (goods) {
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
if (text === title) {
|
|
|
data = this._getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return skns;
|
|
|
};
|
|
|
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
const _processFloorData = (rawData, type) => {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
|
|
let singlehotFloorTitle = [];
|
|
|
let params = [];
|
|
|
let hasNewUser = false;
|
|
|
|
|
|
// 定义各种楼层需要用到的接口返回的数组中元素的个数
|
|
|
const bigFloorLength = 5;
|
|
|
const normalFloorLength = 3;
|
|
|
const hotCategoryLength = 2;
|
|
|
|
|
|
_.forEach(rawData, (data, index) => {
|
|
|
let floorData = null;
|
|
|
let queryParam = '';
|
|
|
|
|
|
if (data && data.template_name === 'recommend_content_three' ||
|
|
|
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
|
|
|
floorData = floorMap.slide.call(null, data.data);
|
|
|
} else if (data && data.template_intro === '热门品类') { // 处理热门品类
|
|
|
floorData = floorMap.hot.call(null, rawData.slice(index, index + hotCategoryLength), type);
|
|
|
} else if (data && data.data && 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);
|
|
|
|
|
|
if (needQuery[text]) {
|
|
|
queryParam = getQuery(rawData.slice(index, lastIndex));
|
|
|
if (queryParam.length > 0) {
|
|
|
params.push(queryParam);
|
|
|
}
|
|
|
_getCategoryFloorData(args) {
|
|
|
const data = {
|
|
|
category: {
|
|
|
name: args[0].data.text,
|
|
|
navs: args[1].data,
|
|
|
list: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
} else if (data && data.template_name === 'debrisSlider') { // 处理girls的banner
|
|
|
floorData = floorMap.debrisSlide.call(null, data.data);
|
|
|
} else if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') {
|
|
|
if (!hasNewUser) {
|
|
|
floorData = floorMap.newuser.call(null, data.data);
|
|
|
hasNewUser = true;
|
|
|
}
|
|
|
_.forEach(args[2].data, (it, index) => {
|
|
|
|
|
|
}
|
|
|
// 设置图片大小
|
|
|
if (index === 1) {
|
|
|
it.w = '377;';
|
|
|
it.h = '504;';
|
|
|
} else {
|
|
|
it.w = '185';
|
|
|
it.h = '510';
|
|
|
}
|
|
|
|
|
|
// 处理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));
|
|
|
}
|
|
|
data.category.list.push(it);
|
|
|
});
|
|
|
|
|
|
// 处理手风琴楼层
|
|
|
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));
|
|
|
}
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
_getAccordionFloorData(args) {
|
|
|
let data = {
|
|
|
accordion: {
|
|
|
name: args[0].data.text,
|
|
|
navs: args[1].data,
|
|
|
slide: []
|
|
|
}
|
|
|
};
|
|
|
|
|
|
// 处理promise
|
|
|
if (floorData && floorData.then && typeof floorData.then === 'function') {
|
|
|
searchPromise.push(floorData);
|
|
|
data.accordion.slide = args[2].data;
|
|
|
|
|
|
// 记住楼层位置, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorIndex.push(floorList.length);
|
|
|
return data;
|
|
|
}
|
|
|
|
|
|
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorTitle.push(_getText(data.data.text));
|
|
|
} else if (!_.isNil(floorData)) {
|
|
|
_.isArray(floorData) ?
|
|
|
floorList = floorList.concat(floorData) :
|
|
|
floorList.push(floorData);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
floors: floorList,
|
|
|
promise: _.reverse(searchPromise),
|
|
|
queryParams: _.reverse(params),
|
|
|
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
|
|
};
|
|
|
_requestContent(type, params, code) {
|
|
|
let data = {
|
|
|
client_type: 'web',
|
|
|
content_code: code || channelMap[type || 'boys'].code,
|
|
|
gender: channelMap[type || 'boys'].gender,
|
|
|
page: 1,
|
|
|
limit: 1000
|
|
|
};
|
|
|
|
|
|
const _processJKFloorData = (rawData) => {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
|
|
let singlehotFloorTitle = [];
|
|
|
let params = [];
|
|
|
Object.assign(data, params);
|
|
|
|
|
|
return this.get({
|
|
|
url: 'operations/api/v5/resource/home',
|
|
|
data,
|
|
|
param: {
|
|
|
cache: true,
|
|
|
code: 200
|
|
|
},
|
|
|
api: global.yoho.ServiceAPI
|
|
|
}).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
_.forEach(rawData, (data, index) => {
|
|
|
let floorData = null;
|
|
|
getQuery(args) {
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
|
|
|
if (data && data.template_name === 'recommend_content_three' ||
|
|
|
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
|
|
|
floorData = floorMap.slide.call(null, data.data);
|
|
|
floorData.slide.floorId = data.template_id;
|
|
|
} else if (data && data.data && data.data.text) { // 处理一般楼层
|
|
|
let text = _getText(data.data.text);
|
|
|
if (goods) {
|
|
|
_.forEach(goods, good => {
|
|
|
skns += good.id + ' ';
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 最新速报
|
|
|
if (text.indexOf('最新速报') >= 0) {
|
|
|
floorData = _getNewReportFloorData(rawData.slice(index, index + 6));
|
|
|
return skns;
|
|
|
}
|
|
|
|
|
|
// 单个图作为最新速报模块用过的,标识一下,不作为广告位了
|
|
|
_.filter(rawData.slice(index, index + 5), function(o) {
|
|
|
if (o.template_name === 'single_image') {
|
|
|
o.hasUser = true;
|
|
|
_processFloorData(rawData, type) {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
|
|
let singlehotFloorTitle = [];
|
|
|
let params = [];
|
|
|
let hasNewUser = false;
|
|
|
|
|
|
// 定义各种楼层需要用到的接口返回的数组中元素的个数
|
|
|
const bigFloorLength = 5;
|
|
|
const normalFloorLength = 3;
|
|
|
const hotCategoryLength = 2;
|
|
|
|
|
|
_.forEach(rawData, (data, index) => {
|
|
|
let floorData = null;
|
|
|
let queryParam = '';
|
|
|
|
|
|
if (data && data.template_name === 'recommend_content_three' ||
|
|
|
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
|
|
|
floorData = this.floorMap.slide(data.data);
|
|
|
} else if (data && data.template_intro === '热门品类') { // 处理热门品类
|
|
|
floorData = this.floorMap.hot(rawData.slice(index, index + hotCategoryLength), type);
|
|
|
} else if (data && data.data && data.data.text) { // 处理一般楼层
|
|
|
let text = this._getText(data.data.text);
|
|
|
let lastIndex = index + bigFloorLength < rawData.length ?
|
|
|
index + bigFloorLength : index + (rawData.length - index - 1);
|
|
|
|
|
|
floorData = this.floorMap[text] &&
|
|
|
this.floorMap[text](rawData.slice(index, lastIndex), type);
|
|
|
|
|
|
if (needQuery[text]) {
|
|
|
queryParam = this.getQuery(rawData.slice(index, lastIndex));
|
|
|
if (queryParam.length > 0) {
|
|
|
params.push(queryParam);
|
|
|
}
|
|
|
});
|
|
|
} else { // 文本
|
|
|
}
|
|
|
|
|
|
let href = rawData[index + 1].template_name === 'textNav' ?
|
|
|
rawData.slice(index, index + 2) : data;
|
|
|
} else if (data && data.template_name === 'debrisSlider') { // 处理girls的banner
|
|
|
floorData = this.floorMap.debrisSlide(data.data);
|
|
|
} else if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') {
|
|
|
if (!hasNewUser) {
|
|
|
floorData = this.floorMap.newuser(data.data);
|
|
|
hasNewUser = true;
|
|
|
}
|
|
|
|
|
|
floorData = floorMap.floorTitle.call(null, href);
|
|
|
}
|
|
|
|
|
|
} else if (data && data.template_name === 'jk_floor') { // 左1大图,右6小图,title
|
|
|
floorData = floorMap.jacket.call(null, data.data);
|
|
|
} else if (data && data.template_name === 'recommend_content_five') {
|
|
|
// 1标题12图,在日韩馆频道页,作为7个品类显示
|
|
|
floorData = floorMap.sevenCategory.call(null, data.data);
|
|
|
floorData.sevenCategory.floorId = data.template_id;
|
|
|
} else if (data && data.template_name === 'single_image') {
|
|
|
if (!data.hasUser) {
|
|
|
// 一张图,在日韩馆频道页,做广告位
|
|
|
floorData = floorMap.ad.call(null, data.data);
|
|
|
// 处理lifestyle分类楼层
|
|
|
if (!floorData && index + normalFloorLength < rawData.length &&
|
|
|
rawData[index + 1].template_name === 'textNav' &&
|
|
|
rawData[index + 2].template_name === 'floor') {
|
|
|
floorData = this.floorMap.category(rawData.slice(index, index + normalFloorLength));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 处理promise
|
|
|
if (floorData && floorData.then && typeof floorData.then === 'function') {
|
|
|
searchPromise.push(floorData);
|
|
|
|
|
|
// 记住楼层位置, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorIndex.push(floorList.length);
|
|
|
|
|
|
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorTitle.push(_getText(data.data.text));
|
|
|
} else if (!_.isNil(floorData)) {
|
|
|
_.isArray(floorData) ?
|
|
|
floorList = floorList.concat(floorData) :
|
|
|
floorList.push(floorData);
|
|
|
}
|
|
|
// 处理手风琴楼层
|
|
|
if (!floorData && index + normalFloorLength < rawData.length &&
|
|
|
rawData[index + 1].template_name === 'textNav' &&
|
|
|
rawData[index + 2].template_name === 'focus') {
|
|
|
floorData = this.floorMap.accordion(rawData.slice(index, index + normalFloorLength));
|
|
|
}
|
|
|
|
|
|
|
|
|
});
|
|
|
// 处理promise
|
|
|
if (floorData && floorData.then && typeof floorData.then === 'function') {
|
|
|
searchPromise.push(floorData);
|
|
|
|
|
|
return {
|
|
|
floors: floorList,
|
|
|
promise: _.reverse(searchPromise),
|
|
|
queryParams: _.reverse(params),
|
|
|
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
|
|
};
|
|
|
// 记住楼层位置, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorIndex.push(floorList.length);
|
|
|
|
|
|
const _formatResourceParams = (channel, code) => {
|
|
|
return serviceApi.get('operations/api/v5/resource/get', {content_code: code}, config.apiCache).then(data => {
|
|
|
let result = data && data.data[0] && data.data[0].data[0];
|
|
|
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorTitle.push(this._getText(data.data.text));
|
|
|
} else if (!_.isNil(floorData)) {
|
|
|
_.isArray(floorData) ?
|
|
|
floorList = floorList.concat(floorData) :
|
|
|
floorList.push(floorData);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (result) {
|
|
|
result.channel = channel;
|
|
|
}
|
|
|
return {
|
|
|
floors: floorList,
|
|
|
promise: _.reverse(searchPromise),
|
|
|
queryParams: _.reverse(params),
|
|
|
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return result || {};
|
|
|
});
|
|
|
};
|
|
|
_processJKFloorData(rawData) {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
|
|
let singlehotFloorTitle = [];
|
|
|
let params = [];
|
|
|
|
|
|
/**
|
|
|
* 频道页首次登陆导航并行调接口数据
|
|
|
* @param {Object} data
|
|
|
* @return {Object} formatData
|
|
|
*/
|
|
|
const _formatParams = (channel, data) => {
|
|
|
let params = {};
|
|
|
|
|
|
// 排序数据映射表
|
|
|
let orderMaps = {
|
|
|
s_t_desc: 'shelve_time:desc',
|
|
|
s_t_asc: 'shelve_time:asc',
|
|
|
s_p_asc: 'sales_price:asc',
|
|
|
s_p_desc: 'sales_price:desc',
|
|
|
p_d_desc: 'discount:desc',
|
|
|
p_d_asc: 'discount:asc',
|
|
|
skn_desc: 'product_skn:desc',
|
|
|
skn_asc: 'product_skn:asc',
|
|
|
activities_desc: 'activities.order_by:desc',
|
|
|
activities_asc: 'activities.order_by:asc',
|
|
|
s_n_asc: 'sales_num:asc',
|
|
|
s_n_desc: 'sales_num:desc',
|
|
|
activities_id_desc: 'activities.activity_id:desc',
|
|
|
activities_id_asc: 'activities.activity_id:asc',
|
|
|
brand_desc: 'brand_weight:desc'
|
|
|
};
|
|
|
|
|
|
params.status = 1; // 是否上架,1表示在架,2表示不在
|
|
|
params.sales = 'Y'; // 只搜索销售的产品
|
|
|
params.outlets = 2; // 非奥莱商品
|
|
|
params.stocknumber = 1; // 过滤掉已售罄的商品
|
|
|
params.attribute_not = 2; // 过滤掉赠品
|
|
|
if (!data.order) {
|
|
|
params.order = orderMaps.s_t_desc;
|
|
|
} else {
|
|
|
params.order = orderMaps[data.order] ? orderMaps[data.order] : '';
|
|
|
}
|
|
|
if (!data.page) {
|
|
|
params.page = 1;
|
|
|
}
|
|
|
|
|
|
if (data.viewNum) {
|
|
|
params.viewNum = data.viewNum;
|
|
|
} else if (!data.limit) {
|
|
|
params.viewNum = 60;
|
|
|
} else {
|
|
|
params.viewNum = data.limit;
|
|
|
delete data.limit;
|
|
|
}
|
|
|
if (data) {
|
|
|
params = Object.assign(data);
|
|
|
}
|
|
|
_.forEach(rawData, (data, index) => {
|
|
|
let floorData = null;
|
|
|
|
|
|
return searchApi.getProductList(params).then(result => {
|
|
|
let ret = result.data;
|
|
|
if (data && data.template_name === 'recommend_content_three' ||
|
|
|
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
|
|
|
floorData = this.floorMap.slide.call(null, data.data);
|
|
|
floorData.slide.floorId = data.template_id;
|
|
|
} else if (data && data.data && data.data.text) { // 处理一般楼层
|
|
|
let text = this._getText(data.data.text);
|
|
|
|
|
|
if (ret) {
|
|
|
ret.channel = channel;
|
|
|
}
|
|
|
// 最新速报
|
|
|
if (text.indexOf('最新速报') >= 0) {
|
|
|
floorData = this._getNewReportFloorData(rawData.slice(index, index + 6));
|
|
|
|
|
|
return ret;
|
|
|
});
|
|
|
};
|
|
|
// 单个图作为最新速报模块用过的,标识一下,不作为广告位了
|
|
|
_.filter(rawData.slice(index, index + 5), function(o) {
|
|
|
if (o.template_name === 'single_image') {
|
|
|
o.hasUser = true;
|
|
|
}
|
|
|
});
|
|
|
} else { // 文本
|
|
|
|
|
|
/**
|
|
|
* 格式化频道页首次登陆导航数据
|
|
|
* @param {Object} data
|
|
|
* @return {Object} formatData
|
|
|
*/
|
|
|
const formatIndexGuideData = data => {
|
|
|
let channels = {
|
|
|
boys: {gender: '1,3', limit: 1},
|
|
|
girls: {gender: '2,3', limit: 1},
|
|
|
lifestyle: {msort: 10, misort: '266,280,101,103,259', limit: 1},
|
|
|
kids: {msort: 365, limit: 1}
|
|
|
};
|
|
|
let formatData = [];
|
|
|
let promiseArr = [];
|
|
|
|
|
|
_.forEach(data, item => {
|
|
|
let channel = item.sort_name_en.toLowerCase().replace(' ', '');
|
|
|
|
|
|
formatData.push({
|
|
|
channel: channel,
|
|
|
url: item.sort_url,
|
|
|
sort_name: item.sort_name,
|
|
|
sort_name_en: item.sort_name_en,
|
|
|
content_code: item.content_code,
|
|
|
src: '',
|
|
|
num: 0
|
|
|
});
|
|
|
let href = rawData[index + 1].template_name === 'textNav' ?
|
|
|
rawData.slice(index, index + 2) : data;
|
|
|
|
|
|
if (channels[channel]) {
|
|
|
promiseArr.push(_formatParams(channel, channels[channel]));
|
|
|
}
|
|
|
});
|
|
|
floorData = this.floorMap.floorTitle.call(null, href);
|
|
|
}
|
|
|
|
|
|
return Promise.all(promiseArr).then(result => {
|
|
|
_.forEach(formatData, item => {
|
|
|
_.forEach(result, it => {
|
|
|
if (item && it && item.channel === it.channel) {
|
|
|
item.num = it.total;
|
|
|
} else if (data && data.template_name === 'jk_floor') { // 左1大图,右6小图,title
|
|
|
floorData = this.floorMap.jacket.call(null, data.data);
|
|
|
} else if (data && data.template_name === 'recommend_content_five') {
|
|
|
// 1标题12图,在日韩馆频道页,作为7个品类显示
|
|
|
floorData = this.floorMap.sevenCategory.call(null, data.data);
|
|
|
floorData.sevenCategory.floorId = data.template_id;
|
|
|
} else if (data && data.template_name === 'single_image') {
|
|
|
if (!data.hasUser) {
|
|
|
// 一张图,在日韩馆频道页,做广告位
|
|
|
floorData = this.floorMap.ad.call(null, data.data);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return formatData;
|
|
|
});
|
|
|
};
|
|
|
// 处理promise
|
|
|
if (floorData && floorData.then && typeof floorData.then === 'function') {
|
|
|
searchPromise.push(floorData);
|
|
|
|
|
|
/**
|
|
|
* 获取最新上架商品数据
|
|
|
*
|
|
|
* @param string $channel
|
|
|
* @return array
|
|
|
*/
|
|
|
const getNewArrival = (channel, isJKChannel, poolId)=> {
|
|
|
let rel = [],
|
|
|
sortList = sortMap[channel],
|
|
|
params = {},
|
|
|
method = '';
|
|
|
// 记住楼层位置, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorIndex.push(floorList.length);
|
|
|
|
|
|
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorTitle.push(this._getText(data.data.text));
|
|
|
} else if (!_.isNil(floorData)) {
|
|
|
_.isArray(floorData) ?
|
|
|
floorList = floorList.concat(floorData) :
|
|
|
floorList.push(floorData);
|
|
|
}
|
|
|
|
|
|
|
|
|
if (isJKChannel) {
|
|
|
method = 'app.search.sales';
|
|
|
params = {
|
|
|
productPool: poolId
|
|
|
};
|
|
|
});
|
|
|
|
|
|
// 没有商品池id,不查数据
|
|
|
if (!poolId) {
|
|
|
return Promise.all(rel).then();
|
|
|
}
|
|
|
} else {
|
|
|
method = 'web.search.newshelve';
|
|
|
params = {
|
|
|
order: 'shelve_time:desc',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
|
|
attribute_not: 2,
|
|
|
stocknumber: 3,
|
|
|
dayLimit: 4
|
|
|
return {
|
|
|
floors: floorList,
|
|
|
promise: _.reverse(searchPromise),
|
|
|
queryParams: _.reverse(params),
|
|
|
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
_formatResourceParams(channel, code) {
|
|
|
return this.get({
|
|
|
url: 'operations/api/v5/resource/get',
|
|
|
data: { content_code: code },
|
|
|
param: config.apiCache,
|
|
|
api: global.yoho.ServiceAPI
|
|
|
}).then(data => {
|
|
|
let result = data && data.data[0] && data.data[0].data[0];
|
|
|
|
|
|
if (result) {
|
|
|
result.channel = channel;
|
|
|
}
|
|
|
|
|
|
params.gender = channelMap[channel].gender;
|
|
|
return result || {};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_.forEach(sortList, (item) => {
|
|
|
let data = Object.assign(item, params, {limit: item.viewNum});
|
|
|
/**
|
|
|
* 频道页首次登陆导航并行调接口数据
|
|
|
* @param {Object} data
|
|
|
* @return {Object} formatData
|
|
|
*/
|
|
|
_formatParams(channel, data) {
|
|
|
let params = {};
|
|
|
|
|
|
// 排序数据映射表
|
|
|
let orderMaps = {
|
|
|
s_t_desc: 'shelve_time:desc',
|
|
|
s_t_asc: 'shelve_time:asc',
|
|
|
s_p_asc: 'sales_price:asc',
|
|
|
s_p_desc: 'sales_price:desc',
|
|
|
p_d_desc: 'discount:desc',
|
|
|
p_d_asc: 'discount:asc',
|
|
|
skn_desc: 'product_skn:desc',
|
|
|
skn_asc: 'product_skn:asc',
|
|
|
activities_desc: 'activities.order_by:desc',
|
|
|
activities_asc: 'activities.order_by:asc',
|
|
|
s_n_asc: 'sales_num:asc',
|
|
|
s_n_desc: 'sales_num:desc',
|
|
|
activities_id_desc: 'activities.activity_id:desc',
|
|
|
activities_id_asc: 'activities.activity_id:asc',
|
|
|
brand_desc: 'brand_weight:desc'
|
|
|
};
|
|
|
|
|
|
rel.push(api.get('', Object.assign({
|
|
|
method: method
|
|
|
}, data), {cache: true}));
|
|
|
});
|
|
|
params.status = 1; // 是否上架,1表示在架,2表示不在
|
|
|
params.sales = 'Y'; // 只搜索销售的产品
|
|
|
params.outlets = 2; // 非奥莱商品
|
|
|
params.stocknumber = 1; // 过滤掉已售罄的商品
|
|
|
params.attribute_not = 2; // 过滤掉赠品
|
|
|
if (!data.order) {
|
|
|
params.order = orderMaps.s_t_desc;
|
|
|
} else {
|
|
|
params.order = orderMaps[data.order] ? orderMaps[data.order] : '';
|
|
|
}
|
|
|
if (!data.page) {
|
|
|
params.page = 1;
|
|
|
}
|
|
|
|
|
|
return Promise.all(rel).then(res => {
|
|
|
let data = [],
|
|
|
result = [];
|
|
|
if (data.viewNum) {
|
|
|
params.viewNum = data.viewNum;
|
|
|
} else if (!data.limit) {
|
|
|
params.viewNum = 60;
|
|
|
} else {
|
|
|
params.viewNum = data.limit;
|
|
|
delete data.limit;
|
|
|
}
|
|
|
if (data) {
|
|
|
params = Object.assign(data);
|
|
|
}
|
|
|
|
|
|
_.forEach(sortList, (it, index) => {
|
|
|
let list = _.get(res[index], 'data.product_list', []);
|
|
|
return this.searchApi.getProductList(params).then(result => {
|
|
|
let ret = result.data;
|
|
|
|
|
|
if (list.length === sortList[index].viewNum) {
|
|
|
data = data.concat(list);
|
|
|
if (ret) {
|
|
|
ret.channel = channel;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
_.forEach(data, (item) => {
|
|
|
result.push(processProduct(item, {
|
|
|
width: 280,
|
|
|
height: 373,
|
|
|
gender: params.gender
|
|
|
}));
|
|
|
return ret;
|
|
|
});
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取频道页数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const getContent = (type, isJKChannel, poolId) => {
|
|
|
/**
|
|
|
* 格式化频道页首次登陆导航数据
|
|
|
* @param {Object} data
|
|
|
* @return {Object} formatData
|
|
|
*/
|
|
|
formatIndexGuideData(data) {
|
|
|
let channels = {
|
|
|
boys: {gender: '1,3', limit: 1},
|
|
|
girls: {gender: '2,3', limit: 1},
|
|
|
lifestyle: {msort: 10, misort: '266,280,101,103,259', limit: 1},
|
|
|
kids: {msort: 365, limit: 1}
|
|
|
};
|
|
|
let formatData = [];
|
|
|
let promiseArr = [];
|
|
|
|
|
|
_.forEach(data, item => {
|
|
|
let channel = item.sort_name_en.toLowerCase().replace(' ', '');
|
|
|
|
|
|
formatData.push({
|
|
|
channel: channel,
|
|
|
url: item.sort_url,
|
|
|
sort_name: item.sort_name,
|
|
|
sort_name_en: item.sort_name_en,
|
|
|
content_code: item.content_code,
|
|
|
src: '',
|
|
|
num: 0
|
|
|
});
|
|
|
|
|
|
let params = {new_device: 'Y'};
|
|
|
if (channels[channel]) {
|
|
|
promiseArr.push(this._formatParams(channel, channels[channel]));
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return Promise.all([
|
|
|
headerModel.requestHeaderData(type),
|
|
|
_requestContent(type, params),
|
|
|
getNewArrival(type, isJKChannel, poolId)
|
|
|
]).then(res => {
|
|
|
return Promise.all(promiseArr).then(result => {
|
|
|
_.forEach(formatData, item => {
|
|
|
_.forEach(result, it => {
|
|
|
if (item && it && item.channel === it.channel) {
|
|
|
item.num = it.total;
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
let headerData = res[0].data || res[0],
|
|
|
contentData = res[1].data ? res[1].data.list : res[1];
|
|
|
return formatData;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let data = {};
|
|
|
/**
|
|
|
* 获取最新上架商品数据
|
|
|
*
|
|
|
* @param string $channel
|
|
|
* @return array
|
|
|
*/
|
|
|
getNewArrival(channel, isJKChannel, poolId) {
|
|
|
let rel = [],
|
|
|
sortList = sortMap[channel],
|
|
|
params = {},
|
|
|
method = '';
|
|
|
|
|
|
|
|
|
if (isJKChannel) {
|
|
|
method = 'app.search.sales';
|
|
|
params = {
|
|
|
productPool: poolId
|
|
|
};
|
|
|
|
|
|
// 没有商品池id,不查数据
|
|
|
if (!poolId) {
|
|
|
return Promise.all(rel).then();
|
|
|
}
|
|
|
} else {
|
|
|
method = 'web.search.newshelve';
|
|
|
params = {
|
|
|
order: 'shelve_time:desc',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
|
|
attribute_not: 2,
|
|
|
stocknumber: 3,
|
|
|
dayLimit: 4
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const processResult = _processFloorData(contentData, type);
|
|
|
|
|
|
data = headerData;
|
|
|
data.module = 'channel';
|
|
|
data.page = 'channel';
|
|
|
data.pageType = type;
|
|
|
data.footerTop = true;
|
|
|
data.channel = processResult.floors.map(function(elem) {
|
|
|
params.gender = channelMap[channel].gender;
|
|
|
|
|
|
if (elem.newArrivls) {
|
|
|
elem.newArrivls.goods = res[2];
|
|
|
}
|
|
|
_.forEach(sortList, (item) => {
|
|
|
let data = Object.assign(item, params, {limit: item.viewNum});
|
|
|
|
|
|
return elem;
|
|
|
rel.push(this.get({
|
|
|
data: Object.assign({
|
|
|
method: method
|
|
|
}, data),
|
|
|
param: {cache: true}
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
rawData: contentData,
|
|
|
floorData: data,
|
|
|
searchPromise: processResult.promise,
|
|
|
singlehotFloorIndex: processResult.singlehotFloorIndex,
|
|
|
singlehotFloorTitle: processResult.singlehotFloorTitle,
|
|
|
queryParams: processResult.queryParams,
|
|
|
channelType: type
|
|
|
};
|
|
|
return Promise.all(rel).then(res => {
|
|
|
let data = [],
|
|
|
result = [];
|
|
|
|
|
|
}).then(result => {
|
|
|
|
|
|
// 如果有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.queryParams[index],
|
|
|
data,
|
|
|
result.singlehotFloorTitle[index],
|
|
|
result.channelType
|
|
|
));
|
|
|
});
|
|
|
_.forEach(sortList, (it, index) => {
|
|
|
let list = _.get(res[index], 'data.product_list', []);
|
|
|
|
|
|
return result.floorData;
|
|
|
if (list.length === sortList[index].viewNum) {
|
|
|
data = data.concat(list);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return result.floorData || result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取日韩馆频道页数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const getJKContent = (req) => {
|
|
|
let channel = req.query.channel || req.yoho.channel || 'boys',
|
|
|
contentCode = req.query.content_code;
|
|
|
_.forEach(data, (item) => {
|
|
|
result.push(processProduct(item, {
|
|
|
width: 280,
|
|
|
height: 373,
|
|
|
gender: params.gender
|
|
|
}));
|
|
|
});
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return Promise.all([
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
_requestContent(channel, {}, contentCode),
|
|
|
getNewArrival(channel, true, req.query.template_id)
|
|
|
]).then(res => {
|
|
|
|
|
|
let headerData = res[0].data || res[0],
|
|
|
contentData = res[1].data ? res[1].data.list : res[1];
|
|
|
/**
|
|
|
* 获取频道页数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
getContent(type, isJKChannel, poolId) {
|
|
|
|
|
|
let data = {};
|
|
|
let params = {new_device: 'Y'};
|
|
|
|
|
|
const processResult = _processJKFloorData(contentData);
|
|
|
return Promise.all([
|
|
|
headerModel.requestHeaderData(type),
|
|
|
this._requestContent(type, params),
|
|
|
this.getNewArrival(type, isJKChannel, poolId)
|
|
|
]).then(res => {
|
|
|
|
|
|
data = headerData;
|
|
|
data.module = 'channel';
|
|
|
data.page = 'channel';
|
|
|
data.pageType = channel;
|
|
|
data.mchannel = 'japanKorean';// 子频道,如日韩馆
|
|
|
data.footerTop = true;
|
|
|
data.channel = processResult.floors.map(function(elem) {
|
|
|
let headerData = res[0].data || res[0],
|
|
|
contentData = res[1].data ? res[1].data.list : res[1];
|
|
|
|
|
|
if (elem.newArrivls) {
|
|
|
elem.newArrivls.goods = res[2];
|
|
|
}
|
|
|
let data = {};
|
|
|
|
|
|
return elem;
|
|
|
});
|
|
|
const processResult = this._processFloorData(contentData, type);
|
|
|
|
|
|
return {
|
|
|
rawData: contentData,
|
|
|
floorData: data,
|
|
|
searchPromise: processResult.promise,
|
|
|
singlehotFloorIndex: processResult.singlehotFloorIndex,
|
|
|
singlehotFloorTitle: processResult.singlehotFloorTitle,
|
|
|
queryParams: processResult.queryParams,
|
|
|
channelType: channel
|
|
|
};
|
|
|
data = headerData;
|
|
|
data.module = 'channel';
|
|
|
data.page = 'channel';
|
|
|
data.pageType = type;
|
|
|
data.footerTop = true;
|
|
|
data.channel = processResult.floors.map(function(elem) {
|
|
|
|
|
|
}).then(result => {
|
|
|
|
|
|
// 如果有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.queryParams[index],
|
|
|
data,
|
|
|
result.singlehotFloorTitle[index],
|
|
|
result.channelType
|
|
|
));
|
|
|
});
|
|
|
if (elem.newArrivls) {
|
|
|
elem.newArrivls.goods = res[2];
|
|
|
}
|
|
|
|
|
|
return result.floorData;
|
|
|
return elem;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return result.floorData || result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const getResourceData = (formatData) => {
|
|
|
let promiseArr = [];
|
|
|
return {
|
|
|
rawData: contentData,
|
|
|
floorData: data,
|
|
|
searchPromise: processResult.promise,
|
|
|
singlehotFloorIndex: processResult.singlehotFloorIndex,
|
|
|
singlehotFloorTitle: processResult.singlehotFloorTitle,
|
|
|
queryParams: processResult.queryParams,
|
|
|
channelType: type
|
|
|
};
|
|
|
|
|
|
}).then(result => {
|
|
|
|
|
|
// 如果有promise则做相应处理
|
|
|
if (result.searchPromise.length) {
|
|
|
return Promise.all(result.searchPromise).then(res => {
|
|
|
_.forEach(res, (data, index) => {
|
|
|
result.floorData.channel
|
|
|
.splice(result.singlehotFloorIndex[index], 0,
|
|
|
this._processFloorDataWithQueryReusult(
|
|
|
result.rawData,
|
|
|
result.queryParams[index],
|
|
|
data,
|
|
|
result.singlehotFloorTitle[index],
|
|
|
result.channelType
|
|
|
));
|
|
|
});
|
|
|
|
|
|
return result.floorData;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_.forEach(formatData, item => {
|
|
|
if (item.content_code) {
|
|
|
promiseArr.push(_formatResourceParams(item.channel, item.content_code));
|
|
|
}
|
|
|
});
|
|
|
return Promise.all(promiseArr).then(data => {
|
|
|
_.forEach(formatData, (item, index) => {
|
|
|
_.forEach(data, (it, idx) => {
|
|
|
if (formatData[index].channel === data[idx].channel) {
|
|
|
formatData[index].src = data[idx].src;
|
|
|
}
|
|
|
});
|
|
|
return result.floorData || result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return formatData;
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
|
* 获取日韩馆频道页数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
getJKContent(req) {
|
|
|
let channel = req.query.channel || req.yoho.channel || 'boys',
|
|
|
contentCode = req.query.content_code;
|
|
|
|
|
|
return Promise.all([
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
this._requestContent(channel, {}, contentCode),
|
|
|
this.getNewArrival(channel, true, req.query.template_id)
|
|
|
]).then(res => {
|
|
|
|
|
|
let headerData = res[0].data || res[0],
|
|
|
contentData = res[1].data ? res[1].data.list : res[1];
|
|
|
|
|
|
let data = {};
|
|
|
|
|
|
const processResult = this._processJKFloorData(contentData);
|
|
|
|
|
|
data = headerData;
|
|
|
data.module = 'channel';
|
|
|
data.page = 'channel';
|
|
|
data.pageType = channel;
|
|
|
data.mchannel = 'japanKorean';// 子频道,如日韩馆
|
|
|
data.footerTop = true;
|
|
|
data.channel = processResult.floors.map(function(elem) {
|
|
|
|
|
|
if (elem.newArrivls) {
|
|
|
elem.newArrivls.goods = res[2];
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取频道页首次登陆导航数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const getIndexGuideData = () => {
|
|
|
let params = {
|
|
|
client_type: 'web',
|
|
|
private_key: '0ed29744ed318fd28d2c07985d3ba633'
|
|
|
};
|
|
|
return elem;
|
|
|
});
|
|
|
|
|
|
return serviceApi.get('operations/api/v6/category/getCategory', params, config.apiCache);
|
|
|
};
|
|
|
return {
|
|
|
rawData: contentData,
|
|
|
floorData: data,
|
|
|
searchPromise: processResult.promise,
|
|
|
singlehotFloorIndex: processResult.singlehotFloorIndex,
|
|
|
singlehotFloorTitle: processResult.singlehotFloorTitle,
|
|
|
queryParams: processResult.queryParams,
|
|
|
channelType: channel
|
|
|
};
|
|
|
|
|
|
}).then(result => {
|
|
|
|
|
|
// 如果有promise则做相应处理
|
|
|
if (result.searchPromise.length) {
|
|
|
return Promise.all(result.searchPromise).then(res => {
|
|
|
_.forEach(res, (data, index) => {
|
|
|
result.floorData.channel
|
|
|
.splice(result.singlehotFloorIndex[index], 0,
|
|
|
this._processFloorDataWithQueryReusult(
|
|
|
result.rawData,
|
|
|
result.queryParams[index],
|
|
|
data,
|
|
|
result.singlehotFloorTitle[index],
|
|
|
result.channelType
|
|
|
));
|
|
|
});
|
|
|
|
|
|
return result.floorData;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
const hasNewUserFloor = (channelType, uid) => {
|
|
|
let params = {uid: uid};
|
|
|
return result.floorData || result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return _requestContent(channelType, params).then(res => {
|
|
|
let isNewUser = false,
|
|
|
contentData = res.data ? res.data.list : res;
|
|
|
getResourceData(formatData) {
|
|
|
let promiseArr = [];
|
|
|
|
|
|
_.forEach(contentData, (data) => {
|
|
|
if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') {
|
|
|
isNewUser = true;
|
|
|
return false;
|
|
|
_.forEach(formatData, item => {
|
|
|
if (item.content_code) {
|
|
|
promiseArr.push(this._formatResourceParams(item.channel, item.content_code));
|
|
|
}
|
|
|
});
|
|
|
return Promise.all(promiseArr).then(data => {
|
|
|
_.forEach(formatData, (item, index) => {
|
|
|
_.forEach(data, (it, idx) => {
|
|
|
if (formatData[index].channel === data[idx].channel) {
|
|
|
formatData[index].src = data[idx].src;
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
isNewUser: isNewUser
|
|
|
return formatData;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取频道页首次登陆导航数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
getIndexGuideData() {
|
|
|
let params = {
|
|
|
client_type: 'web',
|
|
|
private_key: '0ed29744ed318fd28d2c07985d3ba633'
|
|
|
};
|
|
|
});
|
|
|
};
|
|
|
|
|
|
return this.get({
|
|
|
url: 'operations/api/v6/category/getCategory',
|
|
|
data: params,
|
|
|
param: config.apiCache,
|
|
|
api: global.yoho.ServiceAPI
|
|
|
});
|
|
|
}
|
|
|
|
|
|
hasNewUserFloor(channelType, uid) {
|
|
|
let params = {uid: uid};
|
|
|
|
|
|
return this._requestContent(channelType, params).then(res => {
|
|
|
let isNewUser = false,
|
|
|
contentData = res.data ? res.data.list : res;
|
|
|
|
|
|
module.exports = {
|
|
|
getNewArrival: getNewArrival,
|
|
|
getContent: getContent,
|
|
|
getJKContent: getJKContent,
|
|
|
getIndexGuideData: getIndexGuideData,
|
|
|
formatIndexGuideData: formatIndexGuideData,
|
|
|
getResourceData: getResourceData,
|
|
|
hasNewUserFloor: hasNewUserFloor
|
|
|
_.forEach(contentData, (data) => {
|
|
|
if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') {
|
|
|
isNewUser = true;
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
isNewUser: isNewUser
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
}; |
...
|
...
|
|