order.js
4.99 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
/**
* [个人中心]首页/我的订单
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2016/07/04
*/
'use strict';
const mcHandler = require('../models/menu-crumb-handler');
const orderModel = require('../models/order');
const cleanHtml = require(`${global.utils}/cleanHtml`);
const _ = require('lodash');
const crypto = global.yoho.crypto;
const config = global.yoho.config;
/**
* 我的订单
*/
const index = (req, res, next) => {
const type = req.query.type;
const page = req.query.page;
const uid = req.user.uid;
Promise.all([orderModel.getOrderData(uid, type, page), mcHandler.getMeThumb()]).then(result => {
const pageData = result[0];
const thumb = result[1];
res.display('index', {
page: 'order',
isMe: true,
content: Object.assign({
nav: mcHandler.getMeCrumb(),
navigation: mcHandler.getSideMenu('我的订单'),
banner: thumb
}, pageData)
});
}).catch(next);
};
const detail = (req, res, next) => {
const code = req.query.orderCode;
const uid = req.user.uid;
Promise.all([orderModel.getOrderDetail(uid, code), mcHandler.getMeThumb()]).then(result => {
const pageData = result[0];
const thumb = result[1];
if (_.has(pageData, 'orderDetail.order_code')) {
pageData.orderDetail.orderCodeM =
crypto.encryption(config.crypto.common, (pageData.orderDetail.order_code).toString());
}
// 转译
if (pageData.orderDetail) {
pageData.orderDetail.address = cleanHtml.htmlDecode(pageData.orderDetail.address);
pageData.orderDetail.allAddress = cleanHtml.htmlDecode(pageData.orderDetail.allAddress);
pageData.orderDetail.remark = cleanHtml.htmlDecode(pageData.orderDetail.remark);
if (pageData.orderDetail.invoice) {
pageData.orderDetail.invoice.title = cleanHtml.htmlDecode(pageData.orderDetail.invoice.title);
}
}
res.display('index', {
isMe: true,
page: 'order-detail',
content: Object.assign({
nav: mcHandler.getMeCrumb(),
navigation: mcHandler.getSideMenu('订单详情'),
banner: thumb
}, pageData)
});
}).catch(next);
};
const getOrderList = (req, res, next) => {
const type = req.query.type;
const page = req.query.page;
const uid = req.user.uid;
orderModel.getOrderData(uid, type, page).then(result => {
res.display('order-table', {
layout: false,
page: 'order',
isMe: true,
orderList: result.order.orderList,
paginationOpts: result.order.paginationOpts,
orderData: result.order.orderData
});
}).catch(next);
};
const getOrderTotal = (req, res, next) => {
const type = req.query.type;
const uid = req.user.uid;
orderModel.getOrderData(uid, type).then(result => {
res.json({
total: result.order.total,
type: result.order.type
});
}).catch(next);
};
const cancelOrder = (req, res, next) => {
const uid = req.user.uid;
const data = req.query;
orderModel.cancelOrder(uid, data).then(result => {
res.json(result);
}).catch(next);
};
const deleteOrder = (req, res, next) => {
const uid = req.user.uid;
const code = req.query.orderCode;
orderModel.deleteOrder(uid, code).then(result => {
res.json(result);
}).catch(next);
};
const getExpressInfo = (req, res, next) => {
const uid = req.user.uid;
const code = req.query.orderCode;
orderModel.getExpressInfo(uid, code).then(result => {
res.json(result);
}).catch(next);
};
const getCancelOrderReason = (req, res, next) => {
orderModel.getCancelOrderReason().then(result => {
res.json(result);
}).catch(next);
};
const editOrder = (req, res, next) => {
const uid = req.user.uid;
const parameter = req.body;
parameter.uid = uid;
parameter.orderCode = crypto.decrypt(config.crypto.common, parameter.orderCode);
if (!parameter.uid || !parameter.orderCode) {
res.json({
code: '401',
message: '请输入合法订单号'
});
} else {
orderModel.editOrder(parameter).then(result => {
res.json(result);
}).catch(next);
}
};
const reAdd = (req, res, next) => {
const uid = req.user.uid;
const code = req.query.orderCode;
orderModel.reAddCart(uid, code).then(result => {
res.json(result);
}).catch(next);
};
const confirmReceive = (req, res, next) => {
const uid = req.user.uid;
const code = req.query.orderCode;
orderModel.confirmReceive(uid, code).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index,
detail,
getOrderList,
getOrderTotal,
cancelOrder,
deleteOrder,
editOrder,
getExpressInfo,
getCancelOrderReason,
reAdd,
confirmReceive
};