...
|
...
|
@@ -6,263 +6,8 @@ const _ = require('lodash'); |
|
|
const commentModel = require('./consult-comment');
|
|
|
const bundle = require('./bundle');
|
|
|
const utils = '../../../utils';
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
|
|
|
|
|
|
const detailProcess = require(`${utils}/detail-process`);
|
|
|
const api = global.yoho.API;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const tool = {
|
|
|
prodessDetailData(origin) {
|
|
|
let dest = {}; // 结果输出
|
|
|
|
|
|
// 商品名称
|
|
|
if (!origin.product_name) {
|
|
|
return dest;
|
|
|
}
|
|
|
|
|
|
dest.goodsName = origin.product_name;
|
|
|
|
|
|
// 是否是虚拟商品
|
|
|
// dest.virtualGoods = (origin.attribute * 1 === 3);
|
|
|
|
|
|
// 活动促销短语
|
|
|
origin.market_phrase && origin.market_phrase !== ' ' && (dest.marketPhrase = origin.market_phrase);
|
|
|
|
|
|
// 商品促销短语
|
|
|
origin.sales_phrase && origin.sales_phrase !== ' ' && (dest.goodsSubtitle = origin.sales_phrase);
|
|
|
|
|
|
// 商品标签
|
|
|
if (origin.tags) {
|
|
|
let productTags = {};
|
|
|
|
|
|
_.forEach(origin.tags, function(value) {
|
|
|
productTags[value] = true;
|
|
|
});
|
|
|
|
|
|
dest.tags = productTags;
|
|
|
}
|
|
|
|
|
|
// 商品价格
|
|
|
let goodsPrice = {
|
|
|
currentPrice: origin.format_sales_price === '0' ? origin.format_market_price : origin.format_sales_price
|
|
|
};
|
|
|
|
|
|
if (origin.format_sales_price !== '0' && origin.format_market_price !== origin.format_sales_price) {
|
|
|
goodsPrice.previousPrice = origin.format_market_price;
|
|
|
}
|
|
|
|
|
|
dest.goodsPrice = goodsPrice;
|
|
|
|
|
|
// 商品返回 YOHO 币
|
|
|
// origin.yohoCoinNum && (dest.commodityReturn = origin.yohoCoinNum);
|
|
|
|
|
|
// 上市期
|
|
|
origin.expect_arrival_time && (dest.periodOfMarket = origin.expect_arrival_time);
|
|
|
|
|
|
|
|
|
// 品牌信息
|
|
|
if (origin.shop_id) {
|
|
|
let extra = `?productSkn=${origin.product_skn}&shopId=${origin.shop_id}`;
|
|
|
|
|
|
dest.preferenceUrl = `/product/detail/preference${extra}`;
|
|
|
}
|
|
|
|
|
|
// dest.brandId = origin.brand_info && origin.brand_info.brand_id || 0;
|
|
|
dest.brandId = _.get(origin, 'brand_info.brand_id', 0);
|
|
|
dest.shopId = _.get(origin, 'shopId', 0);
|
|
|
dest.productSkn = origin.product_skn;
|
|
|
dest.id = origin.product_id;
|
|
|
|
|
|
dest.goodsId = origin.goods_id;
|
|
|
dest.isDepositAdvance = origin.is_deposit_advance === 'Y'; // 是否定金预售
|
|
|
dest.isSeckill = origin.is_secKill === 'Y'; // 是否秒杀
|
|
|
dest.isLimitBuy = origin.isLimitBuy; // 是否 限购
|
|
|
dest.isPresale = Boolean(origin.expect_arrival_time); // 是否普通预售
|
|
|
dest.bundleType = origin.bundle_type; // 商品活动标记
|
|
|
|
|
|
// 自定义 属性
|
|
|
dest.showCoupon = !(
|
|
|
dest.isDepositAdvance || dest.isSeckill || dest.isLimitBuy || dest.isPresale
|
|
|
); // 商品有限购、秒杀、定金预售、普通预售 不显示领
|
|
|
|
|
|
// 20170113 要求关闭商品详情页面领券功能
|
|
|
// dest.showCoupon = false;
|
|
|
|
|
|
// 商品信息
|
|
|
if (origin.goods_list.length) {
|
|
|
let goodsGroup = [];
|
|
|
|
|
|
// pagecache重构
|
|
|
_.forEach(origin.goods_list, function(value) {
|
|
|
|
|
|
// 商品分组
|
|
|
if (value.images_list) {
|
|
|
_.forEach(value.images_list, function(good) {
|
|
|
goodsGroup.push({
|
|
|
goodsId: value.goods_id,
|
|
|
img: good.image_url
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
|
|
|
|
|
|
// 商品图:多个
|
|
|
if (goodsGroup.length > 1) {
|
|
|
let bannerList = [];
|
|
|
|
|
|
_.forEach(goodsGroup, function(value) {
|
|
|
value.img = _.replace(value.img, '/quality/80', '/quality/70');
|
|
|
|
|
|
bannerList.push({
|
|
|
img: value.img
|
|
|
});
|
|
|
});
|
|
|
|
|
|
dest.bannerTop = {
|
|
|
list: bannerList
|
|
|
};
|
|
|
} else if (goodsGroup[0]) {
|
|
|
dest.bannerTop = {
|
|
|
img: goodsGroup[0].img
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 底部简介URL链接
|
|
|
dest.introUrl = '/product/detail/intro/' + origin.product_skn;
|
|
|
dest.brandName = _.get(origin, 'brand_info.brand_name', '');
|
|
|
dest.sortName = _.get(origin, 'middle_sort_name', '');
|
|
|
|
|
|
return dest;
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 处理品牌关联店铺信息
|
|
|
* @param {array}
|
|
|
* @return {array}
|
|
|
*/
|
|
|
processShopsInfo(data) {
|
|
|
let enterStore = [];
|
|
|
|
|
|
_.forEach(data, function(value) {
|
|
|
let shopInfo = {
|
|
|
img: value.brand_ico,
|
|
|
storeName: value.brand_name
|
|
|
};
|
|
|
|
|
|
if (value.shop_id) {
|
|
|
shopInfo.url = helpers.urlFormat('/product/index/brand', {
|
|
|
shop_id: value.shop_id
|
|
|
});
|
|
|
} else {
|
|
|
shopInfo.url = helpers.urlFormat('', null, value.brand_domain);
|
|
|
}
|
|
|
|
|
|
enterStore.push(shopInfo);
|
|
|
});
|
|
|
return enterStore;
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 处理商品 feedback
|
|
|
* @param data feedback要处理数据
|
|
|
* {
|
|
|
* comment, defaultConsult, userConsult
|
|
|
* }
|
|
|
* @param productId 商品id
|
|
|
* @return feedback
|
|
|
*/
|
|
|
processFeedback(data, productId) {
|
|
|
// let {comment, defaultConsult, userConsult} = data;
|
|
|
let comment = data.comment;
|
|
|
let defaultConsult = data.defaultConsult;
|
|
|
let userConsult = data.userConsult;
|
|
|
|
|
|
let feedbacks = {consults: [], consultsNum: 0};
|
|
|
|
|
|
Object.assign(feedbacks, comment);
|
|
|
|
|
|
// 商品评价
|
|
|
feedbacks.commentsUrl = helpers.urlFormat('/product/detail/comments', {
|
|
|
product_id: productId
|
|
|
});
|
|
|
|
|
|
/* 如果有用户咨询,显示用户咨询,否则显示常见问题 */
|
|
|
let obj = {};
|
|
|
|
|
|
if (userConsult.total) {
|
|
|
obj = {
|
|
|
commonConsults: false,
|
|
|
consultsNum: parseInt(userConsult.total, 10),
|
|
|
consults: _.take(userConsult.list, 2)
|
|
|
};
|
|
|
} else if (!_.isEmpty(defaultConsult) && !_.get(comment, 'consultsNum', 0)) {
|
|
|
obj = {
|
|
|
commonConsults: true,
|
|
|
consultsNum: true,
|
|
|
consults: _.take(defaultConsult.faq, 2)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
Object.assign(feedbacks, obj);
|
|
|
|
|
|
if (_.get(feedbacks, 'consultsNum')) {
|
|
|
feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consults', {
|
|
|
product_id: productId,
|
|
|
total: feedbacks.consultsNum
|
|
|
});
|
|
|
} else {
|
|
|
feedbacks.consultsUrl = helpers.urlFormat('/product/detail/consultform', {
|
|
|
product_id: productId
|
|
|
});
|
|
|
}
|
|
|
return feedbacks;
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 套餐数据处理
|
|
|
* @param bundleData
|
|
|
* @param skn
|
|
|
* @returns {{}}
|
|
|
*/
|
|
|
processBundle(bundleData, skn, productId, index) {
|
|
|
let subPrice = _.get(bundleData, 'bundleInfo.subPrice', 0);
|
|
|
|
|
|
return {
|
|
|
tabName: _.get(bundleData, 'bundleInfo.tabName') || '',
|
|
|
title: _.get(bundleData, 'bundleInfo.bundleName') || '优惠套装',
|
|
|
href: helpers.urlFormat('/product/bundle/detail', {bundle_skn: skn, productId: productId, index: index}),
|
|
|
description: subPrice ? '立省¥' + subPrice : 0,
|
|
|
productList: productProcess.processProductList(bundleData && bundleData.productList)
|
|
|
};
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 处理量贩数据
|
|
|
* @param finalResult
|
|
|
* @param bundleData
|
|
|
*/
|
|
|
processDiscount(finalResult, bundleData) {
|
|
|
finalResult.discountBuy = {
|
|
|
num: _.get(bundleData, 'bundleInfo.bundleCount', 1),
|
|
|
promotionPhrase: _.get(bundleData, 'bundleInfo.promotionPhrase', ''),
|
|
|
discount: _.get(bundleData, 'bundleInfo.discount', 1)
|
|
|
};
|
|
|
|
|
|
let oldPromotion = finalResult.promotion;
|
|
|
|
|
|
finalResult.promotion = [{
|
|
|
promotionTitle: _.get(bundleData, 'bundleInfo.promotionPhrase', ''),
|
|
|
promotionType: '量贩'
|
|
|
}];
|
|
|
|
|
|
_.forEach(oldPromotion, value => {
|
|
|
finalResult.promotion.push(value);
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const newDetail = {
|
|
|
getProductData(data) {
|
...
|
...
|
@@ -291,7 +36,7 @@ const newDetail = { |
|
|
result.data.goods_id = data.goodsId;
|
|
|
result.data.shopId = _.get(result, 'data.shop_id', null);
|
|
|
|
|
|
return tool.prodessDetailData(result.data);
|
|
|
return detailProcess.prodessDetailData(result.data);
|
|
|
});
|
|
|
},
|
|
|
|
...
|
...
|
@@ -330,7 +75,7 @@ const newDetail = { |
|
|
|
|
|
finalResult.promotion = info[4];
|
|
|
finalResult.enterStore = info[0];
|
|
|
finalResult.feedbacks = tool.processFeedback({
|
|
|
finalResult.feedbacks = detailProcess.processFeedback({
|
|
|
comment: info[1],
|
|
|
defaultConsult: info[2],
|
|
|
userConsult: info[3]
|
...
|
...
|
@@ -342,10 +87,10 @@ const newDetail = { |
|
|
if (_.some(bundleDatas, data => _.get(data, 'bundleInfo.discountType') === 2)) {
|
|
|
let discountBuy = _.find(bundleDatas, bund => _.get(bund, 'bundleInfo.discountType') === 2);
|
|
|
|
|
|
tool.processDiscount(finalResult, discountBuy);
|
|
|
detailProcess.processDiscount(finalResult, discountBuy);
|
|
|
} else { /* 套装 */
|
|
|
finalResult.bundleDatas = _.map(bundleDatas, (data, index) => {
|
|
|
return tool.processBundle(data, skn, productId, ++index);
|
|
|
return detailProcess.processBundle(data, skn, productId, ++index);
|
|
|
});
|
|
|
}
|
|
|
|
...
|
...
|
@@ -372,7 +117,7 @@ const newDetail = { |
|
|
return api.get('', params, cacheConf)
|
|
|
.then(result => {
|
|
|
if (result && result.code === 200) {
|
|
|
return tool.processShopsInfo(result.data);
|
|
|
return detailProcess.processShopsInfo(result.data);
|
|
|
}
|
|
|
return [];
|
|
|
}, () => []);
|
...
|
...
|
|