...
|
...
|
@@ -5,6 +5,8 @@ |
|
|
|
|
|
'use strict';
|
|
|
const _ = require('lodash');
|
|
|
const Fn = require('lodash/fp');
|
|
|
const qs = require('queryString');
|
|
|
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
...
|
...
|
@@ -68,32 +70,34 @@ const hotProducts = (data) => { |
|
|
*/
|
|
|
const goodsTabBar = (data, shopId) => {
|
|
|
let dest = {
|
|
|
hot: [],
|
|
|
new: []
|
|
|
},
|
|
|
more = {name: 'MORE', href: shopListUrl + '?shopId=' + shopId};
|
|
|
|
|
|
hot: [],
|
|
|
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
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
dest.hot.push(more);
|
|
|
dest.new.push(more);
|
|
|
dest.hot.push({name: 'MORE', url: `${shopListUrl}?navBar=2&order=s_n_desc&shopId=${shopId}`});
|
|
|
dest.new.push({name: 'MORE', url: `${shopListUrl}?navBar=3&order=s_t_desc&shopId=${shopId}`});
|
|
|
return dest;
|
|
|
};
|
|
|
|
...
|
...
|
@@ -144,17 +148,24 @@ const navigationBar = (data, shopId) => { |
|
|
},
|
|
|
{
|
|
|
name: '人气单品',
|
|
|
url: `${shopListUrl}/?navBar=2&shopId=${shopId}`
|
|
|
url: `${shopListUrl}/?navBar=2&order=s_n_desc&shopId=${shopId}`
|
|
|
},
|
|
|
{
|
|
|
name: '新品上架',
|
|
|
url: `${shopListUrl}/?navBar=3&shopId=${shopId}`
|
|
|
url: `${shopListUrl}/?navBar=3&order=s_t_desc&shopId=${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};
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -166,9 +177,10 @@ const largeSlideImg = (data) => { |
|
|
let dest = [];
|
|
|
|
|
|
_.forEach(data, (value) => {
|
|
|
value = _.get(value, 'data[0]', {});
|
|
|
dest.push({
|
|
|
img: value.data[0].src,
|
|
|
url: helpers.urlFormat(value.data[0].url)
|
|
|
img: value.src,
|
|
|
url: value.url
|
|
|
});
|
|
|
});
|
|
|
|
...
|
...
|
@@ -184,9 +196,10 @@ const oneRowTwoColImages = (data) => { |
|
|
let dest = [];
|
|
|
|
|
|
_.forEach(data, (value) => {
|
|
|
value = _.get(value, 'data[0]', {});
|
|
|
dest.push({
|
|
|
img: value.data[0].src,
|
|
|
url: helpers.urlFormat(value.data[0].url)
|
|
|
img: value.src,
|
|
|
url: value.url
|
|
|
});
|
|
|
});
|
|
|
return {oneRowTwoColImages: dest};
|
...
|
...
|
@@ -206,7 +219,7 @@ const recommend = (data) => { |
|
|
name: value.name,
|
|
|
img: value.src,
|
|
|
title: value.title,
|
|
|
url: helpers.urlFormat(value.url)
|
|
|
url: value.url
|
|
|
});
|
|
|
});
|
|
|
|
...
|
...
|
@@ -277,62 +290,130 @@ const hotRecommend = (data) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 店铺装修楼层数据
|
|
|
* @param data 装修数据
|
|
|
* @returns {{}}
|
|
|
* 水牌
|
|
|
*/
|
|
|
exports.getShopDecorator = (data, params, shopId) => {
|
|
|
let dest = {
|
|
|
newArrivel: {},
|
|
|
hotSingle: {}
|
|
|
const signboard = (data) => {
|
|
|
let list = [];
|
|
|
|
|
|
_.forEach(data, value => {
|
|
|
if (value.data) {
|
|
|
_.forEach(value.data, val => {
|
|
|
list.push({
|
|
|
img: helpers.image(val.src, 160, 240),
|
|
|
url: val.url
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
return {
|
|
|
title: _.get(list, '[0].title', ''),
|
|
|
list: list
|
|
|
};
|
|
|
};
|
|
|
|
|
|
_.forEach(data.list, (value) => {
|
|
|
let info = JSON.parse(value.resource_data);
|
|
|
let tabBar;
|
|
|
|
|
|
switch (value.resource_name) {
|
|
|
case 'signboard':
|
|
|
break;
|
|
|
case 'newProducts':
|
|
|
Object.assign(dest.newArrivel, newProducts(info));
|
|
|
break;
|
|
|
case 'hotProducts':
|
|
|
Object.assign(dest.hotSingle, hotProducts(info));
|
|
|
break;
|
|
|
case 'goodsTabBar':
|
|
|
tabBar = goodsTabBar(info);
|
|
|
Object.assign(dest.newArrivel, {navs: tabBar.new});
|
|
|
Object.assign(dest.hotSingle, {navs: tabBar.hot});
|
|
|
break;
|
|
|
case 'shopTopBanner':
|
|
|
Object.assign(dest, shopTopBanner(info));
|
|
|
break;
|
|
|
case 'shopTopBanner_base':
|
|
|
Object.assign(dest, shopTopBannerBase(info));
|
|
|
break;
|
|
|
case 'navigationBar':
|
|
|
Object.assign(dest, navigationBar(info, shopId));
|
|
|
break;
|
|
|
case 'largeSlideImg':
|
|
|
Object.assign(dest, largeSlideImg(info));
|
|
|
break;
|
|
|
case 'oneRowTwoColImages':
|
|
|
Object.assign(dest, oneRowTwoColImages(info, shopId));
|
|
|
break;
|
|
|
case 'recommend':
|
|
|
Object.assign(dest, recommend(info, shopId));
|
|
|
break;
|
|
|
case 'brandBrowse':
|
|
|
Object.assign(dest, brandBrowse(info, params));
|
|
|
break;
|
|
|
case 'hotRecommend':
|
|
|
Object.assign(dest, hotRecommend(info));
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
|
|
|
// 销售类目
|
|
|
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 装修数据
|
|
|
* @returns {{}}
|
|
|
*/
|
|
|
exports.getShopDecorator = (data, params, shopId, base) => {
|
|
|
let dest = {};
|
|
|
|
|
|
if (base) {
|
|
|
_.forEach(data.list, (value) => {
|
|
|
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
|
|
|
|
|
|
switch (value.resource_name) {
|
|
|
case 'signboard':
|
|
|
dest.signboard = signboard(info);
|
|
|
break;
|
|
|
case 'shopTopBanner_base':
|
|
|
Object.assign(dest, shopTopBannerBase(info));
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
});
|
|
|
} else {
|
|
|
Object.assign(dest, {
|
|
|
newArrivel: {},
|
|
|
hotSingle: {}
|
|
|
});
|
|
|
|
|
|
_.forEach(data.list, (value) => {
|
|
|
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
|
|
|
let tabBar;
|
|
|
|
|
|
switch (value.resource_name) {
|
|
|
case 'newProducts':
|
|
|
Object.assign(dest.newArrivel, newProducts(info));
|
|
|
break;
|
|
|
case 'hotProducts':
|
|
|
Object.assign(dest.hotSingle, hotProducts(info));
|
|
|
break;
|
|
|
case 'goodsTabBar':
|
|
|
tabBar = goodsTabBar(info, shopId);
|
|
|
Object.assign(dest.newArrivel, {navs: tabBar.new});
|
|
|
Object.assign(dest.hotSingle, {navs: tabBar.hot});
|
|
|
break;
|
|
|
case 'shopTopBanner':
|
|
|
Object.assign(dest, shopTopBanner(info));
|
|
|
break;
|
|
|
case 'navigationBar':
|
|
|
Object.assign(dest, navigationBar(info, shopId));
|
|
|
break;
|
|
|
case 'largeSlideImg':
|
|
|
Object.assign(dest, largeSlideImg(info, shopId));
|
|
|
break;
|
|
|
case 'oneRowTwoColImages':
|
|
|
Object.assign(dest, oneRowTwoColImages(info, shopId));
|
|
|
break;
|
|
|
case 'recommend':
|
|
|
Object.assign(dest, recommend(info, shopId));
|
|
|
break;
|
|
|
case 'brandBrowse':
|
|
|
Object.assign(dest, brandBrowse(info, params));
|
|
|
break;
|
|
|
case 'hotRecommend':
|
|
|
Object.assign(dest, hotRecommend(info));
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return dest;
|
|
|
}; |
...
|
...
|
|