Authored by 郭成尧

verifyCodeHandle

'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const co = require('bluebird').coroutine;
const co = Promise.coroutine;
const cartModel = require('../models/cart');
const headerModel = require('../../../doraemon/models/header');
const userModel = require('../models/user');
... ... @@ -211,6 +211,7 @@ exports.orderSub = (req, res, next) => {
let msg = req.body.msg || null;
let couponCode = req.body.couponCode || null;
let gift_card_code = req.body.gift_card_code || null;
let verifyCode = req.body.verifyCode || null;
let yohoCoin = req.body.yohoCoin || 0;
let skuList = req.body.skuList || '';
let isPrintPrice = req.body.isPrintPrice || 'Y';
... ... @@ -258,6 +259,23 @@ exports.orderSub = (req, res, next) => {
}
return co(function* () {
// 使用礼品卡,发送验证码
if (gift_card_code) {
if (!verifyCode) {
yield orderModel.giftCardSendSms(uid);
return res.json({
code: 411
});
} else {
let verifyResult = yield orderModel.validRegCode(uid, verifyCode);
if (verifyResult.code !== 200) {
return res.json(verifyResult);
}
}
}
let result;
let params = {
uid: uid,
... ... @@ -536,3 +554,14 @@ exports.jitDetail = (req, res, next) => {
}));
})().catch(next);
};
/**
* 重发验证码
*/
exports.giftCardSendSms = (req, res, next) => {
let uid = req.user.uid;
orderModel.giftCardSendSms(uid).then(result => {
res.json(result);
}).catch(next);
};
... ...
... ... @@ -91,8 +91,20 @@ const giftCardSendSms = (uid) => {
});
};
/**
* 礼品卡支付时验证短信验证码
*/
const validRegCode = (uid, verifyCode) => {
return api.get('', {
method: 'app.giftcard.validRegCode',
uid: uid,
code: verifyCode
});
};
module.exports = {
processInvoiceData,
isNewUser,
giftCardSendSms
giftCardSendSms,
validRegCode
};
... ...
... ... @@ -59,8 +59,10 @@ class OrderEnsure extends Page {
/**
* 验证码弹窗
* @param {手机号} mobile
* @param {弹窗确定事件的回调} sureCallback
*/
showSafeCheckDialog(mobile) {
showSafeCheckDialog(mobile, sureCallback) {
dialog.showDialog({
hasHeader: '安全验证',
dialogText: safeCheckBoxHbs({ mobile: mobile }),
... ... @@ -69,7 +71,10 @@ class OrderEnsure extends Page {
rightBtnText: '确定'
}
});
dialog.removeClickEvent(this.sckDialogClickHandle(this.sureCallback));
dialog.rewriteEvents().then(() => {
this.sckDialogClickHandle(sureCallback);
});
}
/**
... ... @@ -105,7 +110,7 @@ class OrderEnsure extends Page {
$sureBtn.on('click', () => {
if ($(event.target).hasClass('active')) {
return sureCallback();
sureCallback($verifyCodeInput.val());
}
});
}
... ...
... ... @@ -171,7 +171,11 @@ function orderCompute() {
});
}
function submitOrder() {
/**
* 提交订单
* @param {短信验证码} verifyCode
*/
function submitOrder(verifyCode) {
let msg = $('#msg').find('input').val() || orderInfo('msg');
if (isSubmiting) {
... ... @@ -198,6 +202,7 @@ function submitOrder() {
paymentType: orderInfo('paymentType'), // 支付方式
couponCode: orderInfo('couponCode'),
gift_card_code: orderInfo('gift_card_code'),
verifyCode: verifyCode || null,
yohoCoin: orderInfo('yohoCoin'),
skuList: isLimitGood() ? orderInfo('skuList') : void 0
};
... ... @@ -265,7 +270,7 @@ function submitOrder() {
} else if (res.code === 409) {
richTip.show(res.message, res.buttons);
} else if (res.code === 411) {
orderEnsure.showSafeCheckDialog();
orderEnsure.showSafeCheckDialog('123456789', submitOrder);
} else if (res.message) {
tip.show(res.message);
}
... ...
... ... @@ -90,12 +90,12 @@ exports.hideDialog = function() {
$('.dialog-wrapper').remove();
};
exports.removeClickEvent = (callback) => {
/**
* 重写事件绑定
*/
exports.rewriteEvents = () => {
setTimeout(() => {
$('.dialog-wrapper').off();
if (callback) {
return callback();
}
}, 600);
return Promise.resolve();
};
... ...