router.js
14.4 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/**
* router of sub app product
* @author: weiqingting<qingting.wei@yoho.cn>
* @date: 2016/05/06
*/
'use strict';
const express = require('express');
const router = express.Router(); // eslint-disable-line
const cRoot = './controllers';
const headerModel = require('../../doraemon/models/header');
const msgModel = require('./models/message');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const indexController = require(`${cRoot}/index`);
const commentController = require(`${cRoot}/comment`);
// const consultController = require(`${cRoot}/consult`);
// const complaintsController = require(`${cRoot}/complaints`);
const messageController = require(`${cRoot}/message`);
// const returnsController = require(`${cRoot}/returns`);
// const CurrencyController = require(`${cRoot}/Currency`);
const personalController = require(`${cRoot}/qrcode`);
// const RedenvelopesController = require(`${cRoot}/Redenvelopes`);
// const VipController = require(`${cRoot}/vip`);
// const CouponsController = require(`${cRoot}/coupons`);
const UserController = require(`${cRoot}/user`);
const bindController = require(`${cRoot}/3party-bind`);
const AccountController = require(`${cRoot}/account`);
const favoriteController = require(`${cRoot}/favorite`);
const ordersController = require(`${cRoot}/orders`);
// const AddressController = require(`${cRoot}/address`);
// const GiftController = require(`${cRoot}/gift`);
const homeNav = (req) => {
return [
{
title: '交易管理',
subNav: [
{name: '我的订单', href: '/home/orders', catchs: ['/home/orders', '/home/index', '/home/orders/detail']},
{name: '我的收藏', href: '/home/favorite', catchs: ['/home/favorite/reduction']},
{name: '我的有货币', href: '/home/currency'},
{name: '我的红包', href: '/home/redenvelopes'},
{name: '我的优惠券', href: '/home/coupons'},
{name: '我的VIP', href: '/home/vip'}
]
},
{
title: '服务中心',
subNav: [
{name: '我的退/换货', href: '/home/returns'},
{name: '我的咨询', href: '/home/consult'},
{name: '我的评论', href: '/home/comment'},
// {name: '我的投诉', href: '/home/complaints'},
{name: '我的信息', href: '/home/message', count: 0},
{
name: '在线客服',
href: _.get(req.app.locals.pc, 'clientService.new', false) ?
'/service/client' : 'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409',
isBlank: true
}
]
},
{
title: '个人信息管理',
subNav: [
{name: '编辑个人资料', href: '/home/user'},
{name: '账号安全', href: '/home/account', catchs: [
'/home/account/userpwd',
'/home/account/email',
'/home/account/mobile',
'/home/account/checkverifycode',
'/home/account/checkpassword',
'/home/account/verifypassword',
'/home/account/modifypwd',
'/home/account/sendemail',
'/home/account/checkemail',
'/home/account/modifyemail',
'/home/account/sendemailsuccess',
'/home/account/mailresult',
'/home/account/checkmobile',
'/home/account/checkmobilemsg',
'/home/account/sendmobilemsg',
'/home/account/modifymobile'
]},
{name: '地址管理', href: '/home/address'},
{name: '兑换礼品卡', href: '/home/gift'}
]
}
];
};
const getActiveNav = (req, count)=>{
let mHomeNav = _.cloneDeep(homeNav(req));
let activeNav = null;
mHomeNav = mHomeNav.map((item) => {
item.subNav = item.subNav.map((nav) => {
let curMatchPath = req.originalUrl;
if (!nav.matchQuery && curMatchPath.indexOf('?') >= 0) { // 严格的路径匹配,包含后面的参数
curMatchPath = curMatchPath.substr(0, curMatchPath.indexOf('?'));
}
if (curMatchPath === nav.href) {
nav.active = true;
}
if (nav.name === '我的信息') {
nav.count = +count;
}
if (nav.catchs) {
let index = nav.catchs.indexOf(curMatchPath);
if (index > -1) {
nav.active = true;
nav.curHref = nav.catchs[index];
}
}
if (nav.active) {
activeNav = nav;
}
nav.href = nav.href.indexOf('http://') > -1 ? nav.href : helpers.urlFormat(nav.href);
return nav;
});
return item;
});
return {
homeNav: mHomeNav,
activeNav: activeNav
};
};
const getHomeNav = (req, res, next) => {
msgModel.unreadTotal(req.user.uid).then(result => {
let navs = getActiveNav(req, _.get(result, 'data.total', 0));
let activeNav = navs.activeNav;
let bread = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}];
if (activeNav) {
bread.push({
name: '个人中心',
href: helpers.urlFormat('/home')
});
bread.push({
name: activeNav.name
});
// 订单详情
if (activeNav.curHref === '/home/orders/detail') {
Object.assign(_.last(bread), {
href: helpers.urlFormat('/home/orders')
});
bread.push({
name: '订单详情'
});
}
} else {
bread.push({
name: '个人中心'
});
}
res.locals.path = bread; // [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}, {name: '个人中心'}];
res.locals.homeNav = navs.homeNav;
res.locals.userThumb = '//img10.static.yhbimg.com/headimg/' +
'2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
next();
});
};
const getCommonHeader = (req, res, next) => {
let channel = req.query.channel ? req.query.channel : 'boys';
headerModel.requestHeaderData(channel).then((result)=>{
_.merge(res.locals, result);
next();
});
};
// 首页
router.get(['/index','/'], [getHomeNav, getCommonHeader], indexController.index);
// 查看二维码
router.get('/QRcode', [getHomeNav, getCommonHeader], personalController.QRcode);
// 我的评论
router.get('/comment', [getCommonHeader, getHomeNav], commentController.index);
router.post('/comment/saveComment', commentController.saveComment);
router.get('/comment/order', [getCommonHeader, getHomeNav], commentController.commentList4Order);
// 我的咨询
// router.get('/consult', [getCommonHeader, getHomeNav], consultController.index);
// 我的投诉
// router.get('/complaints', [getCommonHeader, getHomeNav], complaintsController.index);
// router.post('/complaints/submit', complaintsController.submit);
// router.post('/complaints/cancel', complaintsController.cancel);
// 我的消息
router.get('/message', [getCommonHeader, getHomeNav], messageController.index);
router.get('/message/detail', [getCommonHeader, getHomeNav], messageController.detail);
router.get('/message/del', messageController.delMsg);
router.get('/message/read', messageController.readMsg);
router.get('/message/pickCoupon', messageController.pickCoupon);
// 我的退/换货
// router.get('/returns', returnsController.index);
// router.get('/refund/apply', returnsController.refundApply);
// router.get('/refund/detail', returnsController.refundDetail);
// router.get('/exchange/apply', returnsController.exchangeApply);
// router.get('/exchange/detail', returnsController.refundDetail);
// router.get('/returns/success', returnsController.index);
// // 地址管理
// router.get('address', addressController.index);
// router.get('address/area', addressController.area);
// router.get('/index', [getCommonHeader, getHomeNav], IndexController.index);
// router.get('/currency', CurrencyController.index);
/* 我的红包*/
// router.get('/redenvelopes', RedenvelopesController.index);
/* 我的VIP*/
// router.get('/vip', VipController.index);
/********************************* 我的收藏开始 *****************************************/
// 我的收藏
router.get('/favorite', [getCommonHeader, getHomeNav], favoriteController.index);
// 品牌页新品到着
router.get('/favorite/newproduct', favoriteController.newProduct);
// 降价提醒
router.get('/favorite/reduction', [getCommonHeader, getHomeNav], favoriteController.reduction);
// 设置降价提醒
router.get('/favorite/notice', favoriteController.notice);
// 取消降价提醒
router.get('/favorite/cancelnotice', favoriteController.cancelNotice);
// 取消收藏
router.get('/favorite/cancel', favoriteController.cancel);
/********************************* 我的收藏结束 *****************************************/
/********************************* 我的订单开始 *****************************************/
router.get('/orders', [getCommonHeader, getHomeNav], ordersController.index);
// 重新加入购物车
router.post('/orders/readd', ordersController.reBuy);
// 删除订单
router.post('/orders/delorder', ordersController.del);
// 修改地址
router.post('/orders/modifyAddress', ordersController.modifyAddress);
// 确认订单
router.post('/orders/confirmOrder', ordersController.confirm);
// 取消订单
router.post('/orders/cancelOrder', ordersController.cancel);
// 订单详情
router.get('/orders/detail', [getCommonHeader, getHomeNav], ordersController.detail);
/********************************* 我的订单结束 *****************************************/
// router.get('/coupons', CouponsController.index);
router.get('/user', [getCommonHeader, getHomeNav], UserController.index);
router.post('/user/edituserinfo', UserController.editUserInfo);
router.post('/user/editusercontactinfo', UserController.editUserContactInfo);
router.post('/user/edituserhabitsinfo', UserController.editUserHabitsInfo);
router.post('/user/edituserlikebrand', UserController.editUserLikeBrand);
router.post('/user/isbrandname', UserController.isBrandName);
// 二维码登录
// router.post('/passport/login/qrcode/refresh', bindController.local.qrcode.refresh); // 刷新二维码
// router.post('/passport/login/qrcode/check', bindController.local.qrcode.check); // 验证二维码的状态
// 微信登录
router.get('/bind/wechat', bindController.wechat.login); // 微信登录, 兼容 PHP 的路径
router.get('/bind/wechat/callback', bindController.wechat.callback);
// sina登录
router.get('/bind/sina', bindController.sina.login);
router.get('/bind/sina/callback', bindController.sina.callback);
// qq登录
router.get('/bind/qq', bindController.qq.login);
router.get('/bind/qq/callback', bindController.qq.callback);
// alipay登录
router.get('/bind/alipay', bindController.alipay.login);
router.get('/bind/alipay/callback', bindController.alipay.callback);
// douban登录
router.get('/bind/douban', bindController.douban.login);
// router.get('/bind/douban/callback', bindController.douban.callback);
// renren登录
router.get('/bind/renren', bindController.renren.login);
router.get('/bind/renren/callback', bindController.renren.callback);
router.post('/cancelbind/:type', bindController.cancelBind);
//
// router.get('/address/area', UserController.getProviceList);
//
// router.get('/account', [getCommonHeader, getHomeNav], AccountController.index);
//
// router.get('/account/userpwd', [getCommonHeader, getHomeNav], AccountController.userPwd);
//
// router.get('/account/email', [getCommonHeader, getHomeNav], AccountController.userEmail);
//
// router.get('/account/mobile', [getCommonHeader, getHomeNav], AccountController.userMobile);
//
// router.post('/account/checkverifycode', [getCommonHeader, getHomeNav], AccountController.checkVerifyCode);
//
// router.post('/account/checkpassword', [getCommonHeader, getHomeNav], AccountController.checkPassword);
//
router.get('/account', [getCommonHeader, getHomeNav], AccountController.index);
router.get('/account/userpwd', [getCommonHeader, getHomeNav], AccountController.userPwd);
router.get('/account/email', [getCommonHeader, getHomeNav], AccountController.userEmail);
router.get('/account/mobile', [getCommonHeader, getHomeNav], AccountController.userMobile);
router.post('/account/checkverifycode', [getCommonHeader, getHomeNav], AccountController.checkVerifyCode);
router.post('/account/checkpassword', [getCommonHeader, getHomeNav], AccountController.checkPassword);
router.post('/account/verifypassword', [getCommonHeader, getHomeNav], AccountController.verifyPassword);
router.post('/account/modifypwd', [getCommonHeader, getHomeNav], AccountController.modifyPwd);
router.post('/account/sendemail', AccountController.sendEmail);
router.post('/account/checkemail', [getCommonHeader, getHomeNav], AccountController.checkEmail);
router.post('/account/modifyemail', [getCommonHeader, getHomeNav], AccountController.modifyEmail);
router.get('/account/sendemailsuccess', [getCommonHeader, getHomeNav], AccountController.sendEmailSuccess);
router.get('/account/mailresult', [getCommonHeader, getHomeNav], AccountController.mailResult);
router.post('/account/checkmobile', AccountController.checkMobile);
router.post('/account/checkmobilemsg', AccountController.checkMobileMsg);
router.post('/account/sendmobilemsg', AccountController.sendMobileMsg);
router.post('/account/modifymobile', AccountController.modifyMobile);
//
// router.get('/address', [getCommonHeader, getHomeNav], AddressController.index);
//
// router.get('/address/editAddress', AddressController.editAddress);
//
// router.post('/address/saveAddress', AddressController.saveAddress);
//
// router.get('/address/delAddress', AddressController.delAddress);
//
// router.get('/address/defaultAddress', AddressController.defaultAddress);
//
// router.get('/gift', [getCommonHeader, getHomeNav], GiftController.index);
//
// router.post('/gift/exchange', GiftController.exchange);
module.exports = router;