|
|
'use strict';
|
|
|
const path = require('path');
|
|
|
const _ = require('lodash');
|
|
|
const camelCase = global.yoho.camelCase;
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const utilsPath = path.join(global.utils, '/constant');
|
|
|
const genderMap = require(utilsPath).genderMap;
|
...
|
...
|
@@ -14,13 +13,13 @@ const _procProductImg = (product, genderVal) => { |
|
|
|
|
|
switch (genderVal) {
|
|
|
case genderMap.men:
|
|
|
defaultImages = product.cover1 || product.imagesUrl;
|
|
|
defaultImages = product.cover_1 || product.images_url;
|
|
|
break;
|
|
|
case genderMap.women:
|
|
|
defaultImages = product.cover2 || product.imagesUrl;
|
|
|
defaultImages = product.cover_2 || product.images_url;
|
|
|
break;
|
|
|
default:
|
|
|
defaultImages = product.imagesUrl || product.cover1 || product.cover2;
|
|
|
defaultImages = product.images_url || product.cover_1 || product.cover_2;
|
|
|
break;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -52,7 +51,6 @@ module.exports = (list, options) => { |
|
|
gender: '',
|
|
|
yhChannel: ''
|
|
|
}, options);
|
|
|
list = camelCase(list);
|
|
|
|
|
|
let genderVal = options.gender.split(',');
|
|
|
|
...
|
...
|
@@ -64,69 +62,69 @@ module.exports = (list, options) => { |
|
|
|
|
|
_.forEach(list, (product) => {
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!product || !product.productId || !product.goodsList || !product.goodsList.length) {
|
|
|
if (!product || !product.product_id || !product.goods_list || !product.goods_list.length) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 如果库存为0,显示已抢完
|
|
|
if (product.storageNum === 0) {
|
|
|
product.noStorage = true;
|
|
|
if (product.storage_num === 0) {
|
|
|
product.no_storage = true;
|
|
|
}
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (product.marketPrice === product.salesPrice) {
|
|
|
product.marketPrice = false;
|
|
|
if (product.market_price === product.sales_price) {
|
|
|
product.market_price = false;
|
|
|
}
|
|
|
|
|
|
// 判别默认的商品是否将默认的图片URL赋值到skn
|
|
|
let flag = false;
|
|
|
|
|
|
// 如果设置了默认图片,就取默认的图片
|
|
|
_.forEach(product.goodsList, (goods) => {
|
|
|
_.forEach(product.goods_list, (goods) => {
|
|
|
if (flag) {
|
|
|
return false;
|
|
|
}
|
|
|
if (goods.isDefault === 'Y') {
|
|
|
product.defaultImages = _procProductImg(goods, genderVal);
|
|
|
if (goods.is_default === 'Y') {
|
|
|
product.default_images = _procProductImg(goods, genderVal);
|
|
|
flag = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
// 如果还未赋值,则取第一个skc产品的默认图片
|
|
|
if (!flag) {
|
|
|
product.defaultImages = _procProductImg(product.goodsList[0], genderVal);
|
|
|
product.default_images = _procProductImg(product.goods_list[0], genderVal);
|
|
|
}
|
|
|
|
|
|
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
|
|
|
product.url = helpers.urlFormat(`/product/pro_${product.productId}_${product.goodsList[0].goodsId}/${product.cnAlphabet}.html`); // eslint-disable-line
|
|
|
product.is_soon_sold_out = product.is_soon_sold_out === 'Y';
|
|
|
product.url = helpers.urlFormat(`/product/pro_${product.product_id}_${product.goods_list[0].goods_id}/${product.cn_alphabet}.html`); // eslint-disable-line
|
|
|
|
|
|
// APP访问需要加附加的参数
|
|
|
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
if (options.isApp) {
|
|
|
product.url += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":'${product.productId}'}}`; // eslint-disable-line
|
|
|
product.url += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":'${product.product_id}'}}`; // eslint-disable-line
|
|
|
}
|
|
|
|
|
|
if (options.showTags) {
|
|
|
product.tags = {};
|
|
|
|
|
|
product.tags.isNew = options.showNew && product.isNew === 'Y'; // 新品
|
|
|
product.tags.isDiscount = options.showSale && product.isDiscount === 'Y'; // 在售
|
|
|
product.tags.isLimited = product.isLimited === 'Y'; // 限量
|
|
|
product.tags.isYohood = product.isYohood === 'Y'; // YOHOOD
|
|
|
product.tags.midYear = product.midYear === 'Y'; // 年中
|
|
|
product.tags.yearEnd = product.yearEnd === 'Y'; // 年末
|
|
|
product.tags.isAdvance = product.isAdvance === 'Y'; // 再到着
|
|
|
product.tags.is_new = options.showNew && product.is_new === 'Y'; // 新品
|
|
|
product.tags.is_discount = options.showSale && product.is_discount === 'Y'; // 在售
|
|
|
product.tags.is_limited = product.is_limited === 'Y'; // 限量
|
|
|
product.tags.is_yohood = product.is_yohood === 'Y'; // YOHOOD
|
|
|
product.tags.mid_year = product.mid_year === 'Y'; // 年中
|
|
|
product.tags.year_end = product.year_end === 'Y'; // 年末
|
|
|
product.tags.is_advance = product.is_advance === 'Y'; // 再到着
|
|
|
|
|
|
// 打折与即将售完组合显示打折
|
|
|
if (product.isSoonSoldOut && product.tags.isDiscount) {
|
|
|
product.tags.isNew = false;
|
|
|
} else if (product.tags.isDiscount &&
|
|
|
(product.tags.isNew || product.tags.isLimited || product.tags.isYohood || product.tags.isAdvance)) {
|
|
|
if (product.isSoonSoldOut && product.tags.is_discount) {
|
|
|
product.tags.is_new = false;
|
|
|
} else if (product.tags.is_discount &&
|
|
|
(product.tags.is_new || product.tags.is_limited || product.tags.is_yohood || product.tags.is_advance)) {
|
|
|
// 打折与其它组合则隐藏打折
|
|
|
product.tags.isDiscount = false;
|
|
|
} else if (product.tags.isYohood && product.tags.isNew) {
|
|
|
product.tags.is_discount = false;
|
|
|
} else if (product.tags.is_yohood && product.tags.is_new) {
|
|
|
// YOHOOD和新品组合显示YOHOOD
|
|
|
product.tags.isNew = false;
|
|
|
product.tags.is_new = false;
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|