Authored by 毕凯

Merge branch 'release/5.8.1' of git.yoho.cn:fe/yohobuywap-node into release/5.8.1

... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-21 10:15:38
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 14:53:12
* @Last Modified time: 2017-06-23 17:53:27
*/
const _ = require('lodash');
const co = require('bluebird').coroutine;
... ... @@ -37,7 +37,7 @@ class BuyNowController {
} catch (e) {
logger.info(`orderEnsure: get buynow-order-info from cookie error:${JSON.stringify(e)}`);
orderInfo = {};
res.clearCookie('buynow-order-info', actCkOpthn);
res.clearCookie('buynow_info', actCkOpthn);
}
let product_sku = req.query.product_sku;
... ... @@ -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);
... ... @@ -92,6 +103,7 @@ class BuyNowController {
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,
use_yoho_coin: req.body.use_yoho_coin,
});
... ... @@ -142,6 +154,9 @@ class BuyNowController {
co(function * () {
let result = yield req.ctx(BuyNowModel).submit(params);
// 提交成功清除Cookie
res.clearCookie('buynow_info', actCkOpthn);
return res.json(result);
})().catch(next);
}
... ... @@ -219,7 +234,7 @@ class BuyNowController {
}
/**
* 选择优惠券
* 选择优惠券页面
*/
selectCoupon(req, res) {
let headerData = headerModel.setNav({
... ... @@ -237,6 +252,62 @@ class BuyNowController {
localCss: true
});
}
/**
* 获取用户可用和不可用优惠券列表
* @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) {
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();
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-06-21 10:15:45
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 11:25:12
* @Last Modified time: 2017-06-23 17:44:33
*/
const api = global.yoho.API;
... ... @@ -17,6 +17,7 @@ class BuyNowModel extends global.yoho.BaseModel {
*/
countUsableCoupon(params) {
return api.post('', {
method: 'app.Buynow.countUsableCoupon',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
... ... @@ -30,6 +31,7 @@ class BuyNowModel extends global.yoho.BaseModel {
*/
listCoupon(params) {
return api.post('', {
method: 'app.Buynow.listCoupon',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
... ... @@ -47,7 +49,7 @@ 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 || 1,
buy_number: params.buy_number,
yoho_coin_mode: params.yoho_coin_mode || 0, // 是否使用有货币
yoho_bill_term: 0, // H5 不支持分期
is_support_apple_pay: 'N', // H5 不支持 APPLE PAY
... ... @@ -68,7 +70,7 @@ 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 || 1,
buy_number: params.buy_number,
payment_type: params.payment_type || 1,
delivery_way: params.delivery_way || 1,
use_red_envelopes: 0,
... ... @@ -105,7 +107,7 @@ 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 || 1,
buy_number: params.buy_number,
yoho_bill_term: 0,
address_id: params.address_id,
delivery_time: params.delivery_time,
... ... @@ -160,6 +162,45 @@ class BuyNowModel extends global.yoho.BaseModel {
return api.post('', finalParams, {cache: false});
}
/**
* 使用优惠券
* @param {*} params
*/
useCoupon(params) {
let finalParams = {
method: 'app.Buynow.useCoupon',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number,
};
if (params.coupon_code) {
finalParams.coupon_code = params.coupon_code;
}
return api.post('', finalParams, {cache: false});
}
/**
* 使用优惠码
* @param {*} params
*/
usePromotionCode(params) {
let finalParams = {
method: 'app.Buynow.usePromotionCode',
uid: params.uid,
product_sku: params.product_sku,
sku_type: params.sku_type || 'I',
buy_number: params.buy_number
};
if (params.promotion_code) {
finalParams.promotion_code = params.promotion_code;
}
return api.post('', finalParams, {cache: false});
}
}
module.exports = BuyNowModel;
... ...
... ... @@ -67,6 +67,10 @@ router.post('/index/buynow/ordercompute', authMW, BuyNowController.orderCompute)
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-21 10:30:21
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 15:28:40
* @Last Modified time: 2017-06-23 17:12:13
*/
require('buynow/order-ensure.page.css');
const $ = require('yoho-jquery');
... ... @@ -186,6 +186,7 @@ function orderCompute() {
deliver_way = orderInfo('delivery_way'),
data = {
product_sku: qs.product_sku,
buy_number: qs.buy_number,
cart_type: orderInfo('cartType') || 'ordinary',
delivery_way: orderInfo('delivery_way'),
payment_type: orderInfo('payment_type'),
... ... @@ -255,6 +256,7 @@ function submitOrder() {
let postData = {
product_sku: qs.product_sku,
buy_number: qs.buy_number,
address_id: orderInfo('address_id'),
delivery_way: orderInfo('delivery_way'),
delivery_time: orderInfo('delivery_time'),
... ...
/*
* @Author: Targaryen
* @Date: 2017-06-23 11:43:44
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 11:43:44
* @Last Modified by: Targaryen
* @Last Modified time: 2017-06-23 17:43:50
*/
require('cart/select-coupon.page.css');
const qs = require('yoho-qs');
let $ = require('yoho-jquery'),
ellipsis = require('yoho-mlellipsis'),
loading = require('plugin/loading'),
... ... @@ -49,27 +50,30 @@ function goToBack() {
$newCoupon.on('submit', function() {
let $this = $(this);
let couponCode = $this.find('[name="couponCode"]').val();
if (!$this.find('[name="couponCode"]').val()) {
if (!couponCode) {
tip.show('请输入优惠券码');
return false;
}
$.ajax({
method: 'POST',
url: '/cart/index/new/couponSearch',
data: $this.serialize()
}).then(function(res) {
if (res.message) {
tip.show(res.message);
url: '/cart/index/buynow/usePromotionCode',
data: {
promotion_code: couponCode,
buy_number: qs.buy_number
}
}).then(function(res) {
if (res.code === 200) {
tip.show('优惠券可用');
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
orderInfo('use_yoho_coin', 0);
orderInfo('coupon_code', res.data.coupon_code);
orderInfo('couponName', res.data.coupon_title);
goToBack();
} else {
tip.show(res.message);
}
}).fail(function() {
tip.show('网络错误');
... ... @@ -94,11 +98,10 @@ $('body').on('touchend', '.not-use', function() {
orderInfo('couponName', null);
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
orderInfo('use_yoho_coin', 0);
goToBack();
});
$newCoupon.find('input').on('input', function() {
if ($(this).val() !== '') {
$newCoupon.find('.submit').css('background', '#444');
... ... @@ -139,9 +142,11 @@ function getCouponHandle(allCoupons) {
$.ajax({
method: 'POST',
url: '/cart/index/new/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) {
... ... @@ -149,7 +154,7 @@ function getCouponHandle(allCoupons) {
orderInfo('couponName', res.data.coupon_title);
// 实付金额发生变化,使用有货币为0
orderInfo('yohoCoin', 0);
orderInfo('use_yoho_coin', 0);
goToBack();
} else if (res.message) {
tip.show(res.message);
... ... @@ -169,7 +174,7 @@ function getCouponHandle(allCoupons) {
}
function getCouponDate() {
function getCouponData() {
if (isGetData) {
return;
... ... @@ -180,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;
... ... @@ -188,4 +197,4 @@ function getCouponDate() {
});
}
getCouponDate();
getCouponData();
... ...
... ... @@ -179,7 +179,8 @@ setTimeout(() => {
return;
}
if (result.buyNow) { // 立即购买
location.href = '/cart/index/buynow/orderensure?product_sku=' + result.sku.skuId;
location.href = '/cart/index/buynow/orderensure?product_sku=' +
result.sku.skuId + '&buy_number=' + result.buyNum;
return;
}
detailFuns.addToCart(result.sku.skuId, productSkn, result.buyNum);
... ...