Authored by 郭成尧

add-giftcard

... ... @@ -4,6 +4,7 @@
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const helpers = global.yoho.helpers;
const co = Promise.coroutine;
const seckillModel = require('../models/seckill');
const headerModel = require('../../../doraemon/models/header'); // 头部model
... ... @@ -80,7 +81,7 @@ exports.ensure = (req, res, next) => {
delivery_way: orderInfo.deliveryId || 1,
payment_type: orderInfo.paymentType || 1,
use_yoho_coin: orderInfo.yohoCoin || 0,
gift_card_code: orderInfo.body.gift_card_code || null
gift_card_code: orderInfo.gift_card_code || null
}));
}
... ... @@ -108,9 +109,10 @@ exports.ensure = (req, res, next) => {
orderEnsure: true,
sku,
}, paymentInfo.data, {
choseGiftCard: helpers.urlFormat('/cart/index/new/selectGiftcard'),
giftCards: paymentProcess.handleGiftCards({
validGiftCardCount: validGiftCardCount,
orderCompute: orderComputerData
orderCompute: _.get(orderComputerData, 'data')
})
});
}
... ...
'use strict';
const _ = require('lodash');
const co = Promise.coroutine;
const helpers = global.yoho.helpers;
const headerModel = require('../../../doraemon/models/header'); // 头部model
const ticketsConfirmModel = require('../models/ticketsConfirm');
const shoppingModel = require('../models/shopping');
const orderModel = require('../models/order');
const paymentProcess = require(global.utils + '/payment-process');
// cookie 参数
... ... @@ -38,10 +40,10 @@ const ticketsConfirm = (req, res, next) => {
let params = {
uid: req.user.uid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
productSku: req.query.productSku,
buyNumber: req.query.buyNumber,
useYohoCoin: orderInfo ? orderInfo.yohoCoin : 0,
gift_card_code: orderInfo.body.gift_card_code || null,
gift_card_code: orderInfo.gift_card_code || null,
yohoCoinMode: true
};
... ... @@ -53,25 +55,53 @@ const ticketsConfirm = (req, res, next) => {
let validGiftCardCount = _.get(validGiftCardCountData, 'data.count', 0);
res.render('ticketsConfirm', _.assign(responseData, result, {
choseGiftCard: helpers.urlFormat('/cart/index/new/selectGiftcard'),
giftCards: paymentProcess.handleGiftCards({
validGiftCardCount: validGiftCardCount,
orderCompute: result
orderCompute: result.orderCompute
})
}));
})().catch(next);
};
const submitTicket = (req, res) => {
const submitTicket = (req, res, next) => {
let uid = req.user.uid;
let udid = req.sessionID || 'yoho';
let gift_card_code = req.body.gift_card_code;
let verifyCode = req.body.verifyCode;
let params = {
uid: req.user.uid,
uid: uid,
udid: udid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
mobile: req.body.mobile,
useYohoCoin: req.body.useYohoCoin,
gift_card_code: req.body.gift_card_code
gift_card_code: gift_card_code,
verifyCode: verifyCode
};
req.ctx(ticketsConfirmModel).submitTicket(params).then(result => {
co(function* () {
// 使用礼品卡,发送验证码
if (gift_card_code) {
if (!verifyCode) {
yield req.ctx(orderModel).giftCardSendSms(uid);
return res.json({
code: 411
});
} else {
let verifyResult = yield req.ctx(orderModel).validRegCode({
uid, verifyCode, udid
});
if (verifyResult.code !== 200) {
return res.json(verifyResult);
}
}
}
let result = yield req.ctx(ticketsConfirmModel).submitTicket(params);
if (result === {}) {
result.message = '人太多啦,稍后再试!';
}
... ... @@ -79,7 +109,7 @@ const submitTicket = (req, res) => {
// 提交成功清除Cookie
res.cookie('order-info', null, actCkOpthn);
res.json(result);
});
})().catch(next);
};
const checkTickets = (req, res) => {
... ...
... ... @@ -94,6 +94,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel {
resu.cartPayData = result[0].data.shopping_cart_data.promotion_formula_list;
resu.price = parseInt(result[0].data.shopping_cart_data.last_order_amount, 10).toFixed(2);
resu.yohoCoinCompute = this.yohoCoinCompute(result[0].data.shopping_cart_data);
resu.orderCompute = _.get(result[0], 'data');
}
return resu;
});
... ... @@ -110,7 +111,8 @@ class ticketsConfirmModel extends global.yoho.BaseModel {
mobile: param.mobile,
use_yoho_coin: param.useYohoCoin,
gift_card_code: param.gift_card_code || null,
qhy_union: ''
qhy_union: '',
udid: param.udid
}}).then((result) => {
return result;
});
... ...
... ... @@ -80,7 +80,7 @@ router.get('/index/buynow/selectGiftcard', authMW, BuyNowController.selectGiftca
router.get('/home/orders/paynew', authMW, payController.payCenter);
// 门票确认
router.post('/index/ticketsConfirm', authMW, ticketsConfirmController.ticketsConfirm);
router.get('/index/ticketsConfirm', authMW, ticketsConfirmController.ticketsConfirm);
// 门票下单
router.post('/index/submitTicket', ticketsConfirmController.submitTicket);
... ...
... ... @@ -51,6 +51,22 @@
</li>
</ul>
</div>
{{!-- 礼品卡 --}}
{{#if giftCards}}
<div class="gift-card">
<ul class="sale-invoice">
<li><a href="{{choseGiftCard}}">
<span class="title">礼品卡</span>
{{# giftCards}}
<span class="count">{{leftInfo}}</span>
<span class="coupon-info pull-right">
{{rightInfo}}<i class="iconfont">&#xe614;</i>
</span>
{{/giftCards}}
</a></li>
</ul>
</div>
{{/if}}
<div class="sub-block delivery-id">
<h3>
<p>发票</p>
... ...
... ... @@ -64,9 +64,9 @@ class OrderEnsure extends Page {
showSafeCheckDialog(renderData, sureCallback) {
dialog.showDialog({
hasHeader: '安全验证',
dialogText: safeCheckBoxHbs(Object.assign(renderData, {
dialogText: safeCheckBoxHbs(Object.assign({
mobile: this.selector.userMobile.val()
})),
}, renderData)),
hasFooter: {
leftBtnText: '取消',
rightBtnText: '确定'
... ...
... ... @@ -478,13 +478,14 @@ if (orderInfo('address') && orderInfo('address').is_support === 'N') {
}
// 电子票下单
function ticketsConfirm() {
function ticketsConfirm(verifyCode) {
let data = {
productSku: productSku,
buyNumber: buyNumber,
mobile: $ticketsMobile.val(),
useYohoCoin: orderInfo('yohoCoin'),
gift_card_code: orderInfo('gift_card_code')
gift_card_code: orderInfo('gift_card_code'),
verifyCode: verifyCode || null
};
if (!$ticketsMobile.val()) {
... ... @@ -502,6 +503,11 @@ function ticketsConfirm() {
// 下单成功调整支付页面
if (ticket.code === 200) {
window.location.href = '/home/orders/paynew?order_code=' + ticket.data.order_code;
} else if (ticket.code === 411) {
orderEnsure.showSafeCheckDialog({
message: ticket.message,
mobile: $ticketsMobile.val()
}, ticketsConfirm);
} else {
tip.show(ticket.message);
}
... ...
... ... @@ -25,9 +25,8 @@ let functions = {
}
tip.show(addRestult.message || '人太多啦,稍后再试!');
} else {
$('#productSku').val(productSku);
$('#buyNumber').val(buyNumber);
$('#buyNowForm').submit();
window.location.href = '/cart/index/ticketsConfirm?productSku=' + productSku +
'&buyNumber=' + buyNumber;
}
},
error: function() {
... ...
... ... @@ -27,6 +27,7 @@
}
}
.gift-card,
.yoho-coin {
margin: 0 2.5%;
width: 95%;
... ...