...
|
...
|
@@ -12,6 +12,31 @@ const shoppingModel = require('../models/shopping'); |
|
|
const paymentProcess = require(global.utils + '/payment-process');
|
|
|
const logger = global.yoho.logger;
|
|
|
|
|
|
/**
|
|
|
* 优惠券数据处理
|
|
|
*/
|
|
|
const _couponProcess = conponData => {
|
|
|
let usableCouponsList = _.get(conponData, 'usable_coupon_catalogs.list', []);
|
|
|
let unusableCouponsList = _.get(conponData, 'unusable_coupon_catalogs.list', []);
|
|
|
let usableCouponNum = _.get(usableCouponsList, '[0].coupons').length;
|
|
|
let unusableCouponNum = 0;
|
|
|
let headMsg = _.replace(_.get(conponData, 'usable_coupon_catalogs.head_msg', []), '\n', '<br>');
|
|
|
|
|
|
_.forEach(unusableCouponsList, listItem => {
|
|
|
if (listItem.coupons) {
|
|
|
unusableCouponNum += listItem.coupons.length;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return {
|
|
|
usableCouponNum,
|
|
|
unusableCouponNum,
|
|
|
usableCouponsList,
|
|
|
unusableCouponsList,
|
|
|
headMsg
|
|
|
};
|
|
|
};
|
|
|
|
|
|
// cookie 参数
|
|
|
const actCkOpthn = {
|
|
|
path: '/cart/index'
|
...
|
...
|
@@ -349,23 +374,46 @@ exports.selectCoupon = (req, res) => { |
|
|
* 下单流程 选择优惠券
|
|
|
* New!
|
|
|
*/
|
|
|
exports.selectCoupons = (req, res) => {
|
|
|
|
|
|
exports.selectCoupons = (req, res, next) => {
|
|
|
let headerData = headerModel.setNav({
|
|
|
navTitle: '选择优惠券',
|
|
|
navBtn: false
|
|
|
});
|
|
|
let orderInfo;
|
|
|
let uid = req.user.uid;
|
|
|
|
|
|
res.render('select-coupons', {
|
|
|
module: 'cart',
|
|
|
page: 'select-coupons',
|
|
|
title: '选择优惠券',
|
|
|
selectCouponPage: true,
|
|
|
pageHeader: headerData,
|
|
|
pageFooter: false,
|
|
|
localCss: true,
|
|
|
width750: true
|
|
|
});
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
let delivery_way = orderInfo.deliveryId || 1;
|
|
|
let coupon_code = orderInfo.coupon_code || '';
|
|
|
|
|
|
|
|
|
co(function* () {
|
|
|
let couponApi = yield req.ctx(shoppingModel).listCoupon({
|
|
|
uid: uid,
|
|
|
delivery_way: delivery_way,
|
|
|
coupon_code: coupon_code
|
|
|
});
|
|
|
let result = _couponProcess(_.get(couponApi, 'data', {}));
|
|
|
|
|
|
res.render('select-coupons', {
|
|
|
module: 'cart',
|
|
|
page: 'select-coupons',
|
|
|
title: '选择优惠券',
|
|
|
selectCouponPage: true,
|
|
|
pageHeader: headerData,
|
|
|
pageFooter: false,
|
|
|
localCss: true,
|
|
|
width750: true,
|
|
|
result: result
|
|
|
});
|
|
|
})().catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -422,30 +470,8 @@ exports.selectGiftcard = (req, res, next) => { |
|
|
/**
|
|
|
* 购物车结算--获取优惠券列表
|
|
|
*/
|
|
|
exports.couponList = (req, res, next) => {
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
let delivery_way = orderInfo.deliveryId || 1;
|
|
|
|
|
|
if (req.xhr) {
|
|
|
return req.ctx(shoppingModel).listCoupon({
|
|
|
uid: req.user.uid,
|
|
|
delivery_way: delivery_way,
|
|
|
is_group_frees: 'Y' // 运费券是否分组
|
|
|
}).then(data => {
|
|
|
res.json(data);
|
|
|
}).catch(next);
|
|
|
} else {
|
|
|
return next();
|
|
|
}
|
|
|
exports.couponList = (req, res) => {
|
|
|
res.json({});
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
|