orders.js
4.89 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
193
'use strict';
const _ = require('lodash');
const ordersService = require('../models/orders-service');
const index = (req, res, next) => {
let ordersModel = req.ctx(ordersService);
let uid = req.user.uid;
let page = _.parseInt(req.query.page) || 1;
let type = _.parseInt(req.query.type) || ordersModel.ORDER_TYPE.all;
let limit = _.parseInt(req.query.limit) || 10;
ordersModel.index(uid, page, limit, type).then((result) => {
return res.render('home/orders/orders', {
meOrdersPage: true,
meOrders: result
});
}).catch(next);
};
const reBuy = (req, res, next) => {
let uid = req.user.uid;
let orderId = req.body.orderCode || '';
if (!orderId) {
return res.json({
code: 400,
message: '缺少参数'
});
}
req.ctx(ordersService).reBuy(uid, orderId).then((result) => {
return res.json(result);
}).catch(next);
};
const del = (req, res, next) => {
let uid = req.user.uid;
let orderId = req.body.orderCode || '';
let channel = req.yoho.channel;
let gender = req.yoho.gender;
if (!orderId) {
return res.json({
code: 400,
message: '缺失必填项'
});
}
req.ctx(ordersService).del(uid, gender, channel, orderId).then((result) => {
return res.json(result);
}).catch(next);
};
const modifyAddress = (req, res, next) => {
let uid = req.user.uid;
let orderId = req.body.orderCode || ''; // 订单号
let userName = req.body.userName || ''; // 收货人
let areaCode = req.body.areaCode || ''; // 区号
let address = req.body.address || ''; // 地址
let mobile = req.body.mobile || ''; // 手机号码
let phoneNum = req.body.phoneNum || ''; // 固定电话
let phoneCode = req.body.phoneCode || ''; // 电话编号
let phone = (function() {
if (phoneNum) {
if (phoneCode) {
return `${phoneCode}-${phoneNum}`;
} else {
return phoneNum;
}
} else {
return '';
}
}());
let udid = req.yoho.udid;
if (!orderId || !userName || !areaCode || !address) {
return res.json({
code: 400,
message: '缺失必镇项'
});
}
req.ctx(ordersService).updateDeliveryAddress(orderId, userName, areaCode, address, mobile, phone, uid, udid)
.then(result => res.json(result))
.catch(next);
};
const confirm = (req, res, next) => {
let uid = req.user.uid;
let orderId = req.body.orderCode || '';
if (!orderId) {
return res.json({
code: 400,
message: '参数缺失'
});
}
req.ctx(ordersService).confirm(uid, orderId).then((result) => {
return res.json(result);
}).catch(next);
};
const cancel = (req, res, next) => {
let uid = req.user.uid;
let orderId = req.body.orderCode || '';
let reason = req.body.reason || '';
let reasonId = req.body.reasonId || '';
req.ctx(ordersService).cancel(uid, orderId, reason, reasonId)
.then(result => res.json(result))
.catch(next);
};
const detail = (req, res, next) => {
let orderId = req.query.orderCode || req.query.order_code;
let uid = req.user.uid;
if (!orderId) {
return res.redirect('/home');
}
req.ctx(ordersService).detail(uid, orderId).then((result) => {
if (_.isEmpty(result)) {
return res.redirect('/home');
}
return res.render('home/orders/order-detail', {
meOrderPage: true,
meOrderDetail: result.detail,
packages: result.package,
cancelReason: result.cancelReason
});
}).catch(next);
};
const express = (req, res, next) => {
let orderId = req.query.orderId || '';
let uid = req.user.uid;
let payType = req.query.payType;
let time = req.query.time;
if (!orderId) {
return res.json({
code: 400,
message: '参数出错'
});
}
req.ctx(ordersService).express(orderId, uid, payType, time).then((result) => {
return res.json(result);
}).catch(next);
};
const refund = (req, res, next) => {
let uid = req.user.uid;
let orderId = req.query.orderId;
let reasonId = req.query.reasonId;
if (!orderId || !reasonId) {
return res.json({
code: 400,
message: '参数错误'
});
}
req.ctx(ordersService).refund(uid, orderId, reasonId).then((result) => {
return res.json(result);
}).catch(next);
};
const refundReason = (req, res, next) => {
req.ctx(ordersService).refundReason().then((result) => {
return res.json({
code: 200,
data: result
});
}).catch(next);
};
module.exports = {
index,
reBuy,
del,
modifyAddress,
confirm,
cancel,
detail,
express,
refund,
refundReason
};