Authored by yyq

use gift card

... ... @@ -6,6 +6,7 @@
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const logger = global.yoho.logger;
... ... @@ -54,6 +55,10 @@ const getCoupons = (req, res, next) => {
// 获取优惠券列表
const convertCoupons = (req, res, next) => {
oeModel.convertCoupons(req.user.uid, req.query.code).then(data => {
if (data.data) {
data.data.userMobile = req.user.mobile;
}
res.send(data);
}).catch(next);
};
... ... @@ -86,7 +91,7 @@ const sendCheckSms = (req, res, next) => {
let params = req.body;
if (params.giftCard) {
return easypayModel.sendGiftCardCkeckSms(req.user.uid).then(result => {
return oeModel.sendGiftCardCkeckSms(req.user.uid).then(result => {
res.json(result);
}).catch(next);
}
... ... @@ -94,6 +99,26 @@ const sendCheckSms = (req, res, next) => {
return next();
};
// 订单提交前置校验
const submitCheck = (req, res, next) => {
let checkCode = req.body.checkCode;
// 带礼品卡号和短信验证码,则校验短信验证码,否则删除使用礼品卡
if (req.body.giftCard && checkCode) {
return oeModel.checkGiftCardSmsCode(checkCode).then(result => {
if (result.code === 200) {
return next();
}
res.json(result);
}).catch(next);
} else {
_.unset(req.body, 'giftCard');
}
return next();
};
// 提交订单
const submit = (req, res, next) => {
let params = req.body;
... ... @@ -193,5 +218,6 @@ module.exports = {
getGiftCards,
compute,
sendCheckSms,
submitCheck,
submit
};
... ...
... ... @@ -117,6 +117,15 @@ const sendGiftCardCkeckSmsAsync = (uid) => api.get('', {
});
/**
* 校验礼品卡使用短信验证码API
* @param code [number] code
*/
const checkGiftCardSmsCodeAsync = (code) => api.get('', {
method: 'app.giftcard.validRegCode',
code: code
});
/**
* 订单提交API
* @param uid [number] uid
* @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
... ... @@ -175,6 +184,13 @@ const orderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, p
});
}
// 礼品卡
if (other.giftCard) {
Object.assign(param, {
gift_card_code: other.giftCard
});
}
// 备注
if (other.remark) {
Object.assign(param, {
... ... @@ -228,5 +244,6 @@ module.exports = {
getGiftCardAsync,
getOrderComputeAsync,
sendGiftCardCkeckSmsAsync,
checkGiftCardSmsCodeAsync,
orderSubmitAsync
};
... ...
... ... @@ -69,6 +69,9 @@ const getGiftCards = (uid) => ensureApi.getGiftCardAsync(uid).then(result => {
// 发送礼品卡使用校验短信
const sendGiftCardCkeckSms = (uid) => ensureApi.sendGiftCardCkeckSmsAsync(uid);
// 校验礼品卡使用短信验证码
const checkGiftCardSmsCode = (uid) => ensureApi.checkGiftCardSmsCodeAsync(uid);
// 订单计算
const compute = (uid, cartType, pa) => {
return ensureApi.getOrderComputeAsync(uid, cartType, pa.paymentType, pa.deliveryWay, pa).then(result => {
... ... @@ -125,5 +128,6 @@ module.exports = {
getGiftCards,
compute,
sendGiftCardCkeckSms,
checkGiftCardSmsCode,
submit
};
... ...
... ... @@ -33,7 +33,7 @@ router.get('/ensure/coupons', auth, ensure.getCoupons); // 结算优惠券列表
router.get('/ensure/giftcards', auth, ensure.getGiftCards); // 结算礼品卡列表
router.get('/ensure/couponcode', auth, ensure.convertCoupons); // 优惠码兑换券
router.post('/ensure/compute', auth, ensure.compute); // 价格重新计算
router.post('/ensure/submit', auth, ensure.submit); // 价格重新计算
router.post('/ensure/submit', auth, ensure.submitCheck, ensure.submit); // 订单提交
router.post('/property/checksms', ensure.sendCheckSms); // 虚拟资产使用校验
router.get('/easypay', auth, easypay.index); // 限购商品快捷结算页
... ...
... ... @@ -266,13 +266,6 @@
</thead>
<tbody>
<tr>
<td>YH436745362</td>
<td>$312312</td>
<td>$312312</td>
<td>2017.9.6</td>
<td><span class="gift-card-radio on" data-id="aotfnyc12285fw" data-price="100.00"></span></td>
</tr>
<tr>
<td colspan="5">暂无礼品卡</td>
</tr>
</tbody>
... ...
... ... @@ -104,6 +104,7 @@ const syncUserSession = (user, req, res) => {
});
req.session.USER_MOBILE = data.mobile;
req.session.TOKEN_ = publicToken;
req.session.LOGIN_UID_ = uid;
... ...
... ... @@ -33,6 +33,7 @@ module.exports = () => {
req.user.name = getName(userInfo); // 0
req.user.vip = getVip(userInfo); // 2
req.user.token = getToken(userInfo); // 3
req.user.mobile = req.session.USER_MOBILE;
req.user.isStudent = req.cookies.isStudent || 0;
req.user.uid = {
... ...
... ... @@ -14,8 +14,7 @@ var $balanceDetail = $('#balance-detail'),
$orderPrice = $('#order-price');
var order = {
printPrice: 'Y',
giftCard: 'eqweqw'
printPrice: 'Y'
};
var payWay,
... ... @@ -690,7 +689,6 @@ giftCard = {
return;
}
this.$giftCardWrap = this.$el.next();
this.getList();
... ... @@ -706,7 +704,12 @@ giftCard = {
if (data.code === 200) {
$('.can-use-tip', that.$el).text('(' + data.data.usable_giftCards.length + '张可用)');
$('tbody', that.$giftCardWrap).html(giftCardTpl(data.data));
that.$radios = $('.gift-card-radio', that.$giftCardWrap);
that.checkContent = '<h2>安全验证</h2>' +
'<p class="tip-info">您正在使用礼品卡支付,为了保障您的安全,请进行安全验证。</p>' +
'<p class="receiver-info">验证码已发送至' + (data.data.userMobile || '您绑定的') + '手机号</p>' +
'<p><input type="text" placeholder="短信验证码" maxlength="8"><span class="send-sms">获取验证码</span></p>';
}
});
},
... ... @@ -746,6 +749,10 @@ giftCard = {
compute();
},
setUseStatus: function(price) {
if (!this.$radios) {
return;
}
if (price && price * 1 > 0) {
this.$radios.filter('.disable').removeClass('disable');
} else {
... ... @@ -771,8 +778,6 @@ refund = {
}
};
$('.locker-switch').click(function() {
var $this = $(this),
$par = $this.parent();
... ... @@ -972,9 +977,10 @@ $('#order-submit').click(function() {
return;
}
// 使用礼品卡时候进行短信校验
if (order.giftCard) {
checkDg = new dialog.Dialog({
content: '<p>您正在使用礼品卡支付,为了保障您的安全,请进行安全验证。</p><span class="send-sms"></span>',
content: giftCard.checkContent || '',
className: 'gift-card-check-dialog',
btns: [{
id: 'check-cancel',
... ... @@ -986,48 +992,60 @@ $('#order-submit').click(function() {
}, {
id: 'check-sure',
btnClass: ['check-sure'],
name: '返回购物车',
name: '确定使用',
cb: function() {
order.checkCode = '';
submitOrder(order);
order.checkCode = $('input', checkDg.$el).val();
if (order.checkCode) {
submitOrder(order);
checkDg.close();
}
}
}]
}).show();
});
checkDg.$sendBtn = $('.send-sms', checkDg.$el);
checkDg.countdown = function() {
checkDg.sendSms = function() {
var that = this;
if (!this.$sendBtn || this.seconds > 0) {
return;
}
sendCkeckSms(); // 发送验证码
if (!this.seconds || this.seconds < 1) {
this.seconds = 59;
}
this.timer && clearInterval(this.timer);
this.$sendBtn.text((this.seconds--) + 's').addClass('timer');
this.timer = setInterval(function() {
if (checkDg.seconds > 0) {
checkDg.$sendBtn.text((checkDg.seconds--) + 's');
if (that.seconds > 0) {
that.$sendBtn.text((that.seconds--) + 's').addClass('timer');
} else {
checkDg.$sendBtn.text('获取验证码');
clearInterval(checkDg.timer);
that.$sendBtn.text('获取验证码').removeClass('timer');
clearInterval(that.timer);
}
}, 1000);
return this;
};
checkDg.$sendBtn.click(function() {
checkDg.countdown();
checkDg.sendSms();
});
sendCkeckSms(); // 发送验证码
checkDg.countdown(); // 倒计时
checkDg.sendSms().show();
return;
} else {
order.checkCode && delete order.checkCode;
}
submitOrder(order);
});
payWay.init();
... ...
... ... @@ -1872,3 +1872,70 @@
padding: 0 6px;
}
}
.gift-card-check-dialog {
font-size: 14px;
.close {
display: none;
}
.content {
width: 352px;
padding: 0 30px;
h2 {
font-size: 18px;
margin-bottom: 26px;
}
> p {
line-height: 2;
}
input {
width: 170px;
height: 30px;
padding-left: 10px;
box-sizing: border-box;
}
.send-sms {
width: 110px;
height: 30px;
color: #fff;
margin-left: 20px;
background-color: #494949;
display: inline-block;
cursor: pointer;
}
.send-sms.timer {
background-color: #b0b0b0;
cursor: default;
}
}
.tip-info {
text-align: left;
}
.receiver-info {
padding: 24px 0 30px;
}
.btns {
padding-top: 30px;
.btn {
min-width: 100px;
padding: 0;
}
.check-sure {
background-color: #000;
color: #fff;
margin-left: 96px;
}
}
}
... ...