Merge branch 'feature/bugfix61' into 'release/6.1'
giftcard-support See merge request !918
Showing
10 changed files
with
134 additions
and
31 deletions
@@ -4,10 +4,15 @@ | @@ -4,10 +4,15 @@ | ||
4 | 'use strict'; | 4 | 'use strict'; |
5 | const _ = require('lodash'); | 5 | const _ = require('lodash'); |
6 | const crypto = global.yoho.crypto; | 6 | const crypto = global.yoho.crypto; |
7 | +const helpers = global.yoho.helpers; | ||
7 | const co = Promise.coroutine; | 8 | const co = Promise.coroutine; |
9 | +const userModel = require('../models/user'); | ||
10 | +const addressModel = require('../models/address'); | ||
8 | const seckillModel = require('../models/seckill'); | 11 | const seckillModel = require('../models/seckill'); |
9 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 12 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
10 | const orderModel = require('../models/order'); | 13 | const orderModel = require('../models/order'); |
14 | +const shoppingModel = require('../models/shopping'); | ||
15 | +const paymentProcess = require(global.utils + '/payment-process'); | ||
11 | 16 | ||
12 | const BAD_REQUEST = '非法请求'; | 17 | const BAD_REQUEST = '非法请求'; |
13 | const SLAT = 'yohobuyseckill98'; | 18 | const SLAT = 'yohobuyseckill98'; |
@@ -77,13 +82,31 @@ exports.ensure = (req, res, next) => { | @@ -77,13 +82,31 @@ exports.ensure = (req, res, next) => { | ||
77 | orderComputerData = yield req.ctx(seckillModel).compute(_.assign(paymentOption, { | 82 | orderComputerData = yield req.ctx(seckillModel).compute(_.assign(paymentOption, { |
78 | delivery_way: orderInfo.deliveryId || 1, | 83 | delivery_way: orderInfo.deliveryId || 1, |
79 | payment_type: orderInfo.paymentType || 1, | 84 | payment_type: orderInfo.paymentType || 1, |
80 | - use_yoho_coin: orderInfo.yohoCoin || 0 | 85 | + use_yoho_coin: orderInfo.yohoCoin || 0, |
86 | + gift_card_code: orderInfo.gift_card_code || null | ||
81 | })); | 87 | })); |
82 | } | 88 | } |
83 | 89 | ||
84 | - // 获取结算 数据 | ||
85 | - let paymentInfo = | ||
86 | - yield req.ctx(seckillModel).payment(paymentOption, orderInfo, _.get(orderComputerData, 'data')); | 90 | + let [userProfile, address, paymentInfo, validGiftCardCountData] = yield Promise.all([ |
91 | + req.ctx(userModel).queryProfile(uid), | ||
92 | + req.ctx(addressModel).addressData(uid), | ||
93 | + req.ctx(seckillModel).payment(paymentOption, orderInfo, _.get(orderComputerData, 'data')), | ||
94 | + req.ctx(shoppingModel).countUsableGiftCard(uid) // 可用礼品卡数量 | ||
95 | + ]); | ||
96 | + | ||
97 | + let validGiftCardCount = _.get(validGiftCardCountData, 'data.count', 0); | ||
98 | + | ||
99 | + // 获取用户完整手机号 | ||
100 | + let mobile = _.get(userProfile, 'data.mobile', ''); | ||
101 | + let orderAddress = _.get(paymentInfo, 'address', []); | ||
102 | + let addressList = _.get(address, 'data', []); | ||
103 | + | ||
104 | + orderAddress.length && _.forEach(addressList, address => { //eslint-disable-line | ||
105 | + if (address.address_id === orderAddress.address_id) { | ||
106 | + mobile = address.mobile; | ||
107 | + return false; | ||
108 | + } | ||
109 | + }); | ||
87 | 110 | ||
88 | if (paymentInfo.code !== 200) { | 111 | if (paymentInfo.code !== 200) { |
89 | view = { | 112 | view = { |
@@ -97,11 +120,17 @@ exports.ensure = (req, res, next) => { | @@ -97,11 +120,17 @@ exports.ensure = (req, res, next) => { | ||
97 | } | 120 | } |
98 | } else { | 121 | } else { |
99 | // 渲染 | 122 | // 渲染 |
100 | - view = Object.assign({ | 123 | + view = _.assign({ |
101 | seckill: skillData, | 124 | seckill: skillData, |
102 | orderEnsure: true, | 125 | orderEnsure: true, |
103 | sku, | 126 | sku, |
104 | - }, paymentInfo.data); | 127 | + }, paymentInfo.data, { |
128 | + choseGiftCard: helpers.urlFormat('/cart/index/new/selectGiftcard'), | ||
129 | + giftCards: paymentProcess.handleGiftCards({ | ||
130 | + validGiftCardCount: validGiftCardCount, | ||
131 | + orderCompute: _.get(orderComputerData, 'data') | ||
132 | + }) | ||
133 | + }); | ||
105 | } | 134 | } |
106 | 135 | ||
107 | res.locals.title = '确认订单'; | 136 | res.locals.title = '确认订单'; |
@@ -114,7 +143,7 @@ exports.ensure = (req, res, next) => { | @@ -114,7 +143,7 @@ exports.ensure = (req, res, next) => { | ||
114 | }), | 143 | }), |
115 | width750: true, | 144 | width750: true, |
116 | localCss: true, | 145 | localCss: true, |
117 | - userMobile: view.phoneNum, | 146 | + userMobile: mobile, |
118 | cartToken: crypto.encryption(SLAT, [sku, activityId].join('')) | 147 | cartToken: crypto.encryption(SLAT, [sku, activityId].join('')) |
119 | }, view)); | 148 | }, view)); |
120 | })().catch(next); | 149 | })().catch(next); |
@@ -147,6 +176,7 @@ exports.compute = (req, res, next) => { | @@ -147,6 +176,7 @@ exports.compute = (req, res, next) => { | ||
147 | product_sku: sku, | 176 | product_sku: sku, |
148 | delivery_way: req.body.deliveryId || 1, | 177 | delivery_way: req.body.deliveryId || 1, |
149 | use_yoho_coin: req.body.yohoCoin || 0, | 178 | use_yoho_coin: req.body.yohoCoin || 0, |
179 | + gift_card_code: req.body.gift_card_code, | ||
150 | activity_id: activityId | 180 | activity_id: activityId |
151 | }; | 181 | }; |
152 | 182 | ||
@@ -210,7 +240,8 @@ exports.submit = (req, res, next) => { | @@ -210,7 +240,8 @@ exports.submit = (req, res, next) => { | ||
210 | product_sku: sku, | 240 | product_sku: sku, |
211 | activity_id: activityId, | 241 | activity_id: activityId, |
212 | uid, | 242 | uid, |
213 | - ip: req.ip || '' | 243 | + ip: req.ip || '', |
244 | + udid: req.sessionID || 'yoho' | ||
214 | }; | 245 | }; |
215 | 246 | ||
216 | if (req.body.invoice === 'true') { | 247 | if (req.body.invoice === 'true') { |
1 | 'use strict'; | 1 | 'use strict'; |
2 | - | 2 | +const _ = require('lodash'); |
3 | +const co = Promise.coroutine; | ||
4 | +const helpers = global.yoho.helpers; | ||
3 | const headerModel = require('../../../doraemon/models/header'); // 头部model | 5 | const headerModel = require('../../../doraemon/models/header'); // 头部model |
4 | const ticketsConfirmModel = require('../models/ticketsConfirm'); | 6 | const ticketsConfirmModel = require('../models/ticketsConfirm'); |
7 | +const shoppingModel = require('../models/shopping'); | ||
8 | +const orderModel = require('../models/order'); | ||
9 | +const paymentProcess = require(global.utils + '/payment-process'); | ||
5 | 10 | ||
6 | // cookie 参数 | 11 | // cookie 参数 |
7 | const actCkOpthn = { | 12 | const actCkOpthn = { |
8 | path: '/cart/index' | 13 | path: '/cart/index' |
9 | }; | 14 | }; |
10 | 15 | ||
11 | -const ticketsConfirm = (req, res) => { | 16 | +const ticketsConfirm = (req, res, next) => { |
12 | let headerData = headerModel.setNav({ | 17 | let headerData = headerModel.setNav({ |
13 | navTitle: '确认订单', | 18 | navTitle: '确认订单', |
14 | navBtn: false | 19 | navBtn: false |
@@ -19,8 +24,6 @@ const ticketsConfirm = (req, res) => { | @@ -19,8 +24,6 @@ const ticketsConfirm = (req, res) => { | ||
19 | module: 'cart', | 24 | module: 'cart', |
20 | page: 'tickets-confirm', | 25 | page: 'tickets-confirm', |
21 | title: '确认订单', | 26 | title: '确认订单', |
22 | - | ||
23 | - // pageFooter: true, | ||
24 | localCss: true, | 27 | localCss: true, |
25 | navBtn: false, | 28 | navBtn: false, |
26 | width750: true | 29 | width750: true |
@@ -37,27 +40,68 @@ const ticketsConfirm = (req, res) => { | @@ -37,27 +40,68 @@ const ticketsConfirm = (req, res) => { | ||
37 | 40 | ||
38 | let params = { | 41 | let params = { |
39 | uid: req.user.uid, | 42 | uid: req.user.uid, |
40 | - productSku: req.body.productSku, | ||
41 | - buyNumber: req.body.buyNumber, | 43 | + productSku: req.query.productSku, |
44 | + buyNumber: req.query.buyNumber, | ||
42 | useYohoCoin: orderInfo ? orderInfo.yohoCoin : 0, | 45 | useYohoCoin: orderInfo ? orderInfo.yohoCoin : 0, |
46 | + gift_card_code: orderInfo.gift_card_code || null, | ||
43 | yohoCoinMode: true | 47 | yohoCoinMode: true |
44 | }; | 48 | }; |
45 | 49 | ||
46 | - req.ctx(ticketsConfirmModel).ticketsConfirm(params).then(result => { | ||
47 | - res.render('ticketsConfirm', Object.assign(responseData, result)); | ||
48 | - }); | 50 | + co(function* () { |
51 | + let [result, validGiftCardCountData] = yield Promise.all([ | ||
52 | + req.ctx(ticketsConfirmModel).ticketsConfirm(params), | ||
53 | + req.ctx(shoppingModel).countUsableGiftCard(req.user.uid) // 可用礼品卡数量 | ||
54 | + ]); | ||
55 | + let validGiftCardCount = _.get(validGiftCardCountData, 'data.count', 0); | ||
56 | + | ||
57 | + res.render('ticketsConfirm', _.assign(responseData, result, { | ||
58 | + choseGiftCard: helpers.urlFormat('/cart/index/new/selectGiftcard'), | ||
59 | + giftCards: paymentProcess.handleGiftCards({ | ||
60 | + validGiftCardCount: validGiftCardCount, | ||
61 | + orderCompute: result.orderCompute | ||
62 | + }) | ||
63 | + })); | ||
64 | + })().catch(next); | ||
49 | }; | 65 | }; |
50 | 66 | ||
51 | -const submitTicket = (req, res) => { | 67 | +const submitTicket = (req, res, next) => { |
68 | + let uid = req.user.uid; | ||
69 | + let udid = req.sessionID || 'yoho'; | ||
70 | + let gift_card_code = req.body.gift_card_code; | ||
71 | + let verifyCode = req.body.verifyCode; | ||
52 | let params = { | 72 | let params = { |
53 | - uid: req.user.uid, | 73 | + uid: uid, |
74 | + udid: udid, | ||
54 | productSku: req.body.productSku, | 75 | productSku: req.body.productSku, |
55 | buyNumber: req.body.buyNumber, | 76 | buyNumber: req.body.buyNumber, |
56 | mobile: req.body.mobile, | 77 | mobile: req.body.mobile, |
57 | - useYohoCoin: req.body.useYohoCoin | 78 | + useYohoCoin: req.body.useYohoCoin, |
79 | + gift_card_code: gift_card_code, | ||
80 | + verifyCode: verifyCode | ||
58 | }; | 81 | }; |
59 | 82 | ||
60 | - req.ctx(ticketsConfirmModel).submitTicket(params).then(result => { | 83 | + co(function* () { |
84 | + // 使用礼品卡,发送验证码 | ||
85 | + if (gift_card_code) { | ||
86 | + if (!verifyCode) { | ||
87 | + yield req.ctx(orderModel).giftCardSendSms(uid); | ||
88 | + | ||
89 | + return res.json({ | ||
90 | + code: 411 | ||
91 | + }); | ||
92 | + } else { | ||
93 | + let verifyResult = yield req.ctx(orderModel).validRegCode({ | ||
94 | + uid, verifyCode, udid | ||
95 | + }); | ||
96 | + | ||
97 | + if (verifyResult.code !== 200) { | ||
98 | + return res.json(verifyResult); | ||
99 | + } | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + let result = yield req.ctx(ticketsConfirmModel).submitTicket(params); | ||
104 | + | ||
61 | if (result === {}) { | 105 | if (result === {}) { |
62 | result.message = '人太多啦,稍后再试!'; | 106 | result.message = '人太多啦,稍后再试!'; |
63 | } | 107 | } |
@@ -65,7 +109,7 @@ const submitTicket = (req, res) => { | @@ -65,7 +109,7 @@ const submitTicket = (req, res) => { | ||
65 | // 提交成功清除Cookie | 109 | // 提交成功清除Cookie |
66 | res.cookie('order-info', null, actCkOpthn); | 110 | res.cookie('order-info', null, actCkOpthn); |
67 | res.json(result); | 111 | res.json(result); |
68 | - }); | 112 | + })().catch(next); |
69 | }; | 113 | }; |
70 | 114 | ||
71 | const checkTickets = (req, res) => { | 115 | const checkTickets = (req, res) => { |
@@ -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; |
@@ -93,6 +94,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | @@ -93,6 +94,7 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | ||
93 | resu.cartPayData = result[0].data.shopping_cart_data.promotion_formula_list; | 94 | resu.cartPayData = result[0].data.shopping_cart_data.promotion_formula_list; |
94 | resu.price = parseInt(result[0].data.shopping_cart_data.last_order_amount, 10).toFixed(2); | 95 | resu.price = parseInt(result[0].data.shopping_cart_data.last_order_amount, 10).toFixed(2); |
95 | resu.yohoCoinCompute = this.yohoCoinCompute(result[0].data.shopping_cart_data); | 96 | resu.yohoCoinCompute = this.yohoCoinCompute(result[0].data.shopping_cart_data); |
97 | + resu.orderCompute = _.get(result[0], 'data'); | ||
96 | } | 98 | } |
97 | return resu; | 99 | return resu; |
98 | }); | 100 | }); |
@@ -108,7 +110,9 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | @@ -108,7 +110,9 @@ class ticketsConfirmModel extends global.yoho.BaseModel { | ||
108 | buy_number: param.buyNumber, | 110 | buy_number: param.buyNumber, |
109 | mobile: param.mobile, | 111 | mobile: param.mobile, |
110 | use_yoho_coin: param.useYohoCoin, | 112 | use_yoho_coin: param.useYohoCoin, |
111 | - qhy_union: '' | 113 | + gift_card_code: param.gift_card_code || null, |
114 | + qhy_union: '', | ||
115 | + udid: param.udid | ||
112 | }}).then((result) => { | 116 | }}).then((result) => { |
113 | return result; | 117 | return result; |
114 | }); | 118 | }); |
@@ -80,7 +80,7 @@ router.get('/index/buynow/selectGiftcard', authMW, BuyNowController.selectGiftca | @@ -80,7 +80,7 @@ router.get('/index/buynow/selectGiftcard', authMW, BuyNowController.selectGiftca | ||
80 | router.get('/home/orders/paynew', authMW, payController.payCenter); | 80 | router.get('/home/orders/paynew', authMW, payController.payCenter); |
81 | 81 | ||
82 | // 门票确认 | 82 | // 门票确认 |
83 | -router.post('/index/ticketsConfirm', authMW, ticketsConfirmController.ticketsConfirm); | 83 | +router.get('/index/ticketsConfirm', authMW, ticketsConfirmController.ticketsConfirm); |
84 | 84 | ||
85 | // 门票下单 | 85 | // 门票下单 |
86 | router.post('/index/submitTicket', ticketsConfirmController.submitTicket); | 86 | router.post('/index/submitTicket', ticketsConfirmController.submitTicket); |
@@ -51,6 +51,22 @@ | @@ -51,6 +51,22 @@ | ||
51 | </li> | 51 | </li> |
52 | </ul> | 52 | </ul> |
53 | </div> | 53 | </div> |
54 | + {{!-- 礼品卡 --}} | ||
55 | + {{#if giftCards}} | ||
56 | + <div class="gift-card"> | ||
57 | + <ul class="sale-invoice"> | ||
58 | + <li><a href="{{choseGiftCard}}"> | ||
59 | + <span class="title">礼品卡</span> | ||
60 | + {{# giftCards}} | ||
61 | + <span class="count">{{leftInfo}}</span> | ||
62 | + <span class="coupon-info pull-right"> | ||
63 | + {{rightInfo}}<i class="iconfont"></i> | ||
64 | + </span> | ||
65 | + {{/giftCards}} | ||
66 | + </a></li> | ||
67 | + </ul> | ||
68 | + </div> | ||
69 | + {{/if}} | ||
54 | <div class="sub-block delivery-id"> | 70 | <div class="sub-block delivery-id"> |
55 | <h3> | 71 | <h3> |
56 | <p>发票</p> | 72 | <p>发票</p> |
@@ -64,9 +64,9 @@ class OrderEnsure extends Page { | @@ -64,9 +64,9 @@ class OrderEnsure extends Page { | ||
64 | showSafeCheckDialog(renderData, sureCallback) { | 64 | showSafeCheckDialog(renderData, sureCallback) { |
65 | dialog.showDialog({ | 65 | dialog.showDialog({ |
66 | hasHeader: '安全验证', | 66 | hasHeader: '安全验证', |
67 | - dialogText: safeCheckBoxHbs(Object.assign(renderData, { | 67 | + dialogText: safeCheckBoxHbs(Object.assign({ |
68 | mobile: this.selector.userMobile.val() | 68 | mobile: this.selector.userMobile.val() |
69 | - })), | 69 | + }, renderData)), |
70 | hasFooter: { | 70 | hasFooter: { |
71 | leftBtnText: '取消', | 71 | leftBtnText: '取消', |
72 | rightBtnText: '确定' | 72 | rightBtnText: '确定' |
@@ -478,12 +478,14 @@ if (orderInfo('address') && orderInfo('address').is_support === 'N') { | @@ -478,12 +478,14 @@ if (orderInfo('address') && orderInfo('address').is_support === 'N') { | ||
478 | } | 478 | } |
479 | 479 | ||
480 | // 电子票下单 | 480 | // 电子票下单 |
481 | -function ticketsConfirm() { | 481 | +function ticketsConfirm(verifyCode) { |
482 | let data = { | 482 | let data = { |
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'), | ||
488 | + verifyCode: verifyCode || null | ||
487 | }; | 489 | }; |
488 | 490 | ||
489 | if (!$ticketsMobile.val()) { | 491 | if (!$ticketsMobile.val()) { |
@@ -501,6 +503,11 @@ function ticketsConfirm() { | @@ -501,6 +503,11 @@ function ticketsConfirm() { | ||
501 | // 下单成功调整支付页面 | 503 | // 下单成功调整支付页面 |
502 | if (ticket.code === 200) { | 504 | if (ticket.code === 200) { |
503 | window.location.href = '/home/orders/paynew?order_code=' + ticket.data.order_code; | 505 | window.location.href = '/home/orders/paynew?order_code=' + ticket.data.order_code; |
506 | + } else if (ticket.code === 411) { | ||
507 | + orderEnsure.showSafeCheckDialog({ | ||
508 | + message: ticket.message, | ||
509 | + mobile: $ticketsMobile.val() | ||
510 | + }, ticketsConfirm); | ||
504 | } else { | 511 | } else { |
505 | tip.show(ticket.message); | 512 | tip.show(ticket.message); |
506 | } | 513 | } |
@@ -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 | }; |
@@ -25,9 +25,8 @@ let functions = { | @@ -25,9 +25,8 @@ let functions = { | ||
25 | } | 25 | } |
26 | tip.show(addRestult.message || '人太多啦,稍后再试!'); | 26 | tip.show(addRestult.message || '人太多啦,稍后再试!'); |
27 | } else { | 27 | } else { |
28 | - $('#productSku').val(productSku); | ||
29 | - $('#buyNumber').val(buyNumber); | ||
30 | - $('#buyNowForm').submit(); | 28 | + window.location.href = '/cart/index/ticketsConfirm?productSku=' + productSku + |
29 | + '&buyNumber=' + buyNumber; | ||
31 | } | 30 | } |
32 | }, | 31 | }, |
33 | error: function() { | 32 | error: function() { |
-
Please register or login to post a comment