tickets-seckill-giftcard
Showing
5 changed files
with
45 additions
and
15 deletions
@@ -8,6 +8,8 @@ const co = Promise.coroutine; | @@ -8,6 +8,8 @@ const co = Promise.coroutine; | ||
8 | const seckillModel = require('../models/seckill'); | 8 | const seckillModel = require('../models/seckill'); |
9 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 9 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
10 | const orderModel = require('../models/order'); | 10 | const orderModel = require('../models/order'); |
11 | +const shoppingModel = require('../models/shopping'); | ||
12 | +const paymentProcess = require(global.utils + '/payment-process'); | ||
11 | 13 | ||
12 | const BAD_REQUEST = '非法请求'; | 14 | const BAD_REQUEST = '非法请求'; |
13 | const SLAT = 'yohobuyseckill98'; | 15 | const SLAT = 'yohobuyseckill98'; |
@@ -77,13 +79,17 @@ exports.ensure = (req, res, next) => { | @@ -77,13 +79,17 @@ exports.ensure = (req, res, next) => { | ||
77 | orderComputerData = yield req.ctx(seckillModel).compute(_.assign(paymentOption, { | 79 | orderComputerData = yield req.ctx(seckillModel).compute(_.assign(paymentOption, { |
78 | delivery_way: orderInfo.deliveryId || 1, | 80 | delivery_way: orderInfo.deliveryId || 1, |
79 | payment_type: orderInfo.paymentType || 1, | 81 | payment_type: orderInfo.paymentType || 1, |
80 | - use_yoho_coin: orderInfo.yohoCoin || 0 | 82 | + use_yoho_coin: orderInfo.yohoCoin || 0, |
83 | + gift_card_code: orderInfo.body.gift_card_code || null | ||
81 | })); | 84 | })); |
82 | } | 85 | } |
83 | 86 | ||
84 | - // 获取结算 数据 | ||
85 | - let paymentInfo = | ||
86 | - yield req.ctx(seckillModel).payment(paymentOption, orderInfo, _.get(orderComputerData, 'data')); | 87 | + let [paymentInfo, validGiftCardCountData] = yield Promise.all([ |
88 | + req.ctx(seckillModel).payment(paymentOption, orderInfo, _.get(orderComputerData, 'data')), | ||
89 | + req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量 | ||
90 | + ]); | ||
91 | + | ||
92 | + let validGiftCardCount = _.get(validGiftCardCountData, 'data.count', 0); | ||
87 | 93 | ||
88 | if (paymentInfo.code !== 200) { | 94 | if (paymentInfo.code !== 200) { |
89 | view = { | 95 | view = { |
@@ -97,11 +103,16 @@ exports.ensure = (req, res, next) => { | @@ -97,11 +103,16 @@ exports.ensure = (req, res, next) => { | ||
97 | } | 103 | } |
98 | } else { | 104 | } else { |
99 | // 渲染 | 105 | // 渲染 |
100 | - view = Object.assign({ | 106 | + view = _.assign({ |
101 | seckill: skillData, | 107 | seckill: skillData, |
102 | orderEnsure: true, | 108 | orderEnsure: true, |
103 | sku, | 109 | sku, |
104 | - }, paymentInfo.data); | 110 | + }, paymentInfo.data, { |
111 | + giftCards: paymentProcess.handleGiftCards({ | ||
112 | + validGiftCardCount: validGiftCardCount, | ||
113 | + orderCompute: orderComputerData | ||
114 | + }) | ||
115 | + }); | ||
105 | } | 116 | } |
106 | 117 | ||
107 | res.locals.title = '确认订单'; | 118 | res.locals.title = '确认订单'; |
@@ -147,6 +158,7 @@ exports.compute = (req, res, next) => { | @@ -147,6 +158,7 @@ exports.compute = (req, res, next) => { | ||
147 | product_sku: sku, | 158 | product_sku: sku, |
148 | delivery_way: req.body.deliveryId || 1, | 159 | delivery_way: req.body.deliveryId || 1, |
149 | use_yoho_coin: req.body.yohoCoin || 0, | 160 | use_yoho_coin: req.body.yohoCoin || 0, |
161 | + gift_card_code: req.body.gift_card_code, | ||
150 | activity_id: activityId | 162 | activity_id: activityId |
151 | }; | 163 | }; |
152 | 164 |
1 | 'use strict'; | 1 | 'use strict'; |
2 | - | 2 | +const _ = require('lodash'); |
3 | +const co = Promise.coroutine; | ||
3 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 4 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
4 | const ticketsConfirmModel = require('../models/ticketsConfirm'); | 5 | const ticketsConfirmModel = require('../models/ticketsConfirm'); |
6 | +const shoppingModel = require('../models/shopping'); | ||
7 | +const paymentProcess = require(global.utils + '/payment-process'); | ||
5 | 8 | ||
6 | // cookie 参数 | 9 | // cookie 参数 |
7 | const actCkOpthn = { | 10 | const actCkOpthn = { |
8 | path: '/cart/index' | 11 | path: '/cart/index' |
9 | }; | 12 | }; |
10 | 13 | ||
11 | -const ticketsConfirm = (req, res) => { | 14 | +const ticketsConfirm = (req, res, next) => { |
12 | let headerData = headerModel.setNav({ | 15 | let headerData = headerModel.setNav({ |
13 | navTitle: '确认订单', | 16 | navTitle: '确认订单', |
14 | navBtn: false | 17 | navBtn: false |
@@ -19,8 +22,6 @@ const ticketsConfirm = (req, res) => { | @@ -19,8 +22,6 @@ const ticketsConfirm = (req, res) => { | ||
19 | module: 'cart', | 22 | module: 'cart', |
20 | page: 'tickets-confirm', | 23 | page: 'tickets-confirm', |
21 | title: '确认订单', | 24 | title: '确认订单', |
22 | - | ||
23 | - // pageFooter: true, | ||
24 | localCss: true, | 25 | localCss: true, |
25 | navBtn: false, | 26 | navBtn: false, |
26 | width750: true | 27 | width750: true |
@@ -40,12 +41,24 @@ const ticketsConfirm = (req, res) => { | @@ -40,12 +41,24 @@ const ticketsConfirm = (req, res) => { | ||
40 | productSku: req.body.productSku, | 41 | productSku: req.body.productSku, |
41 | buyNumber: req.body.buyNumber, | 42 | buyNumber: req.body.buyNumber, |
42 | useYohoCoin: orderInfo ? orderInfo.yohoCoin : 0, | 43 | useYohoCoin: orderInfo ? orderInfo.yohoCoin : 0, |
44 | + gift_card_code: orderInfo.body.gift_card_code || null, | ||
43 | yohoCoinMode: true | 45 | yohoCoinMode: true |
44 | }; | 46 | }; |
45 | 47 | ||
46 | - req.ctx(ticketsConfirmModel).ticketsConfirm(params).then(result => { | ||
47 | - res.render('ticketsConfirm', Object.assign(responseData, result)); | ||
48 | - }); | 48 | + co(function* () { |
49 | + let [result, validGiftCardCountData] = yield Promise.all([ | ||
50 | + req.ctx(ticketsConfirmModel).ticketsConfirm(params), | ||
51 | + req.ctx(shoppingModel).countUsableGiftCard(req.user.uid) // 可用礼品卡数量 | ||
52 | + ]); | ||
53 | + let validGiftCardCount = _.get(validGiftCardCountData, 'data.count', 0); | ||
54 | + | ||
55 | + res.render('ticketsConfirm', _.assign(responseData, result, { | ||
56 | + giftCards: paymentProcess.handleGiftCards({ | ||
57 | + validGiftCardCount: validGiftCardCount, | ||
58 | + orderCompute: result | ||
59 | + }) | ||
60 | + })); | ||
61 | + })().catch(next); | ||
49 | }; | 62 | }; |
50 | 63 | ||
51 | const submitTicket = (req, res) => { | 64 | const submitTicket = (req, res) => { |
@@ -54,7 +67,8 @@ const submitTicket = (req, res) => { | @@ -54,7 +67,8 @@ const submitTicket = (req, res) => { | ||
54 | productSku: req.body.productSku, | 67 | productSku: req.body.productSku, |
55 | buyNumber: req.body.buyNumber, | 68 | buyNumber: req.body.buyNumber, |
56 | mobile: req.body.mobile, | 69 | mobile: req.body.mobile, |
57 | - useYohoCoin: req.body.useYohoCoin | 70 | + useYohoCoin: req.body.useYohoCoin, |
71 | + gift_card_code: req.body.gift_card_code | ||
58 | }; | 72 | }; |
59 | 73 | ||
60 | req.ctx(ticketsConfirmModel).submitTicket(params).then(result => { | 74 | req.ctx(ticketsConfirmModel).submitTicket(params).then(result => { |
@@ -18,6 +18,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | @@ -18,6 +18,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | ||
18 | product_sku: param.productSku, | 18 | product_sku: param.productSku, |
19 | buy_number: param.buyNumber, | 19 | buy_number: param.buyNumber, |
20 | use_yoho_coin: param.useYohoCoin || 0, | 20 | use_yoho_coin: param.useYohoCoin || 0, |
21 | + gift_card_code: param.gift_card_code || null, | ||
21 | yoho_coin_mode: param.yohoCoinMode ? param.yohoCoinMode : 0 | 22 | yoho_coin_mode: param.yohoCoinMode ? param.yohoCoinMode : 0 |
22 | }}).then((result) => { | 23 | }}).then((result) => { |
23 | return result; | 24 | return result; |
@@ -108,6 +109,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | @@ -108,6 +109,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | ||
108 | buy_number: param.buyNumber, | 109 | buy_number: param.buyNumber, |
109 | mobile: param.mobile, | 110 | mobile: param.mobile, |
110 | use_yoho_coin: param.useYohoCoin, | 111 | use_yoho_coin: param.useYohoCoin, |
112 | + gift_card_code: param.gift_card_code || null, | ||
111 | qhy_union: '' | 113 | qhy_union: '' |
112 | }}).then((result) => { | 114 | }}).then((result) => { |
113 | return result; | 115 | return result; |
@@ -483,7 +483,8 @@ function ticketsConfirm() { | @@ -483,7 +483,8 @@ function ticketsConfirm() { | ||
483 | productSku: productSku, | 483 | productSku: productSku, |
484 | buyNumber: buyNumber, | 484 | buyNumber: buyNumber, |
485 | mobile: $ticketsMobile.val(), | 485 | mobile: $ticketsMobile.val(), |
486 | - useYohoCoin: orderInfo('yohoCoin') | 486 | + useYohoCoin: orderInfo('yohoCoin'), |
487 | + gift_card_code: orderInfo('gift_card_code') | ||
487 | }; | 488 | }; |
488 | 489 | ||
489 | if (!$ticketsMobile.val()) { | 490 | if (!$ticketsMobile.val()) { |
@@ -154,6 +154,7 @@ function orderCompute() { | @@ -154,6 +154,7 @@ function orderCompute() { | ||
154 | deliveryId: deliverId, // 配送方式id | 154 | deliveryId: deliverId, // 配送方式id |
155 | paymentType: orderInfo('paymentType'), | 155 | paymentType: orderInfo('paymentType'), |
156 | yohoCoin: yohoCoin, | 156 | yohoCoin: yohoCoin, |
157 | + gift_card_code: orderInfo('gift_card_code'), | ||
157 | sku: productSku, | 158 | sku: productSku, |
158 | activityId: activityId | 159 | activityId: activityId |
159 | }; | 160 | }; |
-
Please register or login to post a comment