Authored by 姜枫

handle merge

... ... @@ -5,6 +5,7 @@
*/
'use strict';
const _ = require('lodash');
const Item = require('../models/item');
const index = (req, res, next) => {
... ... @@ -241,6 +242,9 @@ const index = (req, res, next) => {
// };
Item.getProductItemData(req.params).then(result => {
if (_.isEmpty(result)) {
return next();
}
res.display('item', result);
}).catch(next);
};
... ...
... ... @@ -31,7 +31,7 @@ const getsizeInfoAsync = (skn) => {
}, { cache: true });
};
const getProductComfort = productId => {
const getComfortAsync = productId => {
return api.get('', {
method: 'web.productComfort.data',
product_id: productId
... ... @@ -42,8 +42,19 @@ const getProductComfort = productId => {
};
const getModelTryAsync = skn => {
return api.get('', {
method: 'web.productModelTry.data',
product_skn: skn
}, {
cache: true,
code: 200
});
};
module.exports = {
getProductBaseAsync,
getsizeInfoAsync,
getProductComfort
getComfortAsync,
getModelTryAsync
};
... ...
... ... @@ -9,13 +9,91 @@ const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
* 使sizeBoList id以 sizeAttributeBos id顺序一样
* @param sizeInfoBo
*/
const _sizeInfoBoSort = sizeInfoBo => {
if (!sizeInfoBo.sizeBoList || !sizeInfoBo.sizeAttributeBos) {
return {};
}
// TODO: 这里的排序代码很乱
_.forEach(sizeInfoBo.sizeBoList, (sizeBoList, sizek)=> {
let sortAttr = {};
_.forEach(sizeBoList.sortAttributes, sortAttributes => {
sortAttr[sortAttributes.id] = sortAttributes;
});
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
});
_.forEach(sizeInfoBo.sizeBoList, (sizeBoList, sizek)=> {
let sortAttr = [];
_.forEach(sizeInfoBo.sizeAttributeBos, val => {
sortAttr.push(sizeBoList.sortAttributes[val.id]);
});
sizeInfoBo.sizeBoList[sizek].sortAttributes = sortAttr;
});
return sizeInfoBo;
};
const setPathNav = (data, name) => {
let resData = {};
if (!_.isEmpty(data)) {
let navs = [];
let sort = data.sort[0];
navs.push({
link: helpers.urlFormat('/list', {
msort: sort.sort_id
// gender: '' // 待处理
}),
name: sort.sort_name,
pathTitle: sort.sort_name
});
// 二级分类
if (!_.isEmpty(sort.sub)) {
navs.push({
link: helpers.urlFormat('/list', {
msort: sort.sort_id,
misort: sort.sub.sort_id
// gender: '' // 待处理
}),
name: sort.sub[0].sort_name,
pathTitle: sort.sub[0].sort_name
});
}
navs.push({
name: name,
pathTitle: name
});
resData.nav = navs;
}
return resData;
};
/**
* 设置品牌banner数据
* @param brand 品牌相关数据
* @return Object
*/
const setBrandBanner = brand => {
let data = {
bgColor: '#93897d',
bgColor: '#000',
brandLogo: {
link: `#${brand.brandDomain}`, // 品牌跳转链接 -- 待处理
img: brand.brandIco
... ... @@ -166,10 +244,11 @@ const setBrandIntro = brand => {
/**
* 设置商品描述
* @param brand 品牌相关数据
* @param sizeInfo
* @param comfortInfo
* @return Object
*/
const setDescriptionInfo = (sizeInfo, comfortInfo) => {
const setDescriptionData = (sizeInfo, comfortInfo) => {
let resData = {};
if (_.has(sizeInfo, 'productDescBo.erpProductId')) {
... ... @@ -198,7 +277,7 @@ const setDescriptionInfo = (sizeInfo, comfortInfo) => {
];
if (_.isArray(sizeInfo.productDescBo.standardBos)) {
_.forEach(sizeInfo.productDescBo.standardBos, function(value) {
_.forEach(sizeInfo.productDescBo.standardBos, value => {
basic.push({
key: value.standardName,
value: value.standardVal
... ... @@ -211,7 +290,7 @@ const setDescriptionInfo = (sizeInfo, comfortInfo) => {
if (comfortInfo) {
let comfort = [];
_.forEach(comfortInfo, function(value) {
_.forEach(comfortInfo, value => {
let i = 1;
let blocks = [];
let flag = false;
... ... @@ -249,9 +328,243 @@ const setDescriptionInfo = (sizeInfo, comfortInfo) => {
return resData;
};
/**
* 设置洗涤材质信息
* @param sizeInfo
* @return Object
*/
const setMaterialData = sizeInfo => {
let resData = {};
let material = {};
// 洗涤提示
if (sizeInfo.washTipsBoList) {
let wash = [];
_.forEach(sizeInfo.washTipsBoList, value => {
wash.push({
name: value.caption,
img: value.img
});
});
if (!_.isEmpty(wash)) {
material.wash = wash;
}
}
// 商品材质[洗涤说明]
if (sizeInfo.productMaterialList) {
let detail = [];
_.forEach(sizeInfo.productMaterialList, value => {
detail.push({
img: value.imageUrl,
name: value.caption,
enName: value.encaption,
text: value.remark
});
});
if (!_.isEmpty(detail)) {
material.detail = detail;
}
}
if (!_.isEmpty(material)) {
Object.assign(material, {
titleEn: 'MATERIALS',
titleCn: '材料洗涤'
});
resData.material = material;
}
return resData;
};
/**
* 设置尺寸信息
* @param sizeInfo
* @return Object
*/
const setSizeData = (sizeInfo) => {
let resData = {};
if (sizeInfo.sizeInfoBo) {
let referenceName,
boyReference,
girlReference,
gender;
let size = {
titleEn: 'SIZEINFO',
titleCn: '尺码信息'
};
sizeInfo.sizeInfoBo = _sizeInfoBoSort(sizeInfo.sizeInfoBo);
// 参考尺码
if (_.has(sizeInfo, 'productExtra')) {
boyReference = sizeInfo.productExtra.boyReference;
girlReference = sizeInfo.productExtra.girlReference;
}
gender = _.has(sizeInfo, 'productDescBo.gender') ? sizeInfo.productDescBo.gender : 3;
if (gender === 3 && boyReference) {
referenceName = '参考尺码(男)';
} else if (gender === 3 && girlReference) {
referenceName = '参考尺码(女)';
} else {
referenceName = '参考尺码';
}
// 判断是否显示参考尺码
let showReference = (boyReference && _.get(sizeInfo.sizeInfoBo, 'sizeBoList[0].boyReferSize', false)) ||
(girlReference && _.get(sizeInfo.sizeInfoBo, 'sizeBoList[0].girlReferSize', false));
if (sizeInfo.sizeInfoBo.sizeAttributeBos) {
let sizeTable = {};
// 尺码信息头部
sizeTable.thead = [{name: '吊牌尺码', id: '', width: 126}];
// 显示参考尺码
if (showReference) {
sizeTable.thead.push({name: referenceName, id: '', width: 126});
}
_.forEach(sizeInfo.sizeInfoBo.sizeAttributeBos, value => {
sizeTable.thead.push({
name: value.attributeName || ' ',
id: value.id,
width: 126
});
});
sizeTable.tbody = [];
_.forEach(sizeInfo.sizeInfoBo.sizeBoList, value => {
let sizes = [];
// 吊牌尺码
sizes.push(value.sizeName);
// 判断是否显示参考尺码
if (boyReference && (gender === 1 || gender === 3) && showReference) {
sizes.push(value.boyReferSize.referenceName || ' ');
} else if (girlReference && (gender === 2 || gender === 3) && showReference) {
sizes.push(value.girlReferSize.referenceName || ' ');
} else {
if (sizeTable.thead[1] && showReference) {
sizeTable.thead[1] = {};
}
}
// 其他尺码信息
value.sortAttributes.forEach(attr => {
sizes.push((attr.sizeValue || ' '));
});
// 尺码信息
sizeTable.tbody.push(sizes);
});
// 参考尺码为空
if (_.isEmpty(sizeTable.thead[1]) && showReference) {
// 移除这个值
sizeTable.thead.splice(1, 1);
}
size.param = sizeTable;
}
if (!_.isEmpty(sizeInfo.modelBos)) {
let tasteTable = {};
tasteTable.thead = [
{name: '模特', width: 170},
{name: '身高', width: 126},
{name: '体重', width: 126},
{name: '三围', width: 126},
{name: '吊牌尺码', width: 126},
{name: '试穿描述', width: 126}
];
tasteTable.tbody = [];
_.forEach(sizeInfo.modelBos, value => {
let modelInfo = [
value.avatar, value.modelName, value.height,
value.weight, value.vitalStatistics, value.fitModelBo.fit_size,
value.fitModelBo.feel
];
// 是否有备注
if (_.get(value, 'fitModelBo.fit_remark', false)) {
modelInfo.push(value.fitModelBo.fit_remark);
tasteTable.thead[7] = {name: '备注', width: 170};
}
tasteTable.tbody.push(modelInfo);
});
size.taste = tasteTable;
}
resData.sizeInfo = size;
}
return resData;
};
/**
* 设置商品详情页介绍
*
* @param array sizeInfo
* @return string
*/
const setDetailData = sizeInfo => {
let resData = {};
// 详情配图
if (_.has(sizeInfo, 'productIntroBo.productIntro')) {
let details = {
titleEn: 'DETAILS',
titleCn: '商品详情'
};
if (sizeInfo.productDescBo && sizeInfo.productDescBo.phrase) {
details.content = `${sizeInfo.productDescBo.phrase}<br/>`;
}
// 图片换规则
const replacePairs = [
{
reg: /<img src=/g,
str: '<img class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f' +
'///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
},
{
reg: /<img border="0" src=/g,
str: '<img border="0" class="lazy" src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP' +
'///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" data-original='
}
];
let content = sizeInfo.productIntroBo.productIntro;
// 图片换成懒加载方式
_.forEach(replacePairs, value => {
content = _.replace(content, value.reg, value.str);
});
details.content += content;
resData.details = details;
}
return resData;
};
module.exports = {
setBrandBanner,
setPathNav,
setProductData,
setBrandIntro,
setDescriptionInfo
setDescriptionData,
setMaterialData,
setSizeData,
setDetailData
};
... ...
... ... @@ -8,6 +8,8 @@
const itemAPI = require('./item-api');
const itemFUN = require('./item-handler');
const search = require('./search-api');
const _getMultiResourceByBaseInfo = (base, uid) => {
let productId = base.id;
let skn = base.erpProductId;
... ... @@ -17,7 +19,9 @@ const _getMultiResourceByBaseInfo = (base, uid) => {
// 获取相关数据
let promiseData = [
itemAPI.getsizeInfoAsync(skn),
itemAPI.getProductComfort(productId)
itemAPI.getComfortAsync(productId),
itemAPI.getModelTryAsync(skn),
search.getSortAsync({sort: base.smallSortId})
];
if (uid) {
... ... @@ -29,7 +33,9 @@ const _getMultiResourceByBaseInfo = (base, uid) => {
return Promise.all(promiseData).then(result => {
return {
sizeInfo: result[0],
comfort: result[1].data
comfort: result[1].data,
modelTry: result[2].data,
sort: result[3].data
};
});
};
... ... @@ -49,9 +55,7 @@ let getProductItemData = (params) => {
}
// 商品基本信息
Object.assign(data, {
goodInfo: itemFUN.setProductData(result)
});
data.goodInfo = itemFUN.setProductData(result);
if (result.brand) {
Object.assign(data, itemFUN.setBrandBanner(result.brand));
... ... @@ -61,9 +65,20 @@ let getProductItemData = (params) => {
}
return _getMultiResourceByBaseInfo(result).then(mulRes => {
// 设置商品描述
Object.assign(data, itemFUN.setDescriptionInfo(mulRes.sizeInfo, mulRes.comfort));
// 面包屑导航
Object.assign(data, itemFUN.setPathNav(mulRes.sort, result.productName));
// DESCRIPTION商品描述
Object.assign(data, itemFUN.setDescriptionData(mulRes.sizeInfo, mulRes.comfort));
// MATERIALS材料洗涤
Object.assign(data, itemFUN.setMaterialData(mulRes.sizeInfo));
// SIZEINFO尺码信息
Object.assign(data, itemFUN.setSizeData(mulRes.sizeInfo, mulRes.modelTry));
// DETAILS商品详情
Object.assign(data, itemFUN.setDetailData(mulRes.sizeInfo));
return data;
});
... ...
// 由于目前没有相关java接口,暂时调search
'use strict';
const api = global.yoho.SearchAPI;
const getSortAsync = (condition) => {
return api.get('sortgroup.json', condition, {
code: 200
});
};
module.exports = {
getSortAsync
};
... ...
... ... @@ -19,8 +19,8 @@ module.exports = {
},
cookieDomain: 'yohoblk.com',
domains: {
api: 'http://api.yoho.cn/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service: 'http://service.yoho.cn/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
api: 'http://testapi.yoho.cn:28078/', // devapi.yoho.cn:58078 testapi.yoho.cn:28078 devapi.yoho.cn:58078
service: 'http://testservice.yoho.cn:28077/', // testservice.yoho.cn:28077 devservice.yoho.cn:58077
search: 'http://192.168.102.216:8080/yohosearch/'
},
useOneapm: false,
... ...
... ... @@ -270,6 +270,10 @@
margin-left: 20px;
}
}
.detail-content {
text-align: center;
}
}
.info-block {
... ...