...
|
...
|
@@ -75,3 +75,156 @@ exports.upperCase = (str) => { |
|
|
str = str || '';
|
|
|
return str.toUpperCase();
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 格式化商品信息 待处理 没有测试过
|
|
|
* @param {array} productData 需要格式化的商品数据
|
|
|
* @param {Boolean} showTags 控制是否显示标签
|
|
|
* @param {Boolean} showNew 控制是否显示NEW图标
|
|
|
* @param {Boolean} showSale 控制是否显示SALE图标
|
|
|
* @param {Boolean} isApp 判断是不是APP访问
|
|
|
* @param {[type]} showPoint 商品价格是否显示小数位,默认显示
|
|
|
* @return {array} [description]
|
|
|
*/
|
|
|
exports.formatProduct = (productData, showTags, showNew, showSale, isApp, showPoint) => {
|
|
|
|
|
|
if (_.isEmpty(productData)) {
|
|
|
return;
|
|
|
}
|
|
|
if (_.isEmpty(showTags)) {
|
|
|
showTags = true;
|
|
|
}
|
|
|
|
|
|
if (_.isEmpty(showNew)) {
|
|
|
showNew = true;
|
|
|
}
|
|
|
|
|
|
if (_.isEmpty(showSale)) {
|
|
|
showSale = true;
|
|
|
}
|
|
|
|
|
|
if (_.isEmpty(isApp)) {
|
|
|
isApp = false;
|
|
|
}
|
|
|
|
|
|
if (_.isEmpty(showPoint)) {
|
|
|
showPoint = true;
|
|
|
}
|
|
|
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (_.isEmpty(productData.product_skn) ||
|
|
|
_.isEmpty(productData.goods_list[0])) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (parseInt(productData.market_price, 10) ===
|
|
|
parseInt(productData.sales_price, 10)) {
|
|
|
productData.market_price = false;
|
|
|
}
|
|
|
|
|
|
// 判别默认的商品是否将默认的图片URL赋值到skn
|
|
|
let flag = false;
|
|
|
|
|
|
// 如果设置了默认图片,就取默认的图片
|
|
|
_.forEach(productData.goods_list, function(oneGoods) {
|
|
|
|
|
|
// 此skc是默认的,则将图片赋值给skn
|
|
|
if (oneGoods.is_default === 'Y') {
|
|
|
// productData.default_images = procProductImg(oneGoods);
|
|
|
flag = true;
|
|
|
return;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
if (!flag) {
|
|
|
// productData.default_images = procProductImg(productData.goods_list[0]);
|
|
|
}
|
|
|
|
|
|
let result = {};
|
|
|
|
|
|
result.id = productData.product_skn;
|
|
|
result.product_id = productData.product_id;
|
|
|
result.thumb = productData.default_images;
|
|
|
result.name = productData.product_name;
|
|
|
result.price = _.isEmpty(productData.market_price) ? false : productData.market_price;
|
|
|
result.salePrice = productData.sales_price;
|
|
|
|
|
|
if (showPoint) {
|
|
|
result.price = result.price + '.00';
|
|
|
result.salePrice = result.salePrice + '.00';
|
|
|
}
|
|
|
|
|
|
result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y');
|
|
|
// result.url = url('/product/pro_' + productData.product_id +
|
|
|
// '_' + productData.goods_list[0].goods_id +
|
|
|
// '/' + productData.cn_alphabet + '.html');
|
|
|
|
|
|
// APP访问需要加附加的参数
|
|
|
if (isApp) {
|
|
|
result.url = result.url +
|
|
|
'?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' +
|
|
|
productData.product_skn + '}}';
|
|
|
}
|
|
|
|
|
|
if (showTags) {
|
|
|
result.tags = {};
|
|
|
|
|
|
result.tags.is_new = showNew && !_.isEmpty(productData.is_new) &&
|
|
|
productData.is_new === 'Y'; // 新品
|
|
|
result.tags.is_discount = showSale && !_.isEmpty(productData.is_discount) &&
|
|
|
productData.is_discount === 'Y'; // 限量
|
|
|
result.tags.is_limited = !_.isEmpty(productData.is_limited) &&
|
|
|
productData.is_limited === 'Y'; // YOHOOD
|
|
|
result.tags.is_yohood = !_.isEmpty(productData.is_yohood) &&
|
|
|
productData.is_yohood === 'Y';
|
|
|
result.tags.midYear = !_.isEmpty(productData.midYear) &&
|
|
|
productData.midYear === 'Y'; // 年中
|
|
|
result.tags.yearEnd = !_.isEmpty(productData.yearEnd) &&
|
|
|
productData.yearEnd === 'Y'; // 年末
|
|
|
result.tags.is_advance = !_.isEmpty(productData.is_advance) &&
|
|
|
productData.is_advance === 'Y'; // 再到着
|
|
|
|
|
|
// 打折与即将售完组合显示打折
|
|
|
// 打折与其它组合则隐藏打折
|
|
|
// YOHOOD和新品组合显示YOHOOD
|
|
|
if (!_.isEmpty(result.is_soon_sold_out) && !_.isEmpty(result.tags.is_discount)) {
|
|
|
result.tags.is_new = false;
|
|
|
} else if (result.tags.is_discount && (result.tags.is_new) || result.tags.is_advance) {
|
|
|
result.tags.is_discount = false;
|
|
|
} else if (!_.isEmpty(result.tags.is_yohood) && !_.isEmpty(result.tags.is_new)) {
|
|
|
result.tags.is_new = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 根据性别来决定 默认图片获取字段 如果是 2、3
|
|
|
* @param {[type]} images [description]
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
/*exports.procProductImg = (images) => {
|
|
|
let imgUrl = (!_.isEmpty(images.images_url)) ? images.images_url : '';
|
|
|
let cover1 = (!_.isEmpty(images.cover_1)) ? images.cover_1 : '';
|
|
|
let cover2 = (!_.isEmpty(images.cover_2)) ? images.cover_2 : '';
|
|
|
// let gender = getGenderByCookie();
|
|
|
|
|
|
if (gender === '2,3') {
|
|
|
let temp = !_.isEmpty(cover1) ? cover1 : imgUrl;
|
|
|
return !_.isEmpty(cover2) ? cover2 : temp;
|
|
|
} else {
|
|
|
let temp = !_.isEmpty(cover2) ? cover2 : imgUrl;
|
|
|
return !_.isEmpty(cover1) ? cover1 : temp;
|
|
|
}
|
|
|
};*/
|
|
|
|
|
|
/**
|
|
|
* 根据用户访问的COOKIE判断出性别 待处理
|
|
|
* @return {[type]} [description]
|
|
|
*/
|
|
|
exports.getGenderByCookie = () => {
|
|
|
return '2,3';
|
|
|
}; |
...
|
...
|
|