orderDetail.js
5.92 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/**
* 个人中心 controller
* @author: chengyao.guo<chengyao.guo@yoho.cn>
* @date: 2016/08/10
*/
'use strict';
const helpers = global.yoho.helpers;
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const orderDetailModel = require('../models/orderDetail');
const orderModel = require('../models/order');
const payModel = require('../../cart/models/pay');
const addressModel = require('../models/address');
const addressProcess = require(global.utils + '/address-process');
const orderDetailData = (req, res, next) => {
let uid = req.user.uid;
let orderCode = req.query.order_code;
let serviceUrl = _.get(req.app.locals.wap, 'clientService.new', false) ?
helpers.urlFormat('/service/im') :
'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409&info=';
if (req.query.openId) {
// 微信支付成功,发送支付确认接口
payModel.sendPayConfirm(orderCode, 22, uid);
}
Promise.all([
orderDetailModel.orderDetailData(uid, orderCode),
orderDetailModel.closeReasons(),
orderModel.refundReason()
]).then(result => {
let orderDetail = result[0];
let cancelReason = result[1];
let refundReason = result[2];
if (!orderDetail || _.isEmpty(orderDetail)) {
return next(404);
}
Object.assign(orderDetail, {
cancelReason: cancelReason
});
orderDetail.serviceUrl = serviceUrl;
res.render('orderDetail', {
module: 'home',
page: 'orderdetail',
pageHeader: headerModel.setNav({
navTitle: '订单详情'
}),
title: '订单详情',
pageFooter: true,
orderDetail: orderDetail,
refundReason: refundReason,
localCss: true,
});
}).catch(next);
};
// 删除订单
const delOrder = (req, res, next) => {
let orderCode = req.query.id;
let uid = req.user.uid;
orderDetailModel.delOrder(orderCode, uid).then((result) => {
res.json(result);
}).catch(next);
};
// 再次购买
const readdData = (req, res, next) => {
let orderCode = req.query.orderCode;
let uid = req.user.uid;
orderDetailModel.readdData(orderCode, uid).then((result) => {
res.json(result);
}).catch(next);
};
// 取消订单
const cancelOrder = (req, res, next) => {
let orderCode = req.query.id;
let uid = req.user.uid;
let reasonId = req.query.reasonId || 1;
let gender = req.query.gender || '1,3';
let channel = req.query.channel || 1;
let reason = req.query.reason;
orderDetailModel.cancelOrder(orderCode, uid, reasonId, gender, channel, reason).then((result) => {
res.json(result);
}).catch(next);
};
/**
* 申请退款
*/
const refundApply = (req, res, next) => {
let orderCode = req.query.id;
if (!orderCode) {
return res.json({
code: 404,
msg: '订单号不存在!'
});
}
orderDetailModel.refundApply({
orderCode: req.query.id,
uid: req.user.uid,
reasonId: req.query.reasonId || 1,
reason: req.query.reason
}).then(result => {
res.json(result);
}).catch(next);
};
/**
* 我的订单-查看物流信息
*/
const logistic = (req, res, next) => {
orderDetailModel.logistics(req.query.order_code, req.user.uid).then(result => {
res.render('logistic', _.assign(result, {
pageHeader: headerModel.setNav({
navTitle: '订单详情',
navBtn: false
}),
module: 'home',
page: 'logistic',
logisticInfoPage: true
}));
}).catch(next);
};
/**
* 订单修改地址页面
*/
const addressModify = (req, res, next) => {
let uid = req.user.uid;
let orderCode = req.query.orderCode;
let areaCode = req.query.areaCode;
let provinceAreaCode = req.query.provinceAreaCode || false;
addressModel.getAddressData({uid: uid}).then(result => {
let userAddressList = result;
let addressData = addressProcess.getAddressByAreaCode(areaCode,
_.get(userAddressList, 'data', [])) || {};
Object.assign(addressData, {
orderCode: orderCode,
});
if (provinceAreaCode) {
// 不允许修改省份,字符串拆分
let areaArray = addressData.area.split(' ');
let area = _.slice(areaArray, 1);
Object.assign(addressData, {
changeProvince: false,
provinceCode: provinceAreaCode,
province: areaArray[0],
area: area
});
} else {
Object.assign(addressData, {
changeProvince: true,
});
}
res.render('order-address-modify', Object.assign(addressData, {
pageHeader: headerModel.setNav({
navTitle: '修改地址'
}),
module: 'home',
page: 'order-address-modify',
localCss: true
}));
}).catch(next);
};
/**
* 修改订单地址
* @param {*} req
* @param {*} res
* @param {*} next
*/
const changeAddress = (req, res, next) => {
let uid = req.user.uid;
let udid = req.cookies._yasvd || '';
if (!uid) {
return res.json({
code: 401,
message: '用户数据不存在!'
});
}
orderDetailModel.changeAddress({
uid: req.user.uid,
orderCode: req.body.orderCode,
username: req.body.username,
areaCode: req.body.area_code,
address: req.body.address,
mobile: req.body.mobile,
udid: udid
}).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
orderDetailData,
delOrder,
readdData,
cancelOrder,
refundApply,
logistic,
addressModify,
changeAddress
};