Authored by 郭成尧

change-de

... ... @@ -89,7 +89,8 @@ class BuyNowController {
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) // 可用礼品卡数量
]);
... ... @@ -131,7 +132,8 @@ class BuyNowController {
coupon: paymentProcess.handleCoupons({
paymentApiCouponData: _.get(result, 'data.coupon_pay', {}),
validCouponCount: _.get(validCouponCount, 'data.count', 0),
orderComputeCouponPay: _.get(computeData, 'data.coupon_pay')
orderComputeCouponPay: _.get(computeData, 'data.coupon_pay'),
userCheckCoupon: orderInfo.user_check_coupon
}),
selectAddressUrl: helpers.urlFormat('/cart/index/buynow/selectAddress', {
product_sku: product_sku,
... ... @@ -176,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);
}
... ...
... ... @@ -163,6 +163,15 @@ exports.orderCompute = (req, res, next) => {
let uid = req.user.uid;
let skuList = req.body.skuList;
let type = req.body.type;
let orderInfo;
try {
orderInfo = JSON.parse(req.cookies['order-info']);
} catch (e) {
logger.info(`orderEnsure: get orderInfo from cookie error:${JSON.stringify(e)}`);
orderInfo = {};
res.clearCookie('order-info', actCkOpthn);
}
if (type !== 'tickets') {
let params = {
... ... @@ -185,7 +194,8 @@ exports.orderCompute = (req, res, next) => {
}).catch(next);
} else {
req.ctx(cartModel).orderCompute(_.assign(params, {
product_sku_list: skuList
product_sku_list: skuList,
userCheckCoupon: orderInfo.user_check_coupon
})).then(result => {
res.json(result);
}).catch(next);
... ...
... ... @@ -20,7 +20,8 @@ class BuyNowModel extends global.yoho.BaseModel {
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number
buy_number: params.buy_number,
delivery_way: params.delivery_way
},
param: {
cache: false
... ...
... ... @@ -114,7 +114,8 @@ class cartModel extends global.yoho.BaseModel {
coupon: paymentProcess.handleCoupons({
paymentApiCouponData,
validCouponCount: validCouponCount,
orderComputeCouponPay: orderCompute.coupon_pay
orderComputeCouponPay: orderCompute.coupon_pay,
userCheckCoupon: orderInfoCookie.user_check_coupon
}),
giftCards: paymentProcess.handleGiftCards({
validGiftCardCount: validGiftCardCount,
... ... @@ -130,11 +131,26 @@ class cartModel extends global.yoho.BaseModel {
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
*/
orderCompute(params) {
return this.ctx.req.ctx(shoppingModel).orderComputeAPI(params).then(result => {
if (result && result.data) {
result.data.use_yoho_coin = paymentProcess.transPrice(result.data.use_yoho_coin);
result.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(result.data);
return result.data;
return Promise.all([
this.ctx.req.ctx(shoppingModel).orderComputeAPI(params),
this.ctx.req.ctx(shoppingModel).getValidCouponCount({
uid: params.uid,
delivery_way: params.delivery_way
})
]).then(result => {
let computerResult = result[0];
let validCouponCount = _.get(result[1], 'data.count', 0);
if (computerResult && computerResult.data) {
computerResult.data.use_yoho_coin = paymentProcess.transPrice(computerResult.data.use_yoho_coin);
computerResult.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(computerResult.data);
computerResult.data.coupon = paymentProcess.handleCoupons({
paymentApiCouponData: {},
validCouponCount: validCouponCount,
orderComputeCouponPay: _.get(computerResult, 'data.coupon_pay'),
userCheckCoupon: params.user_check_coupon
});
return computerResult.data;
} else {
return {};
}
... ...
... ... @@ -10,7 +10,7 @@
{{showText}}
</span>
<span class="coupon-info pull-right{{#isEqualOr info '无可用'}} no-can-use{{/isEqualOr}}">
{{priceText}}
<span class="coupon-price-info">{{priceText}}</span>
<i class="iconfont">&#xe614;</i>
</span>
{{/if}}
... ...
... ... @@ -131,6 +131,8 @@ function orderCompute() {
$('.price-cost span').html('¥' + res.last_order_amount);
$('.bill span').html('¥' + res.last_order_amount);
$('.total').html(total);
$('.coupon .count').html(res.coupon.showText);
$('.coupon .coupon-price-info').html(res.coupon.priceText);
}
updateDeliverWay(deliver_way);
... ...
... ... @@ -173,6 +173,8 @@ function orderCompute() {
$('.price-cost span').html('¥' + res.last_order_amount);
$('.bill span').html('¥' + res.last_order_amount);
$('.total').html(total);
$('.coupon .count').html(res.coupon.showText);
$('.coupon .coupon-price-info').html(res.coupon.priceText);
}
updateDeliverId(deliverId);
... ...
... ... @@ -366,7 +366,9 @@ function handleCoupons(params) {
showText = `${validCouponCount}张可用`;
}
if (!_.isEmpty(orderComputeCouponPay) && couponData.coupon_count) {
if (!_.isEmpty(orderComputeCouponPay) &&
couponData.coupon_count &&
params.userCheckCoupon === 'Y') {
showText = `已选${couponData.coupon_count}张`;
priceText = `-${couponData.coupon_amount_str}`;
}
... ...