...
|
...
|
@@ -5,7 +5,6 @@ |
|
|
'use strict';
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const productNameProcess = require('./product-name-process');
|
|
|
const productPrcs = require('./product-process');
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -205,154 +204,8 @@ const getProductIcon = (type) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* [根据性别获取]
|
|
|
* @param {[type]} gender [description]
|
|
|
* @return {[type]} [description]
|
|
|
* 逛详情页数据处理
|
|
|
*/
|
|
|
const _getGenderByCookie = (gender) => {
|
|
|
switch (gender) {
|
|
|
case 1: // 男
|
|
|
return '1,3';
|
|
|
case 2: // 女
|
|
|
return '2,3';
|
|
|
default: // 其它
|
|
|
return '1,2,3';
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* [根据性别来决定 默认图片获取字段 如果是 2、3]
|
|
|
*
|
|
|
* 则优先从cover2 --》 cover1 -- 》 images_url
|
|
|
* 否则优先从cover1 --》 cover2 -- 》 images_url
|
|
|
*
|
|
|
* @param {[array]} images [images]
|
|
|
* @param {[Boolean]} gender [性别]
|
|
|
* @return {[type]}
|
|
|
*/
|
|
|
const _procProductImg = (images, gender) => {
|
|
|
let imgUrl = images.images_url || '';
|
|
|
let cover1 = images.cover_1 || '';
|
|
|
let cover2 = images.cover_2 || '';
|
|
|
|
|
|
gender = _getGenderByCookie(gender);
|
|
|
if (gender === '2,3') {
|
|
|
return cover2 || (cover1 || imgUrl);
|
|
|
} else {
|
|
|
return cover1 || (cover2 || imgUrl);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 格式化商品信息
|
|
|
*
|
|
|
* @param array productData 需要格式化的商品数据
|
|
|
* @param bool showTags 控制是否显示标签
|
|
|
* @param bool showNew 控制是否显示NEW图标
|
|
|
* @param bool showSale 控制是否显示SALE图标
|
|
|
* @param int width 图片的宽度
|
|
|
* @param int height 图片的高度
|
|
|
* @param bool isApp 判断是不是APP访问
|
|
|
* @param bool showPoint 商品价格是否显示小数位,默认显示
|
|
|
* @param int gender 性别
|
|
|
* @return array | false
|
|
|
*/
|
|
|
const formatProduct = (productData, showTags, showNew, showSale, width, height, isApp, showPoint, gender) => {
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!productData.product_skn || !productData.goods_list[0]) {
|
|
|
return false;
|
|
|
}
|
|
|
productData.sales_price = productData.sales_price || '';
|
|
|
productData.market_price = productData.market_price || '';
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (parseInt(productData.market_price, 10) === parseInt(productData.sales_price, 10)) {
|
|
|
productData.market_price = false;
|
|
|
}
|
|
|
|
|
|
// 判别默认的商品是否将默认的图片URL赋值到skn
|
|
|
let flag = false;
|
|
|
|
|
|
// 如果设置了默认图片,就取默认的图片
|
|
|
for (let oneGoods of productData.goods_list) {
|
|
|
// 此skc是默认的,则将图片赋值给skn
|
|
|
if (oneGoods.is_default === 'Y') {
|
|
|
productData.default_images = _procProductImg(oneGoods, gender);
|
|
|
flag = true;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
if (!flag) {
|
|
|
productData.default_images = _procProductImg(productData.goods_list[0], gender);
|
|
|
}
|
|
|
|
|
|
let result = {
|
|
|
id: productData.product_skn,
|
|
|
product_id: productData.product_id,
|
|
|
thumb: helpers.image(productData.default_images, width, height),
|
|
|
name: productData.product_name,
|
|
|
price: productData.market_price || false,
|
|
|
salePrice: productData.sales_price
|
|
|
};
|
|
|
|
|
|
if (showPoint) {
|
|
|
if (result.price) {
|
|
|
result.price += '.00';
|
|
|
}
|
|
|
if (result.salePrice) {
|
|
|
result.salePrice += '.00';
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// TODO student price
|
|
|
result.studentPrice = parseInt(productData.sales_price * 100 * 0.9, 10) / 100;
|
|
|
result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y');
|
|
|
|
|
|
if (productData.cn_alphabet) {
|
|
|
productData.cn_alphabet = productNameProcess(productData.cn_alphabet);
|
|
|
}
|
|
|
|
|
|
let url = encodeURI(helpers.urlFormat(`/product/${productData.product_skn}.html`));// 商品url改版
|
|
|
|
|
|
result.url = url.replace('http://', '//');
|
|
|
|
|
|
// APP访问需要加附加的参数
|
|
|
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
if (isApp) {
|
|
|
result.url += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${productData.product_skn}}}`; //eslint-disable-line
|
|
|
}
|
|
|
if (showTags) {
|
|
|
result.tags = {
|
|
|
is_new: showNew && productData.is_new === 'Y', // 新品
|
|
|
is_discount: showSale && productData.is_discount === 'Y', // 在售
|
|
|
is_limited: productData.is_limited && productData.is_limited === 'Y', // 限量
|
|
|
is_yohood: productData.is_yohood && productData.is_yohood === 'Y', // YOHOOD
|
|
|
midYear: productData.midear && productData.midear === 'Y', // 年中
|
|
|
yearEnd: productData.yearnd && productData.yearnd === 'Y', // 年末
|
|
|
is_advance: productData.is_advance && productData.is_advance === 'Y' // 再到着
|
|
|
};
|
|
|
|
|
|
// 打折与即将售完组合显示打折
|
|
|
if (result.is_soon_sold_out && result.tags.is_discount) {
|
|
|
result.tags.is_new = false;
|
|
|
} else if (result.tags.is_discount &&
|
|
|
(result.tags.is_new ||
|
|
|
result.tags.is_limited ||
|
|
|
result.tags.is_yohood ||
|
|
|
result.tags.is_advance) // 打折与其它组合则隐藏打折
|
|
|
) {
|
|
|
result.tags.is_discount = false;
|
|
|
} else if (result.tags.is_yohood && result.tags.is_new) { // YOHOOD和新品组合显示YOHOOD
|
|
|
result.tags.is_new = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
|
|
|
const processArticleDetail = (articleContent, isApp, gender, isWeixin, isqq, isWeibo) => {
|
|
|
let finalDetail = [];
|
|
|
let allgoods = '';
|
...
|
...
|
@@ -515,7 +368,6 @@ module.exports = { |
|
|
formatArticle,
|
|
|
transHttpsUrl,
|
|
|
getFilterUrl,
|
|
|
formatProduct,
|
|
|
getProductIcon,
|
|
|
processArticleDetail,
|
|
|
pushGoodsInfo
|
...
|
...
|
|