...
|
...
|
@@ -43,6 +43,14 @@ class BuyNowController { |
|
|
let product_sku = req.query.product_sku;
|
|
|
let buy_number = req.query.buy_number;
|
|
|
|
|
|
let isGroup = req.query.is_group || '0';
|
|
|
|
|
|
if (isGroup === '1') {
|
|
|
isGroup = false;
|
|
|
} else {
|
|
|
isGroup = true;
|
|
|
}
|
|
|
|
|
|
if (!product_sku || !buy_number) {
|
|
|
return next();
|
|
|
}
|
...
|
...
|
@@ -72,103 +80,208 @@ class BuyNowController { |
|
|
});
|
|
|
}
|
|
|
|
|
|
co(function * () {
|
|
|
let [userProfile, address, result, computeData, validCouponCount, validGiftCardCount] =
|
|
|
yield Promise.all([
|
|
|
req.ctx(userModel).queryProfile(uid),
|
|
|
req.ctx(addressModel).addressData(uid),
|
|
|
req.ctx(BuyNowModel).payment({
|
|
|
uid: uid,
|
|
|
product_sku: product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number,
|
|
|
yoho_coin_mode: parseInt(orderInfo.use_yoho_coin, 10) > 0 ? 1 : 0
|
|
|
}),
|
|
|
computerPromise,
|
|
|
req.ctx(BuyNowModel).countUsableCoupon({
|
|
|
uid: uid,
|
|
|
product_sku: req.query.product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number,
|
|
|
delivery_way: orderInfo.delivery_way
|
|
|
}),
|
|
|
req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量
|
|
|
]);
|
|
|
|
|
|
// 获取用户完整手机号
|
|
|
let mobile = _.get(userProfile, 'data.mobile', '');
|
|
|
let orderAddress = _.get(result, 'address', []);
|
|
|
let addressList = _.get(address, 'data', []);
|
|
|
let autoSelectCouponCodeStr = _.get(result, 'data.coupon_pay.coupon_code', '');
|
|
|
let orderEnsure = {};
|
|
|
|
|
|
if (result.code !== 200 && result.message) {
|
|
|
orderEnsure = {message: result.message};
|
|
|
} else {
|
|
|
orderAddress.length && _.forEach(addressList, address => { //eslint-disable-line
|
|
|
if (address.address_id === orderAddress.address_id) {
|
|
|
mobile = address.mobile;
|
|
|
return false;
|
|
|
if (isGroup) {
|
|
|
co(function * () {
|
|
|
let [userProfile, address, result, computeData, validCouponCount, validGiftCardCount] =
|
|
|
yield Promise.all([
|
|
|
req.ctx(userModel).queryProfile(uid),
|
|
|
req.ctx(addressModel).addressData(uid),
|
|
|
req.ctx(BuyNowModel).payment({
|
|
|
uid: uid,
|
|
|
product_sku: product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number,
|
|
|
yoho_coin_mode: parseInt(orderInfo.use_yoho_coin, 10) > 0 ? 1 : 0
|
|
|
}),
|
|
|
computerPromise,
|
|
|
req.ctx(BuyNowModel).countUsableCoupon({
|
|
|
uid: uid,
|
|
|
product_sku: req.query.product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number,
|
|
|
delivery_way: orderInfo.delivery_way
|
|
|
}),
|
|
|
req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量
|
|
|
]);
|
|
|
|
|
|
// 获取用户完整手机号
|
|
|
let mobile = _.get(userProfile, 'data.mobile', '');
|
|
|
let orderAddress = _.get(result, 'address', []);
|
|
|
let addressList = _.get(address, 'data', []);
|
|
|
let autoSelectCouponCodeStr = _.get(result, 'data.coupon_pay.coupon_code', '');
|
|
|
let orderEnsure = {};
|
|
|
|
|
|
if (result.code !== 200 && result.message) {
|
|
|
orderEnsure = {message: result.message};
|
|
|
} else {
|
|
|
orderAddress.length && _.forEach(addressList, address => { //eslint-disable-line
|
|
|
if (address.address_id === orderAddress.address_id) {
|
|
|
mobile = address.mobile;
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (orderInfo.user_check_coupon !== 'Y' && autoSelectCouponCodeStr) {
|
|
|
orderInfo.coupon_code = autoSelectCouponCodeStr;
|
|
|
res.cookie('buynow_info', JSON.stringify(orderInfo), actCkOpthn);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (orderInfo.user_check_coupon !== 'Y' && autoSelectCouponCodeStr) {
|
|
|
orderInfo.coupon_code = autoSelectCouponCodeStr;
|
|
|
res.cookie('buynow_info', JSON.stringify(orderInfo), actCkOpthn);
|
|
|
// 兼容原有的数据格式
|
|
|
orderInfo.deliveryId = orderInfo.delivery_way;
|
|
|
orderInfo.deliveryTimeId = orderInfo.delivery_time;
|
|
|
orderInfo.couponCode = orderInfo.coupon_code;
|
|
|
orderInfo.yohoCoin = orderInfo.use_yoho_coin;
|
|
|
orderInfo.paymentType = orderInfo.payment_type;
|
|
|
|
|
|
orderEnsure = _.assign(
|
|
|
paymentProcess.tranformPayment(
|
|
|
_.get(result, 'data', {}), orderInfo, null, null,
|
|
|
_.get(computeData, 'data', {})),
|
|
|
{
|
|
|
coupon: paymentProcess.handleCoupons({
|
|
|
paymentApiCouponData: _.get(result, 'data.coupon_pay', {}),
|
|
|
validCouponCount: _.get(validCouponCount, 'data.count', 0),
|
|
|
orderComputeCouponPay: _.get(computeData, 'data.coupon_pay'),
|
|
|
userCheckCoupon: orderInfo.user_check_coupon
|
|
|
}),
|
|
|
selectAddressUrl: helpers.urlFormat('/cart/index/buynow/selectAddress', {
|
|
|
product_sku: product_sku,
|
|
|
buy_number: buy_number
|
|
|
}),
|
|
|
selectCouponUrl: helpers.urlFormat('/cart/index/buynow/selectCoupon', {
|
|
|
product_sku: product_sku,
|
|
|
buy_number: buy_number
|
|
|
}),
|
|
|
isOrdinaryCart: true,
|
|
|
isGroupCart: true,
|
|
|
choseGiftCard: helpers.urlFormat('/cart/index/buynow/selectGiftcard'),
|
|
|
giftCards: paymentProcess.handleGiftCards({
|
|
|
validGiftCardCount: _.get(validGiftCardCount, 'data.count', 0),
|
|
|
orderCompute: _.get(computeData, 'data', {})
|
|
|
})
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
// 兼容原有的数据格式
|
|
|
orderInfo.deliveryId = orderInfo.delivery_way;
|
|
|
orderInfo.deliveryTimeId = orderInfo.delivery_time;
|
|
|
orderInfo.couponCode = orderInfo.coupon_code;
|
|
|
orderInfo.yohoCoin = orderInfo.use_yoho_coin;
|
|
|
orderInfo.paymentType = orderInfo.payment_type;
|
|
|
|
|
|
orderEnsure = _.assign(
|
|
|
paymentProcess.tranformPayment(
|
|
|
_.get(result, 'data', {}), orderInfo, null, null,
|
|
|
_.get(computeData, 'data', {})),
|
|
|
{
|
|
|
coupon: paymentProcess.handleCoupons({
|
|
|
paymentApiCouponData: _.get(result, 'data.coupon_pay', {}),
|
|
|
validCouponCount: _.get(validCouponCount, 'data.count', 0),
|
|
|
orderComputeCouponPay: _.get(computeData, 'data.coupon_pay'),
|
|
|
userCheckCoupon: orderInfo.user_check_coupon
|
|
|
}),
|
|
|
selectAddressUrl: helpers.urlFormat('/cart/index/buynow/selectAddress', {
|
|
|
return res.render('buynow/order-ensure', {
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: '确认订单',
|
|
|
navBtn: false
|
|
|
}),
|
|
|
module: 'cart',
|
|
|
page: 'buynow-order-ensure',
|
|
|
title: '确认订单',
|
|
|
width750: true,
|
|
|
localCss: true,
|
|
|
product_sku: product_sku,
|
|
|
orderEnsure: orderEnsure,
|
|
|
userMobile: mobile
|
|
|
});
|
|
|
|
|
|
})().catch(next);
|
|
|
} else {
|
|
|
let activity_id = req.query.activity_id;
|
|
|
let group_no = req.query.group_no;
|
|
|
|
|
|
co(function * () {
|
|
|
let [userProfile, address, result, computeData, validCouponCount, validGiftCardCount] =
|
|
|
yield Promise.all([
|
|
|
req.ctx(userModel).queryProfile(uid),
|
|
|
req.ctx(addressModel).addressData(uid),
|
|
|
req.ctx(BuyNowModel).groupBuyPayment({
|
|
|
uid: uid,
|
|
|
product_sku: product_sku,
|
|
|
buy_number: buy_number
|
|
|
group_no,
|
|
|
activity_id: activity_id,
|
|
|
}),
|
|
|
selectCouponUrl: helpers.urlFormat('/cart/index/buynow/selectCoupon', {
|
|
|
product_sku: product_sku,
|
|
|
buy_number: buy_number
|
|
|
computerPromise,
|
|
|
req.ctx(BuyNowModel).countUsableCoupon({
|
|
|
uid: uid,
|
|
|
product_sku: req.query.product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number,
|
|
|
delivery_way: orderInfo.delivery_way
|
|
|
}),
|
|
|
isOrdinaryCart: true,
|
|
|
choseGiftCard: helpers.urlFormat('/cart/index/buynow/selectGiftcard'),
|
|
|
giftCards: paymentProcess.handleGiftCards({
|
|
|
validGiftCardCount: _.get(validGiftCardCount, 'data.count', 0),
|
|
|
orderCompute: _.get(computeData, 'data', {})
|
|
|
})
|
|
|
req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量
|
|
|
]);
|
|
|
|
|
|
// 获取用户完整手机号
|
|
|
let mobile = _.get(userProfile, 'data.mobile', '');
|
|
|
let orderAddress = _.get(result, 'address', []);
|
|
|
let addressList = _.get(address, 'data', []);
|
|
|
let autoSelectCouponCodeStr = _.get(result, 'data.coupon_pay.coupon_code', '');
|
|
|
let orderEnsure = {};
|
|
|
|
|
|
if (result.code !== 200 && result.message) {
|
|
|
orderEnsure = {message: result.message};
|
|
|
} else {
|
|
|
orderAddress.length && _.forEach(addressList, address => { //eslint-disable-line
|
|
|
if (address.address_id === orderAddress.address_id) {
|
|
|
mobile = address.mobile;
|
|
|
return false;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (orderInfo.user_check_coupon !== 'Y' && autoSelectCouponCodeStr) {
|
|
|
orderInfo.coupon_code = autoSelectCouponCodeStr;
|
|
|
res.cookie('buynow_info', JSON.stringify(orderInfo), actCkOpthn);
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
return res.render('buynow/order-ensure', {
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: '确认订单',
|
|
|
navBtn: false
|
|
|
}),
|
|
|
module: 'cart',
|
|
|
page: 'buynow-order-ensure',
|
|
|
title: '确认订单',
|
|
|
width750: true,
|
|
|
localCss: true,
|
|
|
product_sku: product_sku,
|
|
|
orderEnsure: orderEnsure,
|
|
|
userMobile: mobile
|
|
|
});
|
|
|
// 兼容原有的数据格式
|
|
|
orderInfo.deliveryId = orderInfo.delivery_way;
|
|
|
orderInfo.deliveryTimeId = orderInfo.delivery_time;
|
|
|
orderInfo.couponCode = orderInfo.coupon_code;
|
|
|
orderInfo.yohoCoin = orderInfo.use_yoho_coin;
|
|
|
orderInfo.paymentType = orderInfo.payment_type;
|
|
|
|
|
|
orderEnsure = _.assign(
|
|
|
paymentProcess.tranformPayment(
|
|
|
_.get(result, 'data', {}), orderInfo, null, null,
|
|
|
_.get(computeData, 'data', {})),
|
|
|
{
|
|
|
coupon: paymentProcess.handleCoupons({
|
|
|
paymentApiCouponData: _.get(result, 'data.coupon_pay', {}),
|
|
|
validCouponCount: _.get(validCouponCount, 'data.count', 0),
|
|
|
orderComputeCouponPay: _.get(computeData, 'data.coupon_pay'),
|
|
|
userCheckCoupon: orderInfo.user_check_coupon
|
|
|
}),
|
|
|
selectAddressUrl: helpers.urlFormat('/cart/index/buynow/selectAddress', {
|
|
|
product_sku: product_sku,
|
|
|
buy_number: buy_number
|
|
|
}),
|
|
|
selectCouponUrl: helpers.urlFormat('/cart/index/buynow/selectCoupon', {
|
|
|
product_sku: product_sku,
|
|
|
buy_number: buy_number
|
|
|
}),
|
|
|
isOrdinaryCart: false,
|
|
|
isGroupCart: false,
|
|
|
choseGiftCard: helpers.urlFormat('/cart/index/buynow/selectGiftcard'),
|
|
|
giftCards: paymentProcess.handleGiftCards({
|
|
|
validGiftCardCount: _.get(validGiftCardCount, 'data.count', 0),
|
|
|
orderCompute: _.get(computeData, 'data', {})
|
|
|
})
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
return res.render('buynow/order-ensure', {
|
|
|
pageHeader: headerModel.setNav({
|
|
|
navTitle: '确认订单',
|
|
|
navBtn: false
|
|
|
}),
|
|
|
module: 'cart',
|
|
|
page: 'buynow-order-ensure',
|
|
|
title: '确认订单',
|
|
|
width750: true,
|
|
|
localCss: true,
|
|
|
product_sku: product_sku,
|
|
|
orderEnsure: orderEnsure,
|
|
|
userMobile: mobile
|
|
|
});
|
|
|
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
|