Authored by 毕凯

Merge branch 'feature/bugfix61' into 'release/6.1'

giftcard-support



See merge request !918
... ... @@ -4,10 +4,15 @@
'use strict';
const _ = require('lodash');
const crypto = global.yoho.crypto;
const helpers = global.yoho.helpers;
const co = Promise.coroutine;
const userModel = require('../models/user');
const addressModel = require('../models/address');
const seckillModel = require('../models/seckill');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const orderModel = require('../models/order');
const shoppingModel = require('../models/shopping');
const paymentProcess = require(global.utils + '/payment-process');
const BAD_REQUEST = '非法请求';
const SLAT = 'yohobuyseckill98';
... ... @@ -77,13 +82,31 @@ exports.ensure = (req, res, next) => {
orderComputerData = yield req.ctx(seckillModel).compute(_.assign(paymentOption, {
delivery_way: orderInfo.deliveryId || 1,
payment_type: orderInfo.paymentType || 1,
use_yoho_coin: orderInfo.yohoCoin || 0
use_yoho_coin: orderInfo.yohoCoin || 0,
gift_card_code: orderInfo.gift_card_code || null
}));
}
// 获取结算 数据
let paymentInfo =
yield req.ctx(seckillModel).payment(paymentOption, orderInfo, _.get(orderComputerData, 'data'));
let [userProfile, address, paymentInfo, validGiftCardCountData] = yield Promise.all([
req.ctx(userModel).queryProfile(uid),
req.ctx(addressModel).addressData(uid),
req.ctx(seckillModel).payment(paymentOption, orderInfo, _.get(orderComputerData, 'data')),
req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量
]);
let validGiftCardCount = _.get(validGiftCardCountData, 'data.count', 0);
// 获取用户完整手机号
let mobile = _.get(userProfile, 'data.mobile', '');
let orderAddress = _.get(paymentInfo, 'address', []);
let addressList = _.get(address, 'data', []);
orderAddress.length && _.forEach(addressList, address => { //eslint-disable-line
if (address.address_id === orderAddress.address_id) {
mobile = address.mobile;
return false;
}
});
if (paymentInfo.code !== 200) {
view = {
... ... @@ -97,11 +120,17 @@ exports.ensure = (req, res, next) => {
}
} else {
// 渲染
view = Object.assign({
view = _.assign({
seckill: skillData,
orderEnsure: true,
sku,
}, paymentInfo.data);
}, paymentInfo.data, {
choseGiftCard: helpers.urlFormat('/cart/index/new/selectGiftcard'),
giftCards: paymentProcess.handleGiftCards({
validGiftCardCount: validGiftCardCount,
orderCompute: _.get(orderComputerData, 'data')
})
});
}
res.locals.title = '确认订单';
... ... @@ -114,7 +143,7 @@ exports.ensure = (req, res, next) => {
}),
width750: true,
localCss: true,
userMobile: view.phoneNum,
userMobile: mobile,
cartToken: crypto.encryption(SLAT, [sku, activityId].join(''))
}, view));
})().catch(next);
... ... @@ -147,6 +176,7 @@ exports.compute = (req, res, next) => {
product_sku: sku,
delivery_way: req.body.deliveryId || 1,
use_yoho_coin: req.body.yohoCoin || 0,
gift_card_code: req.body.gift_card_code,
activity_id: activityId
};
... ... @@ -210,7 +240,8 @@ exports.submit = (req, res, next) => {
product_sku: sku,
activity_id: activityId,
uid,
ip: req.ip || ''
ip: req.ip || '',
udid: req.sessionID || 'yoho'
};
if (req.body.invoice === 'true') {
... ...
'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 参数
const actCkOpthn = {
path: '/cart/index'
};
const ticketsConfirm = (req, res) => {
const ticketsConfirm = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '确认订单',
navBtn: false
... ... @@ -19,8 +24,6 @@ const ticketsConfirm = (req, res) => {
module: 'cart',
page: 'tickets-confirm',
title: '确认订单',
// pageFooter: true,
localCss: true,
navBtn: false,
width750: true
... ... @@ -37,27 +40,68 @@ const ticketsConfirm = (req, res) => {
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.gift_card_code || null,
yohoCoinMode: true
};
req.ctx(ticketsConfirmModel).ticketsConfirm(params).then(result => {
res.render('ticketsConfirm', Object.assign(responseData, result));
});
co(function* () {
let [result, validGiftCardCountData] = yield Promise.all([
req.ctx(ticketsConfirmModel).ticketsConfirm(params),
req.ctx(shoppingModel).countUsableGiftCard(req.user.uid) // 可用礼品卡数量
]);
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
})
}));
})().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
useYohoCoin: req.body.useYohoCoin,
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 = '人太多啦,稍后再试!';
}
... ... @@ -65,7 +109,7 @@ const submitTicket = (req, res) => {
// 提交成功清除Cookie
res.cookie('order-info', null, actCkOpthn);
res.json(result);
});
})().catch(next);
};
const checkTickets = (req, res) => {
... ...
... ... @@ -18,6 +18,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel {
product_sku: param.productSku,
buy_number: param.buyNumber,
use_yoho_coin: param.useYohoCoin || 0,
gift_card_code: param.gift_card_code || null,
yoho_coin_mode: param.yohoCoinMode ? param.yohoCoinMode : 0
}}).then((result) => {
return result;
... ... @@ -93,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;
});
... ... @@ -108,7 +110,9 @@ class ticketsConfirmModel extends global.yoho.BaseModel {
buy_number: param.buyNumber,
mobile: param.mobile,
use_yoho_coin: param.useYohoCoin,
qhy_union: ''
gift_card_code: param.gift_card_code || null,
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,12 +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')
useYohoCoin: orderInfo('yohoCoin'),
gift_card_code: orderInfo('gift_card_code'),
verifyCode: verifyCode || null
};
if (!$ticketsMobile.val()) {
... ... @@ -501,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);
}
... ...
... ... @@ -154,6 +154,7 @@ function orderCompute() {
deliveryId: deliverId, // 配送方式id
paymentType: orderInfo('paymentType'),
yohoCoin: yohoCoin,
gift_card_code: orderInfo('gift_card_code'),
sku: productSku,
activityId: activityId
};
... ...
... ... @@ -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%;
... ...