...
|
...
|
@@ -13,16 +13,49 @@ const helpers = global.yoho.helpers; |
|
|
const config = global.yoho.config;
|
|
|
|
|
|
const processProduct = require(`${global.utils}/product-process`).processProduct;
|
|
|
const searchApi = require('./search-api');
|
|
|
const SearchApi = require('./search-api');
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
|
|
|
const needQuery = {
|
|
|
'GIRL KIDS': true,
|
|
|
'BOY KIDS': true,
|
|
|
人气单品: true,
|
|
|
ACCESSORIES: true
|
|
|
};
|
|
|
|
|
|
const api = global.yoho.API;
|
|
|
const serviceApi = global.yoho.ServiceAPI;
|
|
|
const channelMap = dataMap.channel;
|
|
|
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
const sortMap = dataMap.sort;
|
|
|
|
|
|
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)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 获取可用的标题
|
|
|
const _getText = data => {
|
|
|
_getText(data) {
|
|
|
let text = data.split(' ')[0];
|
|
|
const regResult = /\w+/.exec(text);
|
|
|
const titleWithoutChinese = /^(?=.*[A-Za-z0-9])[A-Za-z0-9 _]*$/;
|
...
|
...
|
@@ -39,21 +72,17 @@ const _getText = data => { |
|
|
}
|
|
|
|
|
|
return text;
|
|
|
};
|
|
|
|
|
|
const channelMap = dataMap.channel;
|
|
|
|
|
|
const sortMap = dataMap.sort;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 新人专享
|
|
|
* @param {[Object]} data 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
const _getNewUserFloorData = data => {
|
|
|
_getNewUserFloorData(data) {
|
|
|
let floorData = {
|
|
|
newUserFloor: {
|
|
|
name: _getText(data.title.name),
|
|
|
name: this._getText(data.title.name),
|
|
|
navs: {},
|
|
|
bannerImage: {
|
|
|
url: data.banner_image[0].url,
|
...
|
...
|
@@ -87,14 +116,14 @@ const _getNewUserFloorData = data => { |
|
|
}
|
|
|
|
|
|
return floorData;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取带小图的banner
|
|
|
* @param {[Object]} data 原始数据
|
|
|
* @return {[Object]} 转换后的数据
|
|
|
*/
|
|
|
const _getDebrisSlide = data => {
|
|
|
_getDebrisSlide(data) {
|
|
|
let floorData = {
|
|
|
debrisSlider: {
|
|
|
left: [],
|
...
|
...
|
@@ -110,27 +139,27 @@ const _getDebrisSlide = data => { |
|
|
});
|
|
|
|
|
|
return floorData;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取广告位
|
|
|
* @param {Object} data 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
const _getadbannerData = data => {
|
|
|
_getadbannerData(data) {
|
|
|
|
|
|
return {
|
|
|
adbanner: data
|
|
|
};
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 生成banner模板数据
|
|
|
* @param {Object} srcData 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
const _getSlideData = srcData => {
|
|
|
_getSlideData(srcData) {
|
|
|
const slideData = {
|
|
|
slide: {
|
|
|
list: [],
|
...
|
...
|
@@ -151,15 +180,15 @@ const _getSlideData = srcData => { |
|
|
}
|
|
|
|
|
|
return slideData;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取品牌列表数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getBrandLogosData = (args, showNum) => {
|
|
|
_getBrandLogosData(args, showNum) {
|
|
|
let items = [],
|
|
|
brandLogos = [],
|
|
|
i = 0,
|
...
|
...
|
@@ -214,14 +243,14 @@ const _getBrandLogosData = (args, showNum) => { |
|
|
isMore: true
|
|
|
});
|
|
|
return brandLogos;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取最新速报模板数据 : 大图+小图+大图+single_image(广告位)/+floor(logo列表)
|
|
|
* @param {Object} srcData 原始数据
|
|
|
* @return {Object} 转换后的数据
|
|
|
*/
|
|
|
const _getNewReportFloorData = (args) => {
|
|
|
_getNewReportFloorData(args) {
|
|
|
const title = args[0].data.text;
|
|
|
let floorId = args[0].template_id;
|
|
|
let item = args[1].data;
|
...
|
...
|
@@ -258,7 +287,7 @@ const _getNewReportFloorData = (args) => { |
|
|
|
|
|
// 广告位
|
|
|
if (forthItem.template_name && forthItem.template_name === 'single_image') {
|
|
|
adData = _getadbannerData(forthItem.data[0]);
|
|
|
adData = this._getadbannerData(forthItem.data[0]);
|
|
|
floorDatas.push(adData);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -269,30 +298,30 @@ const _getNewReportFloorData = (args) => { |
|
|
brandLogoObj.moreBrand = args[5].data[0].url || '';
|
|
|
}
|
|
|
|
|
|
brandLogoObj.brandLogos = _getBrandLogosData(forthItem.data, brandLogoObj.showNum);
|
|
|
brandLogoObj.brandLogos = this._getBrandLogosData(forthItem.data, brandLogoObj.showNum);
|
|
|
data.newReport.brandLogoObj = brandLogoObj;
|
|
|
}
|
|
|
return floorDatas;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 给目标对象绑定频道属性
|
|
|
* @param {Object} obj 需要绑定频道属性的对象
|
|
|
* @param {String} type 需要设置的频道类型
|
|
|
* @return undefined
|
|
|
*/
|
|
|
const _setChannelType = (obj, type) => {
|
|
|
_setChannelType(obj, type) {
|
|
|
obj[type + 'Channel'] = true;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取优选品牌模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getPreBrandTopData = (args, type) => {
|
|
|
_getPreBrandTopData(args, type) {
|
|
|
const title = args[0].data.text;
|
|
|
let item = args[1].data,
|
|
|
logoItems = args[2] || {},
|
...
|
...
|
@@ -314,25 +343,25 @@ const _getPreBrandTopData = (args, type) => { |
|
|
if (_.get(args[3], 'data[0].url', '')) {
|
|
|
brandLogoObj.moreBrand = args[3].data[0].url;
|
|
|
}
|
|
|
brandLogoObj.brandLogos = _getBrandLogosData(args[2].data, showNum);
|
|
|
brandLogoObj.brandLogos = this._getBrandLogosData(args[2].data, showNum);
|
|
|
data.preferenceBrands.brandLogoObj = brandLogoObj;
|
|
|
}
|
|
|
data.preferenceBrands.imgBrand = item;
|
|
|
if (type === 'kids') {
|
|
|
data.preferenceBrands.sliderColor = '#7AD3F8';
|
|
|
}
|
|
|
_setChannelType(data.preferenceBrands, type);
|
|
|
this._setChannelType(data.preferenceBrands, type);
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取热门分类模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getHotGoodsFloorData = (args, type) => {
|
|
|
_getHotGoodsFloorData(args, type) {
|
|
|
let item = args[0];
|
|
|
let nextItem = args[1];
|
|
|
|
...
|
...
|
@@ -376,19 +405,19 @@ const _getHotGoodsFloorData = (args, type) => { |
|
|
list.push(object);
|
|
|
data.recommend.tplrecommend = list;
|
|
|
|
|
|
_setChannelType(data.recommend, type);
|
|
|
this._setChannelType(data.recommend, type);
|
|
|
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取japanKorean潮流上装Jacket,title+左大图+右6小图模板数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getJacketData = (arg) => {
|
|
|
_getJacketData(arg) {
|
|
|
let resData = {
|
|
|
tpltopic: {
|
|
|
bigPic: arg.big_image[0],
|
...
|
...
|
@@ -401,29 +430,29 @@ const _getJacketData = (arg) => { |
|
|
}
|
|
|
|
|
|
return resData;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取7个品类图
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getClothesCategory = (arg) => {
|
|
|
_getClothesCategory(arg) {
|
|
|
return {
|
|
|
sevenCategory: {
|
|
|
categorys: arg.list
|
|
|
}
|
|
|
};
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取boys人气单品模版数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getBoysSingleHot = (args, type) => {
|
|
|
_getBoysSingleHot(args, type) {
|
|
|
const len = 10;
|
|
|
const data = {
|
|
|
singlehot: {
|
...
|
...
|
@@ -460,24 +489,24 @@ const _getBoysSingleHot = (args, type) => { |
|
|
});
|
|
|
|
|
|
data.singlehot.imgHot = list;
|
|
|
_setChannelType(data.singlehot, type);
|
|
|
this._setChannelType(data.singlehot, type);
|
|
|
floorDatas.push(data);
|
|
|
|
|
|
if (args[3].template_name === 'single_image') {
|
|
|
adData = _getadbannerData(args[3].data[0]);
|
|
|
adData = this._getadbannerData(args[3].data[0]);
|
|
|
floorDatas.push(adData);
|
|
|
}
|
|
|
|
|
|
return floorDatas;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取girls人气单品模版数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getGirlsSingleHot = (args, type) => {
|
|
|
_getGirlsSingleHot(args, type) {
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
|
...
|
...
|
@@ -489,7 +518,7 @@ const _getGirlsSingleHot = (args, type) => { |
|
|
return;
|
|
|
}
|
|
|
|
|
|
return searchApi.getProductList({
|
|
|
return this.searchApi.getProductList({
|
|
|
client_type: 'web',
|
|
|
query: skns,
|
|
|
order: 'shelve_time:desc',
|
...
|
...
|
@@ -501,30 +530,30 @@ const _getGirlsSingleHot = (args, type) => { |
|
|
gender: channelMap[type].gender,
|
|
|
limit: 60
|
|
|
}, config.apiCache);
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 人气单品入口
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getSingleHotFloorData = (args, type) => {
|
|
|
_getSingleHotFloorData(args, type) {
|
|
|
if (type === 'boys') {
|
|
|
return _getBoysSingleHot(args, type);
|
|
|
return this._getBoysSingleHot(args, type);
|
|
|
} else {
|
|
|
return _getGirlsSingleHot(args, type);
|
|
|
return this._getGirlsSingleHot(args, type);
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 组装最新上架楼层数据
|
|
|
*
|
|
|
* @param string data
|
|
|
* return obj
|
|
|
*/
|
|
|
const _getNewGoodsFloorData = args => {
|
|
|
_getNewGoodsFloorData(args) {
|
|
|
const data = {};
|
|
|
|
|
|
if (!_.isEmpty(args)) {
|
...
|
...
|
@@ -537,15 +566,15 @@ const _getNewGoodsFloorData = args => { |
|
|
data.newArrivls.navs = args[1] ? args[1].data : {};
|
|
|
}
|
|
|
return data;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 文本标题
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getFloorTitleData = (args) => {
|
|
|
_getFloorTitleData(args) {
|
|
|
let resData = {
|
|
|
floorHeader: {}
|
|
|
};
|
...
|
...
|
@@ -560,12 +589,12 @@ const _getFloorTitleData = (args) => { |
|
|
}
|
|
|
|
|
|
if (resData.floorHeader.name.indexOf('最新上架') >= 0) {
|
|
|
resData = _getNewGoodsFloorData(args);
|
|
|
resData = this._getNewGoodsFloorData(args);
|
|
|
}
|
|
|
return resData;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 处理异步获取的人气单品数据
|
|
|
* @param {[Object]} args 参数列表
|
|
|
* @param {String} originQuery 原始skns
|
...
|
...
|
@@ -573,7 +602,7 @@ const _getFloorTitleData = (args) => { |
|
|
* @param {String} type 频道类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _getSingehotViaResult = (args, originQuery, queryResult, type) => {
|
|
|
_getSingehotViaResult(args, originQuery, queryResult, type) {
|
|
|
let data = {
|
|
|
singlehot: {
|
|
|
name: args[0].data.text,
|
...
|
...
|
@@ -643,11 +672,11 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => { |
|
|
}
|
|
|
});
|
|
|
data.singlehot.navs = args[1].data;
|
|
|
_setChannelType(data.singlehot, type);
|
|
|
this._setChannelType(data.singlehot, type);
|
|
|
return data;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 异步获取人气单品
|
|
|
* @param {[Object]} rawData 接口返回的原始数据
|
|
|
* @param {[Object]} floorData 已经经过处理的楼层数据
|
...
|
...
|
@@ -657,27 +686,25 @@ const _getSingehotViaResult = (args, originQuery, queryResult, type) => { |
|
|
* @param {Type} type 人气单品楼层的类型
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const _processFloorDataWithQueryReusult = (rawData, originQuery, queryResult, title, type) => {
|
|
|
_processFloorDataWithQueryReusult(rawData, originQuery, queryResult, title, type) {
|
|
|
let data = {};
|
|
|
|
|
|
_.forEach(rawData, (subData, index) => {
|
|
|
|
|
|
if (subData && subData.data && subData.data.text) {
|
|
|
const text = subData.data.text && _getText(subData.data.text);
|
|
|
const text = subData.data.text && this._getText(subData.data.text);
|
|
|
|
|
|
|
|
|
if (text === title) {
|
|
|
data = _getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type);
|
|
|
data = this._getSingehotViaResult(rawData.slice(index, index + 4), originQuery, queryResult, type);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
const _getCategoryFloorData = args => {
|
|
|
_getCategoryFloorData(args) {
|
|
|
const data = {
|
|
|
category: {
|
|
|
name: args[0].data.text,
|
...
|
...
|
@@ -701,9 +728,9 @@ const _getCategoryFloorData = args => { |
|
|
});
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const _getAccordionFloorData = args => {
|
|
|
_getAccordionFloorData(args) {
|
|
|
let data = {
|
|
|
accordion: {
|
|
|
name: args[0].data.text,
|
...
|
...
|
@@ -715,9 +742,9 @@ const _getAccordionFloorData = args => { |
|
|
data.accordion.slide = args[2].data;
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const _requestContent = (type, params, code) => {
|
|
|
_requestContent(type, params, code) {
|
|
|
let data = {
|
|
|
client_type: 'web',
|
|
|
content_code: code || channelMap[type || 'boys'].code,
|
...
|
...
|
@@ -727,43 +754,22 @@ const _requestContent = (type, params, code) => { |
|
|
};
|
|
|
|
|
|
Object.assign(data, params);
|
|
|
return serviceApi.get('operations/api/v5/resource/home', data, {
|
|
|
|
|
|
return this.get({
|
|
|
url: 'operations/api/v5/resource/home',
|
|
|
data,
|
|
|
param: {
|
|
|
cache: true,
|
|
|
code: 200
|
|
|
},
|
|
|
api: global.yoho.ServiceAPI
|
|
|
}).then(result => {
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
const needQuery = {
|
|
|
'GIRL KIDS': true,
|
|
|
'BOY KIDS': true,
|
|
|
人气单品: true,
|
|
|
ACCESSORIES: true
|
|
|
};
|
|
|
|
|
|
const getQuery = args => {
|
|
|
getQuery(args) {
|
|
|
let goods = args[2] && args[2].data;
|
|
|
let skns = '';
|
|
|
|
...
|
...
|
@@ -774,10 +780,9 @@ const getQuery = args => { |
|
|
}
|
|
|
|
|
|
return skns;
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
const _processFloorData = (rawData, type) => {
|
|
|
_processFloorData(rawData, type) {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
...
|
...
|
@@ -796,29 +801,29 @@ const _processFloorData = (rawData, type) => { |
|
|
|
|
|
if (data && data.template_name === 'recommend_content_three' ||
|
|
|
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
|
|
|
floorData = floorMap.slide.call(null, data.data);
|
|
|
floorData = this.floorMap.slide(data.data);
|
|
|
} else if (data && data.template_intro === '热门品类') { // 处理热门品类
|
|
|
floorData = floorMap.hot.call(null, rawData.slice(index, index + hotCategoryLength), type);
|
|
|
floorData = this.floorMap.hot(rawData.slice(index, index + hotCategoryLength), type);
|
|
|
} else if (data && data.data && data.data.text) { // 处理一般楼层
|
|
|
let text = _getText(data.data.text);
|
|
|
let text = this._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);
|
|
|
floorData = this.floorMap[text] &&
|
|
|
this.floorMap[text](rawData.slice(index, lastIndex), type);
|
|
|
|
|
|
if (needQuery[text]) {
|
|
|
queryParam = getQuery(rawData.slice(index, lastIndex));
|
|
|
queryParam = this.getQuery(rawData.slice(index, lastIndex));
|
|
|
if (queryParam.length > 0) {
|
|
|
params.push(queryParam);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else if (data && data.template_name === 'debrisSlider') { // 处理girls的banner
|
|
|
floorData = floorMap.debrisSlide.call(null, data.data);
|
|
|
floorData = this.floorMap.debrisSlide(data.data);
|
|
|
} else if (data.template_name === 'new_user_floor' || data.template_intro === '新人专享') {
|
|
|
if (!hasNewUser) {
|
|
|
floorData = floorMap.newuser.call(null, data.data);
|
|
|
floorData = this.floorMap.newuser(data.data);
|
|
|
hasNewUser = true;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -828,14 +833,14 @@ const _processFloorData = (rawData, type) => { |
|
|
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));
|
|
|
floorData = this.floorMap.category(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));
|
|
|
floorData = this.floorMap.accordion(rawData.slice(index, index + normalFloorLength));
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -847,7 +852,7 @@ const _processFloorData = (rawData, type) => { |
|
|
singlehotFloorIndex.push(floorList.length);
|
|
|
|
|
|
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorTitle.push(_getText(data.data.text));
|
|
|
singlehotFloorTitle.push(this._getText(data.data.text));
|
|
|
} else if (!_.isNil(floorData)) {
|
|
|
_.isArray(floorData) ?
|
|
|
floorList = floorList.concat(floorData) :
|
...
|
...
|
@@ -862,9 +867,9 @@ const _processFloorData = (rawData, type) => { |
|
|
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const _processJKFloorData = (rawData) => {
|
|
|
_processJKFloorData(rawData) {
|
|
|
let floorList = [];
|
|
|
let searchPromise = [];
|
|
|
let singlehotFloorIndex = [];
|
...
|
...
|
@@ -877,14 +882,14 @@ const _processJKFloorData = (rawData) => { |
|
|
|
|
|
if (data && data.template_name === 'recommend_content_three' ||
|
|
|
(data.template_intro === '焦点图' && index === 0)) { // 处理banner
|
|
|
floorData = floorMap.slide.call(null, data.data);
|
|
|
floorData = this.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);
|
|
|
let text = this._getText(data.data.text);
|
|
|
|
|
|
// 最新速报
|
|
|
if (text.indexOf('最新速报') >= 0) {
|
|
|
floorData = _getNewReportFloorData(rawData.slice(index, index + 6));
|
|
|
floorData = this._getNewReportFloorData(rawData.slice(index, index + 6));
|
|
|
|
|
|
// 单个图作为最新速报模块用过的,标识一下,不作为广告位了
|
|
|
_.filter(rawData.slice(index, index + 5), function(o) {
|
...
|
...
|
@@ -897,19 +902,19 @@ const _processJKFloorData = (rawData) => { |
|
|
let href = rawData[index + 1].template_name === 'textNav' ?
|
|
|
rawData.slice(index, index + 2) : data;
|
|
|
|
|
|
floorData = floorMap.floorTitle.call(null, href);
|
|
|
floorData = this.floorMap.floorTitle.call(null, href);
|
|
|
}
|
|
|
|
|
|
} else if (data && data.template_name === 'jk_floor') { // 左1大图,右6小图,title
|
|
|
floorData = floorMap.jacket.call(null, data.data);
|
|
|
floorData = this.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 = 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 = floorMap.ad.call(null, data.data);
|
|
|
floorData = this.floorMap.ad.call(null, data.data);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -921,7 +926,7 @@ const _processJKFloorData = (rawData) => { |
|
|
singlehotFloorIndex.push(floorList.length);
|
|
|
|
|
|
// 记住楼层标题, 以便后面promise获取数据后插入楼层数据
|
|
|
singlehotFloorTitle.push(_getText(data.data.text));
|
|
|
singlehotFloorTitle.push(this._getText(data.data.text));
|
|
|
} else if (!_.isNil(floorData)) {
|
|
|
_.isArray(floorData) ?
|
|
|
floorList = floorList.concat(floorData) :
|
...
|
...
|
@@ -938,10 +943,15 @@ const _processJKFloorData = (rawData) => { |
|
|
singlehotFloorTitle: _.reverse(singlehotFloorTitle),
|
|
|
singlehotFloorIndex: _.reverse(singlehotFloorIndex)
|
|
|
};
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const _formatResourceParams = (channel, code) => {
|
|
|
return serviceApi.get('operations/api/v5/resource/get', {content_code: code}, config.apiCache).then(data => {
|
|
|
_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) {
|
...
|
...
|
@@ -950,14 +960,14 @@ const _formatResourceParams = (channel, code) => { |
|
|
|
|
|
return result || {};
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 频道页首次登陆导航并行调接口数据
|
|
|
* @param {Object} data
|
|
|
* @return {Object} formatData
|
|
|
*/
|
|
|
const _formatParams = (channel, data) => {
|
|
|
_formatParams(channel, data) {
|
|
|
let params = {};
|
|
|
|
|
|
// 排序数据映射表
|
...
|
...
|
@@ -1005,7 +1015,7 @@ const _formatParams = (channel, data) => { |
|
|
params = Object.assign(data);
|
|
|
}
|
|
|
|
|
|
return searchApi.getProductList(params).then(result => {
|
|
|
return this.searchApi.getProductList(params).then(result => {
|
|
|
let ret = result.data;
|
|
|
|
|
|
if (ret) {
|
...
|
...
|
@@ -1014,14 +1024,14 @@ const _formatParams = (channel, data) => { |
|
|
|
|
|
return ret;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 格式化频道页首次登陆导航数据
|
|
|
* @param {Object} data
|
|
|
* @return {Object} formatData
|
|
|
*/
|
|
|
const formatIndexGuideData = data => {
|
|
|
formatIndexGuideData(data) {
|
|
|
let channels = {
|
|
|
boys: {gender: '1,3', limit: 1},
|
|
|
girls: {gender: '2,3', limit: 1},
|
...
|
...
|
@@ -1045,7 +1055,7 @@ const formatIndexGuideData = data => { |
|
|
});
|
|
|
|
|
|
if (channels[channel]) {
|
|
|
promiseArr.push(_formatParams(channel, channels[channel]));
|
|
|
promiseArr.push(this._formatParams(channel, channels[channel]));
|
|
|
}
|
|
|
});
|
|
|
|
...
|
...
|
@@ -1060,22 +1070,21 @@ const formatIndexGuideData = data => { |
|
|
|
|
|
return formatData;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取最新上架商品数据
|
|
|
*
|
|
|
* @param string $channel
|
|
|
* @return array
|
|
|
*/
|
|
|
const getNewArrival = (channel, isJKChannel, poolId)=> {
|
|
|
getNewArrival(channel, isJKChannel, poolId) {
|
|
|
let rel = [],
|
|
|
sortList = sortMap[channel],
|
|
|
params = {},
|
|
|
method = '';
|
|
|
|
|
|
|
|
|
|
|
|
if (isJKChannel) {
|
|
|
method = 'app.search.sales';
|
|
|
params = {
|
...
|
...
|
@@ -1104,9 +1113,12 @@ const getNewArrival = (channel, isJKChannel, poolId)=> { |
|
|
_.forEach(sortList, (item) => {
|
|
|
let data = Object.assign(item, params, {limit: item.viewNum});
|
|
|
|
|
|
rel.push(api.get('', Object.assign({
|
|
|
rel.push(this.get({
|
|
|
data: Object.assign({
|
|
|
method: method
|
|
|
}, data), {cache: true}));
|
|
|
}, data),
|
|
|
param: {cache: true}
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
return Promise.all(rel).then(res => {
|
...
|
...
|
@@ -1130,22 +1142,22 @@ const getNewArrival = (channel, isJKChannel, poolId)=> { |
|
|
});
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取频道页数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const getContent = (type, isJKChannel, poolId) => {
|
|
|
getContent(type, isJKChannel, poolId) {
|
|
|
|
|
|
let params = {new_device: 'Y'};
|
|
|
|
|
|
return Promise.all([
|
|
|
headerModel.requestHeaderData(type),
|
|
|
_requestContent(type, params),
|
|
|
getNewArrival(type, isJKChannel, poolId)
|
|
|
this._requestContent(type, params),
|
|
|
this.getNewArrival(type, isJKChannel, poolId)
|
|
|
]).then(res => {
|
|
|
|
|
|
let headerData = res[0].data || res[0],
|
...
|
...
|
@@ -1153,7 +1165,7 @@ const getContent = (type, isJKChannel, poolId) => { |
|
|
|
|
|
let data = {};
|
|
|
|
|
|
const processResult = _processFloorData(contentData, type);
|
|
|
const processResult = this._processFloorData(contentData, type);
|
|
|
|
|
|
data = headerData;
|
|
|
data.module = 'channel';
|
...
|
...
|
@@ -1187,7 +1199,7 @@ const getContent = (type, isJKChannel, poolId) => { |
|
|
_.forEach(res, (data, index) => {
|
|
|
result.floorData.channel
|
|
|
.splice(result.singlehotFloorIndex[index], 0,
|
|
|
_processFloorDataWithQueryReusult(
|
|
|
this._processFloorDataWithQueryReusult(
|
|
|
result.rawData,
|
|
|
result.queryParams[index],
|
|
|
data,
|
...
|
...
|
@@ -1202,21 +1214,21 @@ const getContent = (type, isJKChannel, poolId) => { |
|
|
|
|
|
return result.floorData || result;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取日韩馆频道页数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const getJKContent = (req) => {
|
|
|
getJKContent(req) {
|
|
|
let channel = req.query.channel || req.yoho.channel || 'boys',
|
|
|
contentCode = req.query.content_code;
|
|
|
|
|
|
return Promise.all([
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
_requestContent(channel, {}, contentCode),
|
|
|
getNewArrival(channel, true, req.query.template_id)
|
|
|
this._requestContent(channel, {}, contentCode),
|
|
|
this.getNewArrival(channel, true, req.query.template_id)
|
|
|
]).then(res => {
|
|
|
|
|
|
let headerData = res[0].data || res[0],
|
...
|
...
|
@@ -1224,7 +1236,7 @@ const getJKContent = (req) => { |
|
|
|
|
|
let data = {};
|
|
|
|
|
|
const processResult = _processJKFloorData(contentData);
|
|
|
const processResult = this._processJKFloorData(contentData);
|
|
|
|
|
|
data = headerData;
|
|
|
data.module = 'channel';
|
...
|
...
|
@@ -1259,7 +1271,7 @@ const getJKContent = (req) => { |
|
|
_.forEach(res, (data, index) => {
|
|
|
result.floorData.channel
|
|
|
.splice(result.singlehotFloorIndex[index], 0,
|
|
|
_processFloorDataWithQueryReusult(
|
|
|
this._processFloorDataWithQueryReusult(
|
|
|
result.rawData,
|
|
|
result.queryParams[index],
|
|
|
data,
|
...
|
...
|
@@ -1274,14 +1286,14 @@ const getJKContent = (req) => { |
|
|
|
|
|
return result.floorData || result;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const getResourceData = (formatData) => {
|
|
|
getResourceData(formatData) {
|
|
|
let promiseArr = [];
|
|
|
|
|
|
_.forEach(formatData, item => {
|
|
|
if (item.content_code) {
|
|
|
promiseArr.push(_formatResourceParams(item.channel, item.content_code));
|
|
|
promiseArr.push(this._formatResourceParams(item.channel, item.content_code));
|
|
|
}
|
|
|
});
|
|
|
return Promise.all(promiseArr).then(data => {
|
...
|
...
|
@@ -1295,26 +1307,31 @@ const getResourceData = (formatData) => { |
|
|
|
|
|
return formatData;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 获取频道页首次登陆导航数据
|
|
|
* @param {String} type 传入频道页类型,值可以是: boys, girls, kids, lifestyle
|
|
|
* @return {Object}
|
|
|
*/
|
|
|
const getIndexGuideData = () => {
|
|
|
getIndexGuideData() {
|
|
|
let params = {
|
|
|
client_type: 'web',
|
|
|
private_key: '0ed29744ed318fd28d2c07985d3ba633'
|
|
|
};
|
|
|
|
|
|
return serviceApi.get('operations/api/v6/category/getCategory', params, config.apiCache);
|
|
|
};
|
|
|
return this.get({
|
|
|
url: 'operations/api/v6/category/getCategory',
|
|
|
data: params,
|
|
|
param: config.apiCache,
|
|
|
api: global.yoho.ServiceAPI
|
|
|
});
|
|
|
}
|
|
|
|
|
|
const hasNewUserFloor = (channelType, uid) => {
|
|
|
hasNewUserFloor(channelType, uid) {
|
|
|
let params = {uid: uid};
|
|
|
|
|
|
return _requestContent(channelType, params).then(res => {
|
|
|
return this._requestContent(channelType, params).then(res => {
|
|
|
let isNewUser = false,
|
|
|
contentData = res.data ? res.data.list : res;
|
|
|
|
...
|
...
|
@@ -1329,16 +1346,5 @@ const hasNewUserFloor = (channelType, uid) => { |
|
|
isNewUser: isNewUser
|
|
|
};
|
|
|
});
|
|
|
};
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
getNewArrival: getNewArrival,
|
|
|
getContent: getContent,
|
|
|
getJKContent: getJKContent,
|
|
|
getIndexGuideData: getIndexGuideData,
|
|
|
formatIndexGuideData: formatIndexGuideData,
|
|
|
getResourceData: getResourceData,
|
|
|
hasNewUserFloor: hasNewUserFloor
|
|
|
|
|
|
}
|
|
|
}; |
...
|
...
|
|