Authored by 郭成尧

coupon-handle

... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-21 10:15:38
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 17:22:09
* @Last Modified time: 2017-06-23 17:53:27
*/
const _ = require('lodash');
const co = require('bluebird').coroutine;
... ... @@ -60,6 +60,12 @@ class BuyNowController {
buy_number: req.query.buy_number,
use_yoho_coin: parseInt(orderInfo.use_yoho_coin, 10)
});
let validCouponCount = yield req.ctx(BuyNowModel).countUsableCoupon({
uid: req.user.uid,
product_sku: req.query.product_sku,
sku_type: req.query.sku_type,
buy_number: req.query.buy_number
});
let headerData = headerModel.setNav({
navTitle: '确认订单',
navBtn: false
... ... @@ -72,7 +78,12 @@ class BuyNowController {
title: '确认订单',
width750: true,
product_sku: product_sku,
orderEnsure: paymentProcess.tranformPayment(result.data, orderInfo, null, null, computeData.data)
orderEnsure: _.assign(
paymentProcess.tranformPayment(result.data, orderInfo, null, null, computeData.data),
{
coupon: paymentProcess.coupon(_.get(validCouponCount, 'data.count', 0), orderInfo, computeData)
}
)
});
})().catch(next);
... ... @@ -243,6 +254,45 @@ class BuyNowController {
}
/**
* 获取用户可用和不可用优惠券列表
* @param {*} req
* @param {*} res
* @param {*} next
*/
listCoupon(req, res, next) {
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
});
res.json(result);
})().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) {
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-21 10:15:45
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 17:21:54
* @Last Modified time: 2017-06-23 17:44:33
*/
const api = global.yoho.API;
... ... @@ -17,7 +17,7 @@ class BuyNowModel extends global.yoho.BaseModel {
*/
countUsableCoupon(params) {
return api.post('', {
method: 'countUsableCoupon',
method: 'app.Buynow.countUsableCoupon',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
... ...
... ... @@ -68,7 +68,9 @@ router.post('/index/buynow/ordersub', authMW, BuyNowController.orderSub); // 立
router.get('/index/buynow/selectAddress', authMW, BuyNowController.selectAddress); // 选择地址
router.get('/index/buynow/selectInvoice', authMW, BuyNowController.selectInvoice); // 发票信息
router.get('/index/buynow/selectCoupon', authMW, BuyNowController.selectCoupon); // 选择优惠券页面
router.post('/index/buynow/useCoupon', BuyNowController.useCoupon); // [ajax]使用优惠券
router.post('/index/buynow/usePromotionCode', BuyNowController.usePromotionCode); // [ajax]输入优惠券码使用优惠券
router.get('/index/buynow/listCoupon', BuyNowController.listCoupon); // [ajax]获取优惠券列表
// 支付中心 URL,由于微信安全限制,在现有 URL 后追加 new ,通过 subDomain 中间件转发到此
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-23 11:43:44
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 17:15:35
* @Last Modified time: 2017-06-23 17:43:50
*/
require('cart/select-coupon.page.css');
const qs = require('yoho-qs');
... ... @@ -61,13 +61,9 @@ $newCoupon.on('submit', function() {
url: '/cart/index/buynow/usePromotionCode',
data: {
promotion_code: couponCode,
buy_number: qs.buy_number,
sku_type: qs.sku_type
buy_number: qs.buy_number
}
}).then(function(res) {
if (res.message) {
tip.show(res.message);
}
if (res.code === 200) {
tip.show('优惠券可用');
... ... @@ -76,6 +72,8 @@ $newCoupon.on('submit', function() {
orderInfo('coupon_code', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
goToBack();
} else {
tip.show(res.message);
}
}).fail(function() {
tip.show('网络错误');
... ... @@ -104,7 +102,6 @@ $('body').on('touchend', '.not-use', function() {
goToBack();
});
$newCoupon.find('input').on('input', function() {
if ($(this).val() !== '') {
$newCoupon.find('.submit').css('background', '#444');
... ... @@ -145,9 +142,11 @@ function getCouponHandle(allCoupons) {
$.ajax({
method: 'POST',
url: '/cart/index/buynow/couponSearch',
url: '/cart/index/buynow/useCoupon',
data: {
couponCode: couponCode
product_sku: qs.product_sku,
buy_number: qs.buy_number,
coupon_code: couponCode
}
}).then(function(res) {
if (res.code === 200) {
... ... @@ -175,7 +174,7 @@ function getCouponHandle(allCoupons) {
}
function getCouponDate() {
function getCouponData() {
if (isGetData) {
return;
... ... @@ -186,7 +185,11 @@ function getCouponDate() {
$.ajax({
type: 'GET',
url: '/cart/index/new/couponList',
url: '/cart/index/buynow/listCoupon',
data: {
product_sku: qs.product_sku,
buy_number: qs.buy_number
},
dataType: 'json'
}).then(getCouponHandle).always(function() {
isGetData = false;
... ... @@ -194,4 +197,4 @@ function getCouponDate() {
});
}
getCouponDate();
getCouponData();
... ...