orders.js
3.49 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
'use strict';
const _ = require('lodash');
const ordersService = require('../models/orders-service');
const index = (req, res, next) => {
let uid = req.user.uid;
let page = _.parseInt(req.query.page) || 1;
let type = _.parseInt(req.query.type) || ordersService.ORDER_TYPE.all;
let limit = _.parseInt(req.query.limit) || 10;
ordersService.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: '缺少参数'
});
}
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: '缺失必填项'
});
}
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 = phoneNum ? `${phoneCode}-${phoneNum}` : '';
if (!orderId || !userName || !areaCode || !address) {
return res.json({
code: 400,
message: '缺失必镇项'
});
}
ordersService.updateDeliveryAddress(orderId, userName, areaCode, address, mobile, phone, uid)
.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: '参数缺失'
});
}
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 || '';
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');
}
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);
};
module.exports = {
index,
reBuy,
del,
modifyAddress,
confirm,
cancel,
detail
};