Authored by 刘传洋

m

... ... @@ -430,144 +430,8 @@ const getCoupons = (uid) => api.get('', {
* @returns {*}
*/
const getCartData = (uid, shoppingKey, cartDelList) => {
let analysisData = {
ids: [],
criteo: []
}; // 存放分析用的数据
return co(function * () {
let result = {
isEmpty: false,
isLogin: !!uid,
searchUrl: helpers.urlFormat('', null, 'search'), // 搜索链接(再逛逛)
listUrl: helpers.urlFormat('', null, 'list'),
viewOrderUrl: helpers.urlFormat('/home/orders', {
t: new Date().getTime()
})
};
// 未登录
if (!uid) {
result.loginUrl = helpers.urlFormat('/signin.html', {
refer: helpers.urlFormat('/shopping/cart')
});
}
// 调用接口,获取购物车数据
let cartDataRet = yield cartApi.cartData(uid, shoppingKey);
let cartData = cartDataRet && cartDataRet.data;
let advCartData = _.get(cartData, 'advance_cart_data');
let ordCartData = _.get(cartData, 'ordinary_cart_data');
// 接口异常时,购物车置为空
if (!cartData) {
result.isEmpty = true;
// UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'shoppingKey:' . $shoppingKey);
return result;
}
result.advanceCart = {
// 未参加活动的商品
// goodsList: chelper.formatCartGoods(_.get(advCartData, 'goods_list'), true, false, false, analysisData),
pools: chelper.formatPromotionPools(_.get(advCartData, 'goods_pool_list'), null, true),
offShelves: chelper.formatOffShelves(_.get(advCartData, 'off_shelves_goods_list'), true, analysisData),
soldOuts: chelper.formatSoldOuts(_.get(advCartData, 'sold_out_goods_list'), true, analysisData),
promotionInfos: chelper.formatPromotionInfos(_.get(advCartData, 'promotion_info')),
stat: chelper.formatShoppingCartData(_.get(advCartData, 'shopping_cart_data')),
ensureUrl: helpers.urlFormat('/cart/ensure', {
type: 2
})
};
let giftsList = chelper.formatPriceGifts(_.get(ordCartData, 'gift_list'));
let priceGifts = chelper.formatPriceGifts(_.get(ordCartData, 'price_gift'));
let goodsList = chelper.formatCartGoods(_.get(ordCartData, 'goods_list'), false, false, false, analysisData);
result.ordinaryCart = {
// 全场可选的赠品
gifts: giftsList, // chelper.formatGifts(_.get(ordCartData, 'gift_list')),
// 全场可选的加价购商品列表
priceGifts: priceGifts, // chelper.formatPriceGifts(_.get(ordCartData, 'price_gift')),
// 已选择的全场加价购和赠品
goodsList: goodsList,
pools: chelper.formatPromotionPools(_.get(ordCartData, 'goods_pool_list'), goodsList),
offShelves: chelper.formatOffShelves(_.get(ordCartData, 'off_shelves_goods_list'), false, analysisData),
soldOuts: chelper.formatSoldOuts(_.get(ordCartData, 'sold_out_goods_list'), false, analysisData),
promotionInfos: chelper.formatPromotionInfos(_.get(ordCartData, 'promotion_info'), goodsList),
stat: chelper.formatShoppingCartData(_.get(ordCartData, 'shopping_cart_data')),
ensureUrl: helpers.urlFormat('/cart/ensure')
};
let advStat = result.advanceCart.stat;
let ordStat = result.ordinaryCart.stat;
// 为空
if (!_.get(advStat, 'goodsCount', 0)) {
result.advanceCart = false;
}
if (!_.get(ordStat, 'goodsCount', 0)) {
result.ordinaryCart = false;
}
// promotionInfos, gifts, priceGifts 放一起展示
let hasGifts = result.ordinaryCart.gifts && result.ordinaryCart.gifts.length;
let hasPrices = result.ordinaryCart.priceGifts && result.ordinaryCart.priceGifts.length;
let hasPromo = result.ordinaryCart.promotionInfos && result.ordinaryCart.promotionInfos.length;
if (result.ordinaryCart) {
result.ordinaryCart.hasGlobalBlock = hasGifts || hasPrices || hasPromo;
}
result.stat = {
orderAmount: (parseFloat(_.get(advStat, 'orderAmount', 0)) + parseFloat(_.get(ordStat, 'orderAmount', 0))).toFixed(2),
discountAmount: (parseFloat(_.get(advStat, 'discountAmount', 0)) + parseFloat(_.get(ordStat, 'discountAmount', 0))).toFixed(2),
lastOrderAmount: (parseFloat(_.get(advStat, 'lastOrderAmount', 0)) + parseFloat(_.get(ordStat, 'lastOrderAmount', 0))).toFixed(2),
gainYohoCoin: parseFloat(_.get(advStat, 'gainYohoCoin', 0)) + parseFloat(_.get(ordStat, 'gainYohoCoin', 0)),
goodsCount: _.get(advStat, 'goodsCount', 0) + _.get(ordStat, 'goodsCount', 0),
selectedGoodsCount: _.get(advStat, 'selectedGoodsCount', 0) + _.get(ordStat, 'selectedGoodsCount', 0)
};
/* 移除的商品列表 */
if (cartDelList) {
try {
result.deleteShop = JSON.parse(cartDelList);
} catch (err) {
logger.error(err);
}
}
// 普通购物车和预售购物车都为空
/* if (ordinaryCount === 0 && advanceCount === 0 && ordinarySoldOut && advanceSoldOut) {
result.isEmpty = true;
return result;
}*/
// 预售和普通都有商品
if (result.advanceCart && _.get(result, 'advanceCart.stat.selectedGoodsCount') > 0 &&
result.ordinaryCart && _.get(result, 'ordinaryCart.stat.selectedGoodsCount') > 0) {
result.stat.mix = true;
} else if (result.advanceCart && _.get(result, 'advanceCart.stat.selectedGoodsCount') > 0) {
result.stat.ensureUrl = result.advanceCart.ensureUrl;
} else if (result.ordinaryCart && _.get(result, 'ordinaryCart.stat.selectedGoodsCount') > 0) {
result.stat.ensureUrl = result.ordinaryCart.ensureUrl;
}
return result;
})().then(ret => {
// 增加第三方分析用的数据
// ret['ids'] = empty($analysisData['ids']) ? '' : implode(',', $analysisData['ids']);
// $result['criteo'] = empty($analysisData['criteo']) ? "''" : json_encode($analysisData['criteo']);
return Object.assign(ret, {
ids: _.isArray(analysisData.ids) ? analysisData.ids.join(',') : '',
criteo: analysisData.criteo || ''
// empty($analysisData['criteo']) ? "''" : json_encode($analysisData['criteo']);
});
return cartApi.cartData(uid, shoppingKey).then(cartDataRet => {
return chelper.formatCart(cartDataRet, uid, shoppingKey, cartDelList);
});
};
... ...