order.js
5.08 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
* 订单相关操作.
* @author hgwang
* @date 2016-07-22
*/
'use strict';
const orderModel = require('../models/order');
const notLoginCode = 400;
const notLoginTip = '抱歉,您暂未登录!';
const _ = require('lodash');
const order = {
orders: (req, res) => {
const type = req.query.type || 1;
res.render('order', {
module: 'me',
page: 'order',
type: type
});
},
orderDetail: (req, res) => {
const orderCode = req.query.orderCode;
const uid = req.user.uid;
if (!uid && req.xhr) {
return res.json({
code: notLoginCode,
message: notLoginTip
});
}
res.render('order-detail', {
module: 'me',
page: 'order-detail',
orderCode: orderCode
});
},
getOrderData: (req, res, next) => {
const uid = req.user.uid;
if (!uid && req.xhr) {
return res.json({
code: notLoginCode,
message: notLoginTip
});
}
const param = {
uid: uid,
page: req.query.page,
type: req.query.type,
limit: req.query.limit
};
orderModel.getOrders(param).then(result => {
return res.json(result);
}).catch(next);
},
getOrderDetailData: (req, res, next) => {
const orderCode = req.query.orderCode;
const uid = req.user.uid;
if (!uid && req.xhr) {
return res.json({
code: notLoginCode,
message: notLoginTip
});
}
orderModel.getOrderDetail(uid, orderCode).then(result => {
if (result.data.promotion_formulas) {
_.forEach(result.data.promotion_formulas, function(val) {
if (val.promotion === '活动金额') {
val.promotion = 'VIP优惠';
}
});
}
return res.json(result);
}).catch(next);
},
cancelOrder: (req, res, next) => {
const orderCode = req.body.orderCode;
const reasonId = req.body.reasonId;
const reason = req.body.reason;
const uid = req.user.uid;
orderModel.cancelOrder(uid, orderCode, reasonId, reason).then(result => {
return res.json(result);
}).catch(next);
},
readdData: (req, res, next) => {
// 再次购买
const orderCode = req.body.orderCode;
const uid = req.user.uid;
orderModel.readdData(orderCode, uid).then((result) => {
res.json(result);
}).catch(next);
},
confirmOrder: (req, res, next) => {
const uid = req.user.uid;
const orderode = req.body.orderCode;
orderModel.confirmOrder(uid, orderode).then(result => {
return res.json(result);
}).catch(next);
},
deleteOrder: (req, res, next) => {
const orderCode = req.body.orderCode;
const uid = req.user.uid;
if (!uid && req.xhr) {
return res.json({
code: notLoginCode,
message: notLoginTip
});
}
orderModel.deleteOrder(orderCode, uid).then(result => {
return res.json(result);
}).catch(next);
},
coin: (req, res, next) => {
orderModel.getCoins(req.user.uid).then(result => {
res.render('coin', {
module: 'me',
page: 'coin',
coin: result
});
}).catch(next);
},
/**
* 获取yoho币明细
* @param req
* @param res
* @returns {*|{read, write}}
*/
getCoinDetail: (req, res, next) => {
const uid = req.user.uid;
const page = req.query.page;
const limit = req.query.limit;
if (!uid && req.xhr) {
return res.json({
code: notLoginCode,
message: notLoginTip
});
}
orderModel.getCoinDetail(uid, page, limit).then(result => {
return res.json(result);
}).catch(next);
},
// 订单-物流
logistic: (req, res) => {
res.render('order-logistic', {
module: 'me',
page: 'order-logistic'
});
},
// API- 订单-物流
getOrderLogisticdate: (req, res, next) => {
(req.query.type === 'exchange') && (req.query.type = 'change');
orderModel.getOrderLogisticdate({
uid: req.user.uid || '',
type: req.query.type || '',
order_code: req.query.orderCode,
id: req.query.id
}).then(result => {
return res.json(result);
}).catch(next);
},
cancelReason: (req, res) => {
res.render('cancelreason', {
module: 'me',
page: 'cancelreason'
});
},
// 获取取消订单原因
getCancelReason: (req, res, next) => {
orderModel.getCancelReason().then(result => {
return res.json(result);
}).catch(next);
}
};
module.exports = order;