...
|
...
|
@@ -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') {
|
...
|
...
|
|