Authored by 郭成尧

coupon-code

... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-21 10:15:38
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-26 16:19:38
* @Last Modified time: 2017-06-27 15:20:50
*/
const _ = require('lodash');
const co = require('bluebird').coroutine;
... ... @@ -16,6 +16,7 @@ const paymentProcess = require(`${utils}/payment-process`);
const crypto = global.yoho.crypto;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const camelCase = global.yoho.camelCase;
// cookie 参数
const actCkOpthn = {
... ... @@ -59,7 +60,11 @@ class BuyNowController {
product_sku: product_sku,
sku_type: req.query.sku_type,
buy_number: buy_number,
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10)
payment_type: orderInfo.payment_type,
delivery_way: orderInfo.delivery_way,
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10),
coupon_code: orderInfo.coupon_code,
promotion_code: orderInfo.promotion_code
});
let validCouponCount = yield req.ctx(BuyNowModel).countUsableCoupon({
uid: req.user.uid,
... ... @@ -71,6 +76,25 @@ class BuyNowController {
navTitle: '确认订单',
navBtn: false
});
let orderEnsure = _.assign(
paymentProcess.tranformPayment(result.data, orderInfo, null, null, computeData.data),
{
coupon: paymentProcess.coupon(
_.get(validCouponCount, 'data.count', 0),
orderInfo,
computeData.data
),
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
}
);
return res.render('buynow/order-ensure', {
pageHeader: headerData,
... ... @@ -80,17 +104,7 @@ class BuyNowController {
width750: true,
localCss: true,
product_sku: product_sku,
orderEnsure: _.assign(
paymentProcess.tranformPayment(result.data, orderInfo, null, null, computeData.data),
{
coupon: paymentProcess.coupon(_.get(validCouponCount, 'data.count', 0), orderInfo, computeData),
selectAddressUrl: helpers.urlFormat('/cart/index/buynow/selectAddress', {
product_sku: product_sku,
buy_number: buy_number
}),
isOrdinaryCart: true
}
)
orderEnsure: orderEnsure
});
})().catch(next);
... ... @@ -283,7 +297,9 @@ class BuyNowController {
buy_number: req.query.buy_number
});
res.json(result);
let finalResult = _.get(result, 'data', {});
res.json(camelCase(finalResult));
})().catch(next);
}
... ...
... ... @@ -91,7 +91,7 @@
<ul class="sale-invoice">
{{#if isOrdinaryCart}}
<li class="coupon">
<a href="{{#if isLimit}}javascript:void(0);{{else}}/cart/index/buynow/selectCoupon?product_sku={{@root.product_sku}}{{/if}}">
<a href="{{selectCouponUrl}}">
<span class="title">优惠券/优惠券码</span>
{{# coupon}}
{{#if couponName}}
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-21 10:30:21
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-26 18:01:45
* @Last Modified time: 2017-06-27 15:04:06
*/
require('buynow/order-ensure.page.css');
const $ = require('yoho-jquery');
... ... @@ -118,12 +118,6 @@ if ($couponUse.data('name') !== orderInfo('couponName')) {
orderInfo('couponName', null);
}
// 来自购物车的链接默认不使用优惠券
if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1) {
orderInfo('coupon_code', null);
orderInfo('couponName', null);
}
isLimitGood() && (function() {
let a = [];
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-23 11:43:44
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 17:43:50
* @Last Modified time: 2017-06-27 14:58:41
*/
require('cart/select-coupon.page.css');
const qs = require('yoho-qs');
... ... @@ -115,8 +115,8 @@ function getCouponHandle(allCoupons) {
coupons;
// 把可用和不可用的优惠券分离出来
notAvailableCoupons = allCoupons.notAvailableCoupons;
coupons = allCoupons.coupons;
notAvailableCoupons = allCoupons.unusableCoupons;
coupons = allCoupons.usableCoupons;
// 没有优惠券
if (!(notAvailableCoupons.length || coupons.length)) {
... ... @@ -128,10 +128,12 @@ function getCouponHandle(allCoupons) {
$.each(coupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
coupon.couponDetailInfomation = coupon.couponName;
});
$.each(notAvailableCoupons, function(i, coupon) {
coupon.couponValue = Math.floor(coupon.couponValue);
coupon.couponDetailInfomation = coupon.couponName;
});
// 渲染可用的优惠券
... ...