Authored by 周少峰

Merge branch 'release/5.0.0' of git.yoho.cn:fe/yohobuy-node into release/5.0.0

... ... @@ -5,6 +5,8 @@
'use strict';
const _ = require('lodash');
const Fn = require('lodash/fp');
const qs = require('queryString');
const helpers = global.yoho.helpers;
... ... @@ -72,21 +74,25 @@ const goodsTabBar = (data, shopId) => {
new: []
};
_.forEach(data.hot, (value) => {
if (value.url) {
_.forEach(_.sortBy(data.hot, o => {
return -o.position;
}), (value) => {
if (value.url && value.position) {
dest.hot.push({
name: value.name,
href: value.url
url: value.url
});
}
});
_.forEach(data.new, (value) => {
if (value.url) {
_.forEach(_.sortBy(data.new, o => {
return -o.position;
}), (value) => {
if (value.url && value.position) {
dest.new.push({
name: value.name,
href: value.url
url: value.url
});
}
});
... ... @@ -150,9 +156,16 @@ const navigationBar = (data, shopId) => {
}
];
return {navigationBar: _.union(shopNav, _.filter(data, (value) => {
return value.url;
}))};
_.forEach(data, (value) => {
if (value.url) {
shopNav.push({
name: value.name,
url: `${value.url}&navBar=${shopNav.length}`
});
}
});
return {navigationBar: shopNav};
};
/**
... ... @@ -160,24 +173,14 @@ const navigationBar = (data, shopId) => {
* @param type $data
* @return type []
*/
const largeSlideImg = (data, shopId) => {
const largeSlideImg = (data) => {
let dest = [];
_.forEach(data, (value) => {
let url;
value = _.get(value, 'data[0]', {});
url = value.url;
if (+value.categoryId > 0) {
if (!url) {
url = `${shopListUrl}?shopId=${shopId}`;
}
url += `&productPool=${value.categoryId}`;
}
dest.push({
img: value.src,
url: url
url: value.url
});
});
... ... @@ -189,24 +192,14 @@ const largeSlideImg = (data, shopId) => {
* @param data 装修数据
* @returns {{}}
*/
const oneRowTwoColImages = (data, shopId) => {
const oneRowTwoColImages = (data) => {
let dest = [];
_.forEach(data, (value) => {
let url;
value = _.get(value, 'data[0]', {});
url = value.url;
if (+value.categoryId > 0) {
if (!url) {
url = `${shopListUrl}?shopId=${shopId}`;
}
url += `&productPool=${value.categoryId}`;
}
dest.push({
img: value.src,
url: url
url: value.url
});
});
return {oneRowTwoColImages: dest};
... ... @@ -217,21 +210,16 @@ const oneRowTwoColImages = (data, shopId) => {
* @param type $data
* @return type []
*/
const recommend = (data, shopId) => {
const recommend = (data) => {
let dest = [];
_.forEach(data, (value) => {
let url = value.url || `${shopListUrl}?shopId=${shopId}`;
if (+value.categoryId > 0) {
url += `&productPool=${value.categoryId}`;
}
dest.push({
enName: value.enName,
name: value.name,
img: value.src,
title: value.title,
url: url
url: value.url
});
});
... ... @@ -323,6 +311,38 @@ const signboard = (data) => {
};
};
// 销售类目
const _handleSaleCategory = (shopId, resourceObj) => {
const thisShop = (categoryId) => shopListUrl + '?' + qs.stringify({
productPool: categoryId,
shopId: shopId,
navBar: -1
});
let hasSaleCategory = Fn.pipe(Fn.prop('linkType'), Fn.eq('1'));
if (hasSaleCategory(resourceObj)) {
return Object.assign(resourceObj, {url: thisShop(resourceObj.categoryId)});
}
_(resourceObj).forEach((value) => {
if (_.has(value, 'data')) {
_.forEach(value.data, (it) => {
if (hasSaleCategory(it)) {
Object.assign(it, {url: thisShop(it.categoryId)});
}
});
}
if (hasSaleCategory(value)) {
Object.assign(value, {url: thisShop(value.categoryId)});
}
});
return resourceObj;
};
/**
* 店铺装修楼层数据
* @param data 装修数据
... ... @@ -333,7 +353,7 @@ exports.getShopDecorator = (data, params, shopId, base) => {
if (base) {
_.forEach(data.list, (value) => {
let info = JSON.parse(value.resource_data);
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
switch (value.resource_name) {
case 'signboard':
... ... @@ -351,9 +371,9 @@ exports.getShopDecorator = (data, params, shopId, base) => {
newArrivel: {},
hotSingle: {}
});
_.forEach(data.list, (value) => {
let info = JSON.parse(value.resource_data);
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
let tabBar;
switch (value.resource_name) {
... ...