ticketsConfirm.js
2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
'use strict';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const indexModel = require('../models/ticketsConfirm');
// cookie 参数
const actCkOpthn = {
path: '/cart/index'
};
const ticketsConfirm = (req, res) => {
let headerData = headerModel.setNav({
navTitle: '确认订单',
navBtn: false
});
let responseData = {
pageHeader: headerData,
module: 'cart',
page: 'tickets-confirm',
title: '确认订单',
// pageFooter: true,
localCss: true,
navBtn: false,
width750: true
};
let orderInfo;
try {
orderInfo = JSON.parse(req.cookies['order-info']);
} catch (e) {
orderInfo = {};
res.cookie('order-info', null, actCkOpthn);
}
let params = {
uid: req.user.uid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
useYohoCoin: orderInfo ? orderInfo.yohoCoin : 0,
yohoCoinMode: true
};
indexModel.ticketsConfirm(params).then(result => {
res.render('ticketsConfirm', Object.assign(responseData, result));
});
};
const submitTicket = (req, res) => {
let params = {
uid: req.user.uid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
mobile: req.body.mobile,
useYohoCoin: req.body.useYohoCoin
};
indexModel.submitTicket(params).then(result => {
if (result === {}) {
result.message = '人太多啦,稍后再试!';
}
// 提交成功清除Cookie
res.cookie('order-info', null, actCkOpthn);
res.json(result);
});
};
const checkTickets = (req, res) => {
let params = {
uid: req.user.uid,
productSku: req.body.productSku,
buyNumber: req.body.buyNumber,
useYohoCoin: req.body.useYohoCoin
};
// 未登录
if (!req.user.uid) {
return res.json({
code: 401,
redirect: '/signin.html'
});
} else {
indexModel.checkTickets(params).then(result => {
res.json(result);
});
}
};
module.exports = {
ticketsConfirm,
submitTicket,
checkTickets
};