Authored by 郭成尧

use-gift-card

... ... @@ -357,7 +357,29 @@ exports.selectGiftcard = (req, res, next) => {
let uid = req.user.uid;
co(function* () {
let usable_giftCards = []; // 可用礼品卡列表
let sureActice = false; // 确认按钮状态
let giftCardsData = yield shoppingAPI.listGiftCard(uid);
let usableGiftCardsOrigin = _.get(giftCardsData, 'data.usable_giftCards', false);
if (usableGiftCardsOrigin) {
let orderInfo;
try {
orderInfo = JSON.parse(req.cookies['order-info']);
} catch (e) {
logger.info(`orderEnsure: get orderInfo from cookie error:${JSON.stringify(e)}`);
orderInfo = {};
res.clearCookie('order-info', actCkOpthn);
}
let handleResult = paymentProcess.handleGiftCardsRender(usableGiftCardsOrigin,
_.get(orderInfo, 'gift_card_code'));
usable_giftCards = handleResult.giftCards;
sureActice = handleResult.sureActice;
}
res.render('select-giftcard', {
module: 'cart',
... ... @@ -369,7 +391,8 @@ exports.selectGiftcard = (req, res, next) => {
pageFooter: false,
localCss: true,
width750: true,
usable_giftCards: _.get(giftCardsData, 'data.usable_giftCards', [])
usable_giftCards: usable_giftCards,
sureActice: sureActice
});
})().catch(next);
};
... ...
... ... @@ -49,6 +49,7 @@ exports.cartPay = (params) => {
delivery_way: params.orderInfo.deliveryId,
payment_type: params.orderInfo.paymentType,
coupon_code: params.orderInfo.couponCode,
gift_card_code: params.orderInfo.gift_card_code,
use_yoho_coin: params.orderInfo.yohoCoin,
product_sku_list: skuList,
activityInfo: params.activityInfo
... ... @@ -105,7 +106,6 @@ exports.cartPay = (params) => {
{
giftCards: paymentProcess.handleGiftCards({
validGiftCardCount: validGiftCardCount,
orderInfo: params.orderInfo,
orderCompute: orderCompute
})
}
... ...
... ... @@ -128,14 +128,14 @@
</li>
{{!-- 礼品卡 --}}
{{#ifand isOrdinaryCart giftCards.count}}
{{#ifand isOrdinaryCart giftCards}}
<li class="gift-card">
<a href="{{choseGiftCard}}">
<span class="title">礼品卡</span>
{{# giftCards}}
<span class="count">{{#if selectCount}}已选{{selectCount}}{{^}}{{count}}张可用{{/if}}</span>
<span class="coupon-info pull-right{{#isEqualOr info '未使用'}} no-can-use{{/isEqualOr}}">
{{info}}<i class="iconfont">&#xe614;</i>
<span class="count">{{leftInfo}}</span>
<span class="coupon-info pull-right">
{{rightInfo}}<i class="iconfont">&#xe614;</i>
</span>
{{/giftCards}}
</a>
... ...
<div class="yoho-page select-giftcard-page">
{{# usable_giftCards}}
<div class="giftcard" data-code={{cardCode}}>
<div class="giftcard{{#if checked}} checked{{/if}}" data-code={{cardCode}}>
<div class="card-title clearfix">
<div class="balance pull-left">
<label>余额</label>
... ... @@ -34,5 +34,5 @@
</div>
{{/usable_giftCards}}
<button id="useGiftCardBtn" class="use-giftcard-btn">使用</button>
<button id="useGiftCardBtn" class="use-giftcard-btn{{#if sureActice}} active{{/if}}">使用</button>
</div>
\ No newline at end of file
... ...
... ... @@ -21,6 +21,7 @@ class SelectGiftCard extends Page {
this.selector.page.css('min-height', () => {
return $(window).height() - $('#yoho-header').height();
});
this.linkUrl = document.referrer;
}
bindEvents() {
... ... @@ -28,6 +29,14 @@ class SelectGiftCard extends Page {
this.selector.useGiftCardBtn.on('click', this.useGiftCard.bind(this));
}
goToBack() {
if (this.linkUrl) {
window.location.href = this.linkUrl;
} else {
history.go(-1);
}
}
/**
* 使用礼品卡
*/
... ... @@ -43,6 +52,7 @@ class SelectGiftCard extends Page {
});
this.orderInfo('gift_card_code', selectedGiftCards.join(','));
this.goToBack();
}
/**
... ...
... ... @@ -372,21 +372,62 @@ function coupon(count, orderInfo, orderComputeData) {
}
/**
* 处理礼品卡数据
* 选择礼品卡页面礼品卡数据处理
*/
function handleGiftCardsRender(giftCards, selectCards) {
let result = {
sureActice: false,
giftCards: giftCards
};
let selectCardsArray = selectCards && selectCards.split(',');
_.forEach(result.giftCards, perCard => {
let checked = _.find(selectCardsArray, per => {
return per === _.get(perCard, 'cardCode');
});
if (checked) {
result.sureActice = true;
}
_.assign(perCard, {
checked: checked
});
});
result.giftCards = giftCards;
return result;
}
/**
* 结算页处理礼品卡数据
*/
function handleGiftCards(params) {
let info = '未使用'; // TODO
let count = params.validGiftCardCount; // 几张可用
let amount = _.get(params, 'orderCompute.gift_card.amount', 0); // 可抵用金额
let selectCount = _.get(params, 'orderCompute.gift_card.count', 0); // 用户选择了几张
let leftInfo = '';
let rightInfo = '未使用';
if (!count) {
return {};
}
let amount = _.get(params, 'orderCompute.gift_card.amount', 0);
if (selectCount) {
leftInfo = `已选${selectCount}张`;
} else if (count) {
leftInfo = `${count}张可用`;
}
if (amount) {
info = `可以抵用¥${amount.toFixed(2)}`;
if (selectCount && amount) {
rightInfo = `可以抵用¥${amount.toFixed(2)}`;
}
return {
count: params.validGiftCardCount,
amount: amount,
selectCount: _.get(params, 'orderCompute.gift_card.count', 0),
info: info
leftInfo: leftInfo,
rightInfo: rightInfo
};
}
... ... @@ -499,6 +540,7 @@ module.exports = {
yohoCoinCompute,
coupon,
handleGiftCards,
handleGiftCardsRender,
transformJit,
unionInfoHandle
};
... ...