...
|
...
|
@@ -74,7 +74,8 @@ const formatCartGoods = (cartGoods, isAdvanceCart, inValid, isOffShelves, analys |
|
|
yohoIcon: it.get_yoho_coin || 0,
|
|
|
productSubtotal: transPrice(it.last_vip_price * it.buy_number),
|
|
|
promotionId: it.promotion_id || 0,
|
|
|
isLimitSkn: it.is_limit_skn === 'Y' // is_limit_skn=Y 不支持7天无理由退货
|
|
|
isLimitSkn: it.is_limit_skn === 'Y', // is_limit_skn=Y 不支持7天无理由退货
|
|
|
isAdvance: isAdvanceCart
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
@@ -214,70 +215,77 @@ const formatSoldOuts = (soldOutsList, isAdvanceCart, analysis) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 可选加价购
|
|
|
* isGift 是否是赠品:true-赠品
|
|
|
* 格式化单个加价购商品
|
|
|
*/
|
|
|
const formatPriceGifts = (giftList, isGift) => {
|
|
|
const formatPriceGiftOne = (it) => {
|
|
|
|
|
|
let gift = {
|
|
|
// isShowGift: isGift, // 控制是否显示赠品
|
|
|
// isFold: true, // 控制是否[展开]
|
|
|
promotionId: it.promotion_id,
|
|
|
promotionTitle: it.promotion_title.replace('¥', '¥'), // + '(注:您看到的商品可能因为下单时间差已售完)', // subjoinType
|
|
|
maxSelectNumber: it.max_select_number,
|
|
|
promotionType: it.promotion_type,
|
|
|
tag: PROMOTION_TYPE_TAG_MAP[it.promotion_type],
|
|
|
isGift: 'Gift' === it.promotion_type,
|
|
|
isPriceGift: 'Needpaygift' === it.promotion_type
|
|
|
};
|
|
|
|
|
|
return _.map(giftList, (it) => {
|
|
|
gift.goodsList = _.map(it.goods_list, (g) => {
|
|
|
|
|
|
let gift = {
|
|
|
isShowGift: isGift, // 控制是否显示赠品
|
|
|
isFold: true, // 控制是否[展开]
|
|
|
promotionId: it.promotion_id,
|
|
|
promotionTitle: it.promotion_title.replace('¥', '¥') + '(注:您看到的以下商品可能因为下单时间差已售完)', // subjoinType
|
|
|
maxSelectNumber: it.max_select_number,
|
|
|
promotionType: it.promotion_type
|
|
|
let goods = {
|
|
|
id: g.product_id,
|
|
|
skn: g.product_skn,
|
|
|
subjoinTitle: g.product_name,
|
|
|
imgCover: it.goods_images ? helpers.image(it.goods_images, 60, 60) : '',
|
|
|
subjoinPrice: transPrice(g.last_price),
|
|
|
marketPrice: gift.isGift ? '' : transPrice(g.market_price),
|
|
|
yohoIcon: 0,
|
|
|
isGift: gift.isGift,
|
|
|
isPriceGift: gift.isPriceGift
|
|
|
};
|
|
|
|
|
|
gift.goodsList = _.map(it.goods_list, (g) => {
|
|
|
// 商品链接
|
|
|
if (g.goods_id) {
|
|
|
let cnAlphaBet = g.cn_alphabet ? g.cn_alphabet : md5(g.product_name);
|
|
|
|
|
|
let goods = {
|
|
|
id: g.product_id,
|
|
|
skn: g.product_skn,
|
|
|
subjoinTitle: g.product_name,
|
|
|
imgCover: it.goods_images ? helpers.image(it.goods_images, 60, 60) : '',
|
|
|
subjoinPrice: transPrice(g.last_price),
|
|
|
marketPrice: isGift ? '' : transPrice(g.market_price),
|
|
|
yohoIcon: 0
|
|
|
};
|
|
|
goods.subjoinLink = helpers.urlFormat(`/product/pro_${g.product_id}_${g.goods_id}/${cnAlphaBet}.html`,
|
|
|
null, 'item');
|
|
|
} else {
|
|
|
let uri = `/product/show_${g.product_id}_${g.product_skn}/${makeToken(g.product_skn)}.html`;
|
|
|
|
|
|
// 商品链接
|
|
|
if (g.goods_id) {
|
|
|
let cnAlphaBet = g.cn_alphabet ? g.cn_alphabet : md5(g.product_name);
|
|
|
goods.subjoinLink = helpers.urlFormat(uri, null, 'item');
|
|
|
}
|
|
|
|
|
|
goods.subjoinLink = helpers.urlFormat(`/product/pro_${g.product_id}_${g.goods_id}/${cnAlphaBet}.html`,
|
|
|
null, 'item');
|
|
|
} else {
|
|
|
let uri = `/product/show_${g.product_id}_${g.product_skn}/${makeToken(g.product_skn)}.html`;
|
|
|
return goods;
|
|
|
});
|
|
|
|
|
|
goods.subjoinLink = helpers.urlFormat(uri, null, 'item');
|
|
|
}
|
|
|
return gift;
|
|
|
};
|
|
|
|
|
|
// 赠品
|
|
|
if (isGift) {
|
|
|
goods.isGift = true;
|
|
|
} else { // 加价购
|
|
|
goods.isPriceGift = true;
|
|
|
}
|
|
|
/**
|
|
|
* 可选加价购
|
|
|
* isGift 是否是赠品:true-赠品
|
|
|
*/
|
|
|
const formatPriceGifts = (giftList) => {
|
|
|
|
|
|
return goods;
|
|
|
});
|
|
|
return _.map(giftList, (it) => {
|
|
|
return formatPriceGiftOne(it);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 购物车赠品
|
|
|
*/
|
|
|
const formatGifts = (giftList) => {
|
|
|
return formatPriceGifts(giftList, true);
|
|
|
};
|
|
|
/*const formatGifts = (giftList) => {
|
|
|
return formatPriceGifts(giftList);
|
|
|
};*/
|
|
|
|
|
|
const checkGoodsIsSel = (goodsList, promotionId, giftsList, pricesGifts) => {
|
|
|
const checkGoodsIsSel = (goodsList, promotionId, selectedGiftsList) => {
|
|
|
|
|
|
return _.map(goodsList, goods => {
|
|
|
|
|
|
_.forEach((giftsList || []).concat(pricesGifts), gift => {
|
|
|
_.forEach((selectedGiftsList || []), gift => {
|
|
|
|
|
|
if (goods.id === gift.id && promotionId === gift.promotionId) {
|
|
|
goods.isCheckedGift = true;
|
...
|
...
|
@@ -292,69 +300,76 @@ const checkGoodsIsSel = (goodsList, promotionId, giftsList, pricesGifts) => { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 优惠池头部优惠信息列表
|
|
|
* 格式化promotion 里的数据
|
|
|
*/
|
|
|
const formatPoolPromotionInfos = (infoList, giftsList, priceGifts) => {
|
|
|
const formatPromotion = (it, selectedGiftsList) => {
|
|
|
|
|
|
let status = Number(it.status);
|
|
|
let info = {
|
|
|
status: status,
|
|
|
|
|
|
// "status": 0, // 状态 0 未满足 10 已满足 [20 售光 30 更换 ]
|
|
|
conditionUnit: it.condition_unit, // 0满足,1 件,2金额
|
|
|
conditionValue: it.condition_value,
|
|
|
giftPrice: it.gift_price, // 赠品或加价购商品价格
|
|
|
giftGoodsList: formatCartGoods(it.gift_goods_List), // 可供选择的赠品或加价购商品列表
|
|
|
promotionId: it.promotion_id, // 促销id
|
|
|
promotionTitle: it.promotion_title, // "已满足[满30减10-dev30]",
|
|
|
promotionType: it.promotion_type, // 促销类型
|
|
|
// list.yohobuy.com?pp_id=10408
|
|
|
promotionPageUrl: helpers.urlFormat('', { pp_id: it.promotion_id }, 'list'),
|
|
|
tag: PROMOTION_TYPE_TAG_MAP[it.promotion_type],
|
|
|
|
|
|
isGift: it.promotion_type === 'Gift',
|
|
|
isPriceGift: it.promotion_type === 'Needpaygift',
|
|
|
isNotReach: status === 0, // 未满足
|
|
|
isReach: status === 10, // 满足条件
|
|
|
isEmpty: status === 20, // 已售完
|
|
|
isSelected: status === 30 // 已选择,可更换
|
|
|
};
|
|
|
|
|
|
return _.map(infoList, it => {
|
|
|
// 判断赠品/加价购商品,是否被选中
|
|
|
info.giftGoodsList = checkGoodsIsSel(info.giftGoodsList, info.promotionId, selectedGiftsList);
|
|
|
|
|
|
let status = Number(it.status);
|
|
|
let info = {
|
|
|
status: status,
|
|
|
|
|
|
// "status": 0, // 状态 0 未满足 10 已满足 [20 售光 30 更换 ]
|
|
|
conditionUnit: it.condition_unit, // 0满足,1 件,2金额
|
|
|
conditionValue: it.condition_value,
|
|
|
giftPrice: it.gift_price, // 赠品或加价购商品价格
|
|
|
giftGoodsList: formatCartGoods(it.gift_goods_List), // 可供选择的赠品或加价购商品列表
|
|
|
promotionId: it.promotion_id, // 促销id
|
|
|
promotionTitle: it.promotion_title, // "已满足[满30减10-dev30]",
|
|
|
promotionType: it.promotion_type, // 促销类型
|
|
|
// list.yohobuy.com?pp_id=10408
|
|
|
promotionPageUrl: helpers.urlFormat('', { pp_id: it.promotion_id }, 'list'),
|
|
|
tag: PROMOTION_TYPE_TAG_MAP[it.promotion_type],
|
|
|
|
|
|
isGift: it.promotion_type === 'Gift',
|
|
|
isPriceGift: it.promotion_type === 'Needpaygift',
|
|
|
isNotReach: status === 0, // 未满足
|
|
|
isReach: status === 10, // 满足条件
|
|
|
isEmpty: status === 20, // 已售完
|
|
|
isSelected: status === 30 // 已选择,可更换
|
|
|
};
|
|
|
if (status === 0) {
|
|
|
let tipTxt = `差${ -1 * info.conditionValue}`;
|
|
|
|
|
|
// 判断赠品/加价购商品,是否被选中
|
|
|
info.giftGoodsList = checkGoodsIsSel(info.giftGoodsList, info.promotionId, giftsList, priceGifts);
|
|
|
if (info.conditionUnit === 1) {
|
|
|
tipTxt += '件';
|
|
|
} else if (info.conditionUnit === 2) {
|
|
|
tipTxt += '元';
|
|
|
}
|
|
|
|
|
|
if (status === 0) {
|
|
|
let tipTxt = `差${ -1 * info.conditionValue}`;
|
|
|
info.promotionTitle = tipTxt + info.promotionTitle;
|
|
|
} else if (status === 10) {
|
|
|
info.promotionTitle = '已满足' + info.promotionTitle;
|
|
|
}
|
|
|
|
|
|
if (info.conditionUnit === 1) {
|
|
|
tipTxt += '件';
|
|
|
} else if (info.conditionUnit === 2) {
|
|
|
tipTxt += '元';
|
|
|
}
|
|
|
if (info.giftGoodsList) {
|
|
|
info.giftGoodsListStr = JSON.stringify(info.giftGoodsList);
|
|
|
}
|
|
|
return info;
|
|
|
};
|
|
|
|
|
|
info.promotionTitle = tipTxt + info.promotionTitle;
|
|
|
} else if (status === 10) {
|
|
|
info.promotionTitle = '已满足' + info.promotionTitle;
|
|
|
}
|
|
|
/**
|
|
|
* 优惠池头部优惠信息列表
|
|
|
*/
|
|
|
const formatPoolPromotionInfos = (infoList, selectedGiftsList) => {
|
|
|
|
|
|
if (info.giftGoodsList) {
|
|
|
info.giftGoodsListStr = JSON.stringify(info.giftGoodsList);
|
|
|
}
|
|
|
return info;
|
|
|
return _.map(infoList, it => {
|
|
|
return formatPromotion(it, selectedGiftsList);
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 格式化子优惠池信息,返回商品列表,子优惠列表放在每个商品中
|
|
|
*/
|
|
|
const formatSubPromotionPools = (pools, gifts, priceGifts) => {
|
|
|
const formatSubPromotionPools = (pools, selectedGiftsList) => {
|
|
|
|
|
|
let goodsListPool = _.map(pools, p => {
|
|
|
let pool = {
|
|
|
goodsList: formatCartGoods(p.goods_list),
|
|
|
promotionInfos: formatPoolPromotionInfos(p.promotion_list, gifts, priceGifts)
|
|
|
promotionInfos: formatPoolPromotionInfos(p.promotion_list, selectedGiftsList)
|
|
|
};
|
|
|
|
|
|
let goodsList = pool.goodsList;
|
...
|
...
|
@@ -377,18 +392,18 @@ const formatSubPromotionPools = (pools, gifts, priceGifts) => { |
|
|
* giftsList, priceGifts 已选择的赠品和加价购,判断可选的赠品和加价购是否被选中
|
|
|
* 优惠池
|
|
|
*/
|
|
|
const formatPromotionPools = (pools, giftsList, priceGifts) => {
|
|
|
const formatPromotionPools = (pools, selectedGiftsList) => {
|
|
|
return _.map(pools, p => {
|
|
|
|
|
|
let pool = {
|
|
|
poolTitle: p.pool_title,
|
|
|
poolType: p.pool_type,
|
|
|
goodsList: formatCartGoods(p.goods_list),
|
|
|
promotionInfos: formatPoolPromotionInfos(p.promotion_list, giftsList, priceGifts)
|
|
|
promotionInfos: formatPoolPromotionInfos(p.promotion_list, selectedGiftsList)
|
|
|
};
|
|
|
|
|
|
if (p.sub_pool) {
|
|
|
let goodsWithPromotion = formatSubPromotionPools(p.sub_pool, giftsList, priceGifts);
|
|
|
let goodsWithPromotion = formatSubPromotionPools(p.sub_pool, selectedGiftsList);
|
|
|
|
|
|
if (_.isArray(goodsWithPromotion) && goodsWithPromotion.length) {
|
|
|
pool.goodsList = goodsWithPromotion.concat(pool.goodsList);
|
...
|
...
|
@@ -403,9 +418,11 @@ module.exports = { |
|
|
transPrice,
|
|
|
getShoppingKeyByCookie,
|
|
|
formatCartGoods,
|
|
|
formatGifts,
|
|
|
// formatGifts,
|
|
|
formatPriceGiftOne,
|
|
|
formatPriceGifts,
|
|
|
formatShoppingCartData,
|
|
|
formatPromotion,
|
|
|
formatPromotionPools,
|
|
|
formatPromotionInfos,
|
|
|
formatOffShelves,
|
...
|
...
|
|