Authored by 陈峰

接口改版

... ... @@ -358,22 +358,13 @@ const modifyPriceGift = (req, res, next) => {
* [获取赠品商品列表]
*/
const gift = (req, res, next) => {
let uid = req.user && req.user.uid,
shoppingKey = req.cookies._SPK || '',
channel = req.cookies._Channel,
cartType = req.cookies.cartType || 'ordinary',
promotionId = req.query.promotion_id;
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
// uid = 20422448;
let promise;
let cartType = req.cookies.cartType || 'ordinary',
promotionIds = req.query.promotion_ids;
if (promotionId) {
promise = indexModel.getPriceGiftList(promotionId);
} else {
promise = indexModel.indexData(uid, shoppingKey, channel, cartType, true);
if (!promotionIds) {
return next();
}
return promise.then(data => {
return indexModel.getPriceGiftList(promotionIds, 'Gift').then(data => {
res.render('gift', Object.assign(data, {
title: '赠品',
module: 'cart',
... ... @@ -398,22 +389,13 @@ const gift = (req, res, next) => {
* [获取加价购商品列表]
*/
const advanceBuy = (req, res, next) => {
let uid = req.user && req.user.uid,
shoppingKey = req.cookies._SPK || '',
channel = req.cookies._Channel,
cartType = req.cookies.cartType || 'ordinary',
promotionId = req.query.promotion_id;
// shoppingKey = 'dc9d09e2ffd8607f2cfd8b9c95962923';
// uid = 20422448;
let promise;
let cartType = req.cookies.cartType || 'ordinary',
promotionIds = req.query.promotion_ids;
if (promotionId) {
promise = indexModel.getPriceGiftList(promotionId);
} else {
promise = indexModel.indexData(uid, shoppingKey, channel, cartType, false, true);
if (!promotionIds) {
return next();
}
return promise.then(data => {
return indexModel.getPriceGiftList(promotionIds, 'Needpaygift').then(data => {
res.render('gift', Object.assign(data, {
title: '加价购',
module: 'cart',
... ...
... ... @@ -14,18 +14,16 @@ const cartProcess = require(global.utils + '/cart-process');
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @param string $cartType 购物车类型,默认是是所有购物车,ordinary为普通购物车,advance为预售购物车
* @param bool $onlyGift 只获取赠品的商品数据
* @param bool $onlyAdvanceBuy 只获取加价购的商品数据
* @return array|mixed 处理之后的购物车数据
*/
const indexData = (uid, shoppingKey, saleChannel, cartType, onlyGift, onlyAdvanceBuy) => {
const indexData = (uid, shoppingKey, saleChannel, cartType) => {
return api.get('', {
method: 'app.Shopping.queryCart',
uid: uid,
shopping_key: shoppingKey,
sale_channel: saleChannel
}).then((data) => {
return data.code === 200 ? cartProcess.processData(data, cartType, onlyGift, onlyAdvanceBuy) : undefined;
return data.code === 200 ? cartProcess.processData(data, cartType) : undefined;
});
};
... ... @@ -238,12 +236,12 @@ const giftProductData = (skn, promotionId) => {
/**
* [获取赠品、加价购促销商品列表]
*/
const getPriceGiftList = (promotionId) => {
const getPriceGiftList = (promotionIds, promotionType) => {
return api.get('', {
method: 'app.Shopping.queryPromotionGift',
promotion_id: promotionId
method: 'app.Shopping.queryPromotionGifts',
promotion_ids: promotionIds
}).then((data) => {
return data.code === 200 ? cartProcess.procPriceGiftData(data.data) : undefined;
return data.code === 200 ? cartProcess.procPriceGiftData(data.data, promotionType) : undefined;
});
};
... ...
<div class="gift-advance-page yoho-page">
{{#if advanceBuyPage}}
{{# advanceBuy}}
<div class="advance-block" data-promotion-id="{{promotionId}}">
<p class="title">{{promotionTitle}}</p>
{{#goods}}
{{> cart/gift-advance-good}}
{{/goods}}
</div>
{{/ advanceBuy}}
{{else}}
{{# freebie}}
<div class="advance-block gift-block" data-promotion-id="{{promotionId}}">
<p class="title">{{promotionTitle}}</p>
{{#goods}}
{{> cart/gift-advance-good}}
{{/goods}}
</div>
{{/ freebie}}
{{/if}}
{{#promotionTitle}}<p class="title">{{.}}</p>{{/promotionTitle}}
{{# gifts}}
<div class="advance-block{{#if isGift}} gift-block{{/if}}" data-promotion-id="{{promotionId}}">
{{#goods}}
{{> cart/gift-advance-good}}
{{/goods}}
</div>
{{/ gifts}}
<div id="chose-panel"></div>
</div>
\ No newline at end of file
... ...
... ... @@ -57,7 +57,7 @@
</div>
{{#if freebieOrAdvanceBuy}}
<div class="all-gift-box box">
{{#if giftCount}}
{{#if freebie.length}}
<div class="gift-item freebie">
<div class="flag">
<i class="iconfont gift"></i>
... ... @@ -70,7 +70,7 @@
</div>
</div>
{{/if}}
{{#if advanceBuyCount}}
{{#if advanceBuy.length}}
<div class="gift-item advanceBuy">
<div class="flag">
<i class="iconfont price-gift"></i>
... ...
... ... @@ -44,11 +44,11 @@ function getProductInfo(skn, promotionId) {
chosePanel.setEditModeWithSknId(skn, true, true);
chosePanel.disableNumEdit();
chosePanel.show('', function() {
window.location.href = '/cart/index/index?cartType=' + queryString.cartType;
window.location.href = '/cart/index/index';
});
} else {
chosePanel.show(html, function() {
window.location.href = '/cart/index/index?cartType=' + queryString.cartType;
window.location.href = '/cart/index/index';
});
}
... ...
... ... @@ -15,6 +15,7 @@ let $ = require('yoho-jquery'),
loading = require('../plugin/loading');
let indexObj = {
cartData: {},
editMode: false,
posting: false,
init() {
... ... @@ -75,12 +76,15 @@ let indexObj = {
if (data.commonGoodsCount === 0 && data.ordinarySoldOut === 0) {
data.cartNav = false;
data.cartType = 'advance';
self.cartData = data.preSellCart;
} else if (data.presellGoodsCount === 0 && data.advanceSoldOut === 0) { // 预售购物车空,则显示普通购物车
data.cartNav = false;
data.cartType = 'ordinary';
self.cartData = data.commonCart;
} else { // 以上两个购物车中都有数据, 默认显示普通购物车
data.cartNav = true;
data.cartType = cartType || 'ordinary';
self.cartData = data.commonCart;
}
cookie.set('_cartType', data.cartType);
data.ordinaryCart = data.cartType === 'ordinary';
... ...
... ... @@ -62,45 +62,49 @@ let cartObj = {
status = $(e.currentTarget).data('status'),
promotionTitle = encodeURIComponent(`以下商品参加【${$(e.currentTarget).data('title')}】促销活动`);
self.toPromotionPage({
promotionType,
promotionId,
promotionTitle,
status
});
},
toPromotionPage(opts) {
let cartType = cookie.get('_cartType') || 'ordinary';
let title = encodeURIComponent('优惠活动商品');
let href;
if (opts.status === 20 || opts.status === 0 || (opts.promotionType !== 'Gift' && opts.promotionType !== 'Needpaygift')) {
href = `/product/index/index?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
} else if (opts.promotionType === 'Gift') {
href = `/cart/index/new/gift?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
if (opts.status === 30) {
href += '&edit=1';
}
} else if (opts.promotionType === 'Needpaygift') {
href = `/cart/index/new/advanceBuy?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
if (opts.status === 30) {
href += '&edit=1';
}
if (status === 20 || status === 0 || (promotionType !== 'Gift' && promotionType !== 'Needpaygift')) {
window.location.href = `/product/index/index?promotion_id=${promotionId}&title=优惠活动商品&intro_text=${promotionTitle}`;
} else {
self.toPromotionPage(promotionId, promotionType, status);
}
window.location.href = href;
},
allGiftBoxClick(e) {
let cartType = cookie.get('_cartType') || 'ordinary';
let self = this;
let promotionIds;
if ($(e.currentTarget).find('.no-storage').length) {
return;
}
if ($(e.currentTarget).hasClass('advanceBuy')) {
window.location.href = '/cart/index/new/advanceBuy?cartType=' + cartType;
if (self.handle.cartData.selectAdvanceBuy) {
promotionIds = self.handle.cartData.selectAdvanceBuy.map(advanceBuy => {
return advanceBuy.promotion_id;
});
self.toPromotionPage(promotionIds, 'Needpaygift');
}
} else {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
if (self.handle.cartData.selectFreebie) {
promotionIds = self.handle.cartData.selectFreebie.map(freebie => {
return freebie.promotion_id;
});
self.toPromotionPage(promotionIds, 'Gift');
}
}
},
toPromotionPage(promotioIds, promotionType, status) {
let href;
let cartType = cookie.get('_cartType') || 'ordinary';
if (promotionType === 'Gift') {
href = `/cart/index/new/gift?promotion_ids=${promotioIds}&cartType=${cartType}`;
} else {
href = `/cart/index/new/advanceBuy?promotion_ids=${promotioIds}&cartType=${cartType}`;
}
if (status === 30) {
href += '&edit=1';
}
window.location.href = href;
},
balanceClick() {
let self = this;
let cartType = cookie.get('_cartType') || 'ordinary';
... ... @@ -130,7 +134,7 @@ let cartObj = {
tip.show('请先勾选商品');
return false;
}
if ($('.all-gift-box>.freebie').length || $('.promo-item[data-type="Gift"][data-status="10"]').length) {
if (!cookie.get('_realyGift') && self.handle.cartData.matchGifts && self.handle.cartData.matchGifts.length) {
dialog.showDialog({
dialogText: '您还未选择赠品,是否去选择赠品',
hasFooter: {
... ... @@ -138,7 +142,8 @@ let cartObj = {
rightBtnText: '去选择'
}
}, function() {
self.toGiftPromotion(cartType);
cookie.set('_realyGift', true); // 提示去选择后不再提示
self.toOrderEnsureGift();
}, function() {
self.toOrderEnsure(cartType);
});
... ... @@ -147,24 +152,15 @@ let cartObj = {
self.toOrderEnsure(cartType);
},
toOrderEnsure(cartType) {
cookie.get('_realyGift') && cookie.remove('_realyGift');
cookie.get('order-info') && cookie.remove('order-info');
window.location.href = '/cart/index/new/orderEnsure?cartType=' + cartType;
},
toGiftPromotion(cartType) {
toOrderEnsureGift() {
let self = this;
let promotionEles = $('.promo-item[data-type="Gift"][data-status="10"]');
if (promotionEles.length) {
let promotionEle = promotionEles.eq(0);
self.toPromotionPage({
promotionType: $(promotionEle).data('type'),
promotionId: $(promotionEle).data('id'),
promotionTitle: encodeURIComponent($(promotionEle).data('title')),
status: $(promotionEle).data('status')
});
} else if ($('.all-gift-box>.freebie').length) {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
if (self.handle.cartData.matchGifts && self.handle.cartData.matchGifts.length) {
self.toPromotionPage(self.handle.cartData.matchGifts, 'Gift');
}
}
};
... ...
... ... @@ -11,9 +11,12 @@ var $ = require('yoho-jquery'),
var $recommendForYou = $('.recommend-for-you');
$.get('/product/recommend-for-you/cart').then(function(html) {
var PRDID =[];
var PRDID = [];
$recommendForYou.html(html).show();
$recommendForYou.html(html);
if ($recommendForYou.find('.good-info').length) {
$recommendForYou.show();
}
lazyLoad($('img.lazy'));
//为您优选埋点 http://redmine.yoho.cn/issues/10116
... ...
... ... @@ -58,22 +58,24 @@ const formatPromotionOpt = (promo) => {
* @param int $count 计商品件数
* @return array $arr 处理之后的加价购商品数据
*/
const formatAdvanceGoods = (advanceGood, isGift) => {
return {
promotionId: advanceGood.promotion_id,
promotionTitle: advanceGood.promotion_title,
status: advanceGood.status,
goods: _.get(advanceGood, 'goods_list').map(good => {
return {
id: good.product_skn,
name: good.product_name,
thumb: good.goods_images ? helpers.image(good.goods_images, 120, 160) : '',
price: transPrice(good.last_price),
marketPrice: isGift ? '0.00' : transPrice(good.market_price),
count: good.storage_number
};
})
};
const formatAdvanceGoods = (gifts, isGift) => {
return _.map(gifts, gift => {
return {
promotionId: gift.promotion_id,
promotionTitle: gift.promotion_title,
isGift: isGift,
goods: _.map(gift.goods_list, good => {
return {
id: good.product_skn,
name: good.product_name,
thumb: good.goods_images ? helpers.image(good.goods_images, 120, 160) : '',
price: transPrice(good.last_price),
marketPrice: isGift ? '0.00' : transPrice(good.market_price),
count: good.storage_number
};
})
};
});
};
/**
... ... @@ -153,15 +155,14 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid, inValidLow) => {
result.link = helpers.urlFormat(`/product/show_${goodData.product_skn}.html`);
return result;
};
const procPriceGiftData = (data) => {
const procPriceGiftData = (data, promotionType) => {
let result = {};
let arrays = _.get(data, 'arrays', []);
if (data.promotion_type === 'Gift') {
// 赠品
result.freebie = formatAdvanceGoods(data, true);
} else if (data.promotion_type === 'Needpaygift') {
// 加价购
result.advanceBuy = formatAdvanceGoods(data);
// 赠品和加价购
result.gifts = formatAdvanceGoods(arrays, promotionType === 'Gift');
if (result.gifts.length === 1) {
result.promotionTitle = result.gifts[0].promotionTitle;
}
return result;
};
... ... @@ -235,27 +236,12 @@ const procGoodsDetail = (productData, num) => {
return data;
};
const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => {
const procCartData = (data, isAdvanceCart) => {
if (isAdvanceCart === undefined) {
isAdvanceCart = true;
}
let result = {};
if (onlyGift) {
// 全场赠品
result.freebie = data.g_gift_list.map(good => {
return formatAdvanceGoods(good, true);
});
return result;
}
if (onlyAdvanceBuy) {
// 全场加价购
result.advanceBuy = data.g_price_gift_list.map(good => {
return formatAdvanceGoods(good);
});
return result;
}
// 购买的可用商品列表
result.goods = _.get(data, 'goods_list', []).map(good => {
let gr = formatCartGoods(good, isAdvanceCart);
... ... @@ -309,14 +295,15 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => {
// 赠品
result.freebie = data.g_gift_list.filter(freebie => freebie.status !== 30 && freebie.status !== 0);
result.giftCount = result.freebie.length;
result.selectFreebie = result.freebie.filter(freebie => freebie.status === 10);
result.giftHasStorage = _.some(result.freebie, freebie => freebie.status === 10);
// 加价购
result.advanceBuy = data.g_price_gift_list.filter(advanceBuy => advanceBuy.status !== 30 && advanceBuy.status !== 0);
result.advanceBuyCount = result.advanceBuy.length;
result.selectAdvanceBuy = result.advanceBuy.filter(advanceBuy => advanceBuy.status === 10);
result.advanceHasStorage = _.some(result.advanceBuy, advanceBuy => advanceBuy.status === 10);
}
result.matchGifts = _.get(data, 'match_gift_ids', []);
// 已参加的活动
if (data.promotion_info && data.promotion_info.length > 0) {
... ... @@ -359,16 +346,12 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => {
return result;
};
const processData = (data, cartType, onlyGift, onlyAdvanceBuy) => {
const processData = (data, cartType) => {
if (cartType === undefined) {
cartType = 'all';
}
let cart = data.data;
let result = {};
if (onlyGift || onlyAdvanceBuy) { // 加价购或者赠品数据
return procCartData(cart.ordinary_cart_data, onlyGift, onlyAdvanceBuy);
}
let ordinaryCount = _.get(cart, 'ordinary_cart_data.shopping_cart_data.goods_count', 0);
let advanceCount = _.get(cart, 'advance_cart_data.shopping_cart_data.goods_count', 0);
let ordinarySoldOut = _.get(cart, 'ordinary_cart_data.sold_out_goods_list', []);
... ... @@ -383,12 +366,12 @@ const processData = (data, cartType, onlyGift, onlyAdvanceBuy) => {
/* 普通购物车 */
result.commonGoodsCount = ordinaryCount;
result.ordinarySoldOut = ordinarySoldOut.length;
result.commonCart = procCartData(cart.ordinary_cart_data, onlyGift, onlyAdvanceBuy, false);
result.commonCart = procCartData(cart.ordinary_cart_data, false);
/* 预售购物车 */
result.presellGoodsCount = advanceCount;
result.advanceSoldOut = advanceSoldOut.length;
result.preSellCart = procCartData(cart.advance_cart_data, onlyGift, onlyAdvanceBuy);
result.preSellCart = procCartData(cart.advance_cart_data);
return result;
};
... ...