...
|
...
|
@@ -52,6 +52,26 @@ class BuyNowController { |
|
|
res.clearCookie('buynow_info', actCkOpthn);
|
|
|
}
|
|
|
|
|
|
// 是否需要重新计算
|
|
|
let needReComputer = orderInfo && !_.isEmpty(orderInfo) &&
|
|
|
(orderInfo.yohoCoin || orderInfo.coupon_code);
|
|
|
let computerPromise = null;
|
|
|
|
|
|
if (needReComputer) {
|
|
|
computerPromise = req.ctx(BuyNowModel).compute({
|
|
|
uid: uid,
|
|
|
product_sku: product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number,
|
|
|
payment_type: orderInfo.payment_type,
|
|
|
delivery_way: orderInfo.delivery_way,
|
|
|
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10),
|
|
|
coupon_code: orderInfo.coupon_code,
|
|
|
gift_card_code: orderInfo.gift_card_code,
|
|
|
promotion_code: orderInfo.promotion_code
|
|
|
});
|
|
|
}
|
|
|
|
|
|
co(function * () {
|
|
|
let [userProfile, address, result, computeData, validCouponCount, validGiftCardCount] =
|
|
|
yield Promise.all([
|
...
|
...
|
@@ -64,23 +84,13 @@ class BuyNowController { |
|
|
buy_number: buy_number,
|
|
|
yoho_coin_mode: parseInt(orderInfo.use_yoho_coin, 10) > 0 ? 1 : 0
|
|
|
}),
|
|
|
req.ctx(BuyNowModel).compute({
|
|
|
uid: uid,
|
|
|
product_sku: product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number,
|
|
|
payment_type: orderInfo.payment_type,
|
|
|
delivery_way: orderInfo.delivery_way,
|
|
|
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10),
|
|
|
coupon_code: orderInfo.coupon_code,
|
|
|
gift_card_code: orderInfo.gift_card_code,
|
|
|
promotion_code: orderInfo.promotion_code
|
|
|
}),
|
|
|
computerPromise,
|
|
|
req.ctx(BuyNowModel).countUsableCoupon({
|
|
|
uid: uid,
|
|
|
product_sku: req.query.product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: buy_number
|
|
|
buy_number: buy_number,
|
|
|
delivery_way: orderInfo.delivery_way
|
|
|
}),
|
|
|
req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量
|
|
|
]);
|
...
|
...
|
@@ -89,6 +99,7 @@ class BuyNowController { |
|
|
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) {
|
...
|
...
|
@@ -101,6 +112,11 @@ class BuyNowController { |
|
|
}
|
|
|
});
|
|
|
|
|
|
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;
|
...
|
...
|
@@ -109,13 +125,16 @@ class BuyNowController { |
|
|
orderInfo.paymentType = orderInfo.payment_type;
|
|
|
|
|
|
orderEnsure = _.assign(
|
|
|
paymentProcess.tranformPayment(_.get(result, 'data', {}), orderInfo, null, null, computeData.data),
|
|
|
paymentProcess.tranformPayment(
|
|
|
_.get(result, 'data', {}), orderInfo, null, null,
|
|
|
_.get(computeData, 'data', {})),
|
|
|
{
|
|
|
coupon: paymentProcess.coupon(
|
|
|
_.get(validCouponCount, 'data.count', 0),
|
|
|
orderInfo,
|
|
|
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
|
...
|
...
|
@@ -128,7 +147,7 @@ class BuyNowController { |
|
|
choseGiftCard: helpers.urlFormat('/cart/index/buynow/selectGiftcard'),
|
|
|
giftCards: paymentProcess.handleGiftCards({
|
|
|
validGiftCardCount: _.get(validGiftCardCount, 'data.count', 0),
|
|
|
orderCompute: computeData.data
|
|
|
orderCompute: _.get(computeData, 'data', {})
|
|
|
})
|
|
|
}
|
|
|
);
|
...
|
...
|
@@ -159,26 +178,51 @@ class BuyNowController { |
|
|
* @param {*} next
|
|
|
*/
|
|
|
orderCompute(req, res, next) {
|
|
|
co(function * () {
|
|
|
let result = yield req.ctx(BuyNowModel).compute({
|
|
|
uid: req.user.uid,
|
|
|
cart_type: req.body.cart_type,
|
|
|
delivery_way: req.body.delivery_way,
|
|
|
payment_type: req.body.payment_type,
|
|
|
product_sku: req.body.product_sku,
|
|
|
buy_number: req.body.buy_number,
|
|
|
coupon_code: req.body.coupon_code,
|
|
|
gift_card_code: req.body.gift_card_code,
|
|
|
use_yoho_coin: req.body.use_yoho_coin
|
|
|
});
|
|
|
let orderInfo;
|
|
|
|
|
|
try {
|
|
|
orderInfo = JSON.parse(req.cookies.buynow_info);
|
|
|
} catch (e) {
|
|
|
logger.info(`orderEnsure: get buynow-order-info from cookie error:${JSON.stringify(e)}`);
|
|
|
orderInfo = {};
|
|
|
res.clearCookie('buynow_info', actCkOpthn);
|
|
|
}
|
|
|
|
|
|
co(function* () {
|
|
|
let [result, validCouponCount] = yield Promise.all([
|
|
|
req.ctx(BuyNowModel).compute({
|
|
|
uid: req.user.uid,
|
|
|
cart_type: req.body.cart_type,
|
|
|
delivery_way: req.body.delivery_way,
|
|
|
payment_type: req.body.payment_type,
|
|
|
product_sku: req.body.product_sku,
|
|
|
buy_number: req.body.buy_number,
|
|
|
coupon_code: req.body.coupon_code,
|
|
|
gift_card_code: req.body.gift_card_code,
|
|
|
use_yoho_coin: req.body.use_yoho_coin
|
|
|
}),
|
|
|
req.ctx(BuyNowModel).countUsableCoupon({
|
|
|
uid: req.user.uid,
|
|
|
product_sku: req.body.product_sku,
|
|
|
sku_type: req.body.sku_type,
|
|
|
buy_number: req.body.buy_number,
|
|
|
delivery_way: req.body.delivery_way
|
|
|
})
|
|
|
]);
|
|
|
|
|
|
let finalResult = _.get(result, 'data', {});
|
|
|
|
|
|
if (finalResult) {
|
|
|
_.set(finalResult, 'use_yoho_coin', paymentProcess.transPrice(_.get(result, 'data.use_yoho_coin')));
|
|
|
_.set(finalResult, 'yohoCoinCompute', paymentProcess.yohoCoinCompute(result.data));
|
|
|
_.set(finalResult, 'coupon', paymentProcess.handleCoupons({
|
|
|
paymentApiCouponData: {},
|
|
|
validCouponCount: _.get(validCouponCount, 'data.count', 0),
|
|
|
orderComputeCouponPay: _.get(finalResult, 'coupon_pay'),
|
|
|
userCheckCoupon: orderInfo.user_check_coupon
|
|
|
}));
|
|
|
}
|
|
|
return res.json(result.data);
|
|
|
return res.json(finalResult);
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -363,21 +407,70 @@ class BuyNowController { |
|
|
selectCoupon(req, res) {
|
|
|
let headerData = headerModel.setNav({
|
|
|
navTitle: '选择优惠券',
|
|
|
myConponPageNavBtn: true,
|
|
|
navBtn: false
|
|
|
});
|
|
|
|
|
|
res.render('select-coupon', {
|
|
|
res.render('select-coupons-page', {
|
|
|
module: 'cart',
|
|
|
page: 'buynow-select-coupon',
|
|
|
page: 'buynow-select-coupons',
|
|
|
title: '选择优惠券',
|
|
|
selectCouponPage: true,
|
|
|
pageHeader: headerData,
|
|
|
pageFooter: false,
|
|
|
localCss: true
|
|
|
localCss: true,
|
|
|
width750: true
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取用户可用和不可用优惠券列表
|
|
|
*/
|
|
|
couponList(req, res, next) {
|
|
|
let uid = req.user.uid;
|
|
|
let delivery_way = req.body.delivery_way || 1;
|
|
|
let coupon_code = req.body.coupon_code || '';
|
|
|
let product_sku = req.body.product_sku;
|
|
|
let buy_number = req.body.buy_number;
|
|
|
let sku_type = req.body.sku_type;
|
|
|
|
|
|
co(function* () {
|
|
|
let couponApi = yield req.ctx(BuyNowModel).listCoupon({
|
|
|
uid,
|
|
|
delivery_way,
|
|
|
coupon_code,
|
|
|
product_sku,
|
|
|
buy_number,
|
|
|
sku_type
|
|
|
});
|
|
|
let result = paymentProcess.couponProcess(_.get(couponApi, 'data', {}));
|
|
|
|
|
|
res.render('select-coupons', {
|
|
|
pageFooter: false,
|
|
|
result: result,
|
|
|
layout: false
|
|
|
});
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 输入优惠券码使用优惠券
|
|
|
*/
|
|
|
useCouponCode(req, res, next) {
|
|
|
co(function* () {
|
|
|
let result = yield req.ctx(BuyNowModel).usePromotionCode({
|
|
|
uid: req.user.uid,
|
|
|
product_sku: req.body.product_sku,
|
|
|
sku_type: req.body.sku_type,
|
|
|
buy_number: req.body.buy_number,
|
|
|
promotion_code: req.body.promotion_code
|
|
|
});
|
|
|
|
|
|
res.json(result);
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 选择礼品卡页面
|
|
|
*/
|
|
|
selectGiftcard(req, res, next) {
|
...
|
...
|
@@ -426,104 +519,6 @@ class BuyNowController { |
|
|
});
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取用户可用和不可用优惠券列表
|
|
|
* @param {*} req
|
|
|
* @param {*} res
|
|
|
* @param {*} next
|
|
|
*/
|
|
|
listCoupon(req, res, next) {
|
|
|
let orderInfo;
|
|
|
|
|
|
try {
|
|
|
orderInfo = JSON.parse(req.cookies.buynow_info);
|
|
|
} catch (e) {
|
|
|
logger.info(`orderEnsure: get buynow-order-info from cookie error:${JSON.stringify(e)}`);
|
|
|
orderInfo = {};
|
|
|
res.clearCookie('buynow_info', actCkOpthn);
|
|
|
}
|
|
|
|
|
|
let delivery_way = orderInfo.deliveryId || 1;
|
|
|
|
|
|
co(function* () {
|
|
|
let result = yield req.ctx(BuyNowModel).listCoupon({
|
|
|
uid: req.user.uid,
|
|
|
product_sku: req.query.product_sku,
|
|
|
sku_type: req.query.sku_type,
|
|
|
buy_number: req.query.buy_number,
|
|
|
is_group_frees: 'Y', // 运费券是否分组
|
|
|
delivery_way: delivery_way,
|
|
|
});
|
|
|
|
|
|
let finalResult = {
|
|
|
availableCoupons: [],
|
|
|
usableFreesCoupons: [],
|
|
|
notAvailableCoupons: [],
|
|
|
};
|
|
|
|
|
|
let usableCoupons = _.get(result, 'data.usable_coupons', []);
|
|
|
let freesCoupons = _.get(result, 'data.usable_frees_coupons', []);
|
|
|
let unusableCoupons = _.get(result, 'data.unusable_coupons', []);
|
|
|
|
|
|
let orderInfoUsableUsualCode = _.get(orderInfo, 'usable_usual_code', '');
|
|
|
let orderInfoUsableFreeCode = _.get(orderInfo, 'usable_free_code', '');
|
|
|
|
|
|
let procCouponsData = coupon => {
|
|
|
return {
|
|
|
couponCode: coupon.coupon_code,
|
|
|
couponDetailInfomation: coupon.coupon_name,
|
|
|
couponValue: coupon.coupon_value,
|
|
|
couponValidity: coupon.coupon_validity,
|
|
|
checked: coupon.coupon_code === orderInfoUsableUsualCode ||
|
|
|
coupon.coupon_code === orderInfoUsableFreeCode
|
|
|
};
|
|
|
};
|
|
|
|
|
|
finalResult.availableCoupons = usableCoupons.map(procCouponsData); // 可用优惠券
|
|
|
finalResult.usableFreesCoupons = freesCoupons.map(procCouponsData); // 运费券
|
|
|
finalResult.notAvailableCoupons = unusableCoupons.map(procCouponsData); // 不可用优惠券
|
|
|
|
|
|
res.json(finalResult);
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 使用优惠券
|
|
|
* @param {*} req
|
|
|
* @param {*} res
|
|
|
* @param {*} next
|
|
|
*/
|
|
|
useCoupon(req, res, next) {
|
|
|
co(function* () {
|
|
|
let result = yield req.ctx(BuyNowModel).useCoupon({
|
|
|
uid: req.user.uid,
|
|
|
product_sku: req.body.product_sku,
|
|
|
sku_type: req.body.sku_type,
|
|
|
buy_number: req.body.buy_number,
|
|
|
coupon_code: req.body.coupon_code
|
|
|
});
|
|
|
|
|
|
res.json(result);
|
|
|
})().catch(next);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 输入优惠券码使用优惠券
|
|
|
*/
|
|
|
usePromotionCode(req, res, next) {
|
|
|
co(function* () {
|
|
|
let result = yield req.ctx(BuyNowModel).usePromotionCode({
|
|
|
uid: req.user.uid,
|
|
|
product_sku: req.body.product_sku,
|
|
|
sku_type: req.body.sku_type,
|
|
|
buy_number: req.body.buy_number,
|
|
|
promotion_code: req.body.promotion_code
|
|
|
});
|
|
|
|
|
|
res.json(result);
|
|
|
})().catch(next);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = new BuyNowController(); |
...
|
...
|
|