index.js
10.9 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
/**
* 编辑页
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 2016/09/05
*/
'use strict';
const mRoot = '../models';
const typeLib = require('../../../config/type-lib');
const IndexModel = require(`${mRoot}/index`);
const headerModel = require('../../../doraemon/models/header'); // 头部model
const footerModel = require('../../../doraemon/models/footer_tab'); // 底部tab
const guangProcess = require(`${global.utils}/guang-process`);
const stringProcess = require(`${global.utils}/string-process`);
const Promise = require('bluebird');
const qs = require('querystring');
const channels = {
boys: 1,
girl: 2,
kids: 3,
lifestyle: 4
};
const listTDK = {
0: {
title: '最新潮流资讯-YOHO!BUY 有货',
keywords: '最新潮流文章,潮流资讯,逛潮流',
description: '有货网每天提供全球最新最潮的潮流文章资讯,宣传潮流商品,潮流文化,潮流品牌等信息,想更多了解潮流最新资讯就来有货网!'
}, // 最新
1001: {
title: '人气潮流资讯-YOHO!BUY 有货',
keywords: '人气潮流文章,潮流人气,逛潮流人气',
description: '有货网每天提供全球人气最高的潮流文章资讯,宣传潮流商品,潮流文化,潮流品牌等信息,想更多了解高人气潮流资讯就来有货网!'
}, // 人气
2: {
title: '潮流搭配_潮流资讯-YOHO!BUY 有货',
keywords: '搭配潮流文章,潮流搭配',
description: '有货网每天提供全球最新最潮的潮流搭配文章资讯,宣传潮流商品,潮流文化,潮流品牌等信息,想更多了解学习潮流搭配资讯就来有货网!'
}, // 搭配
4: {
title: '潮流品牌_潮流资讯-YOHO!BUY 有货',
keywords: '逛潮品,潮流潮品,潮品资讯',
description: '有货网每天提供全球最新最潮的潮流潮品文章资讯,宣传潮流商品,潮流文化,潮流品牌等信息,想更多了解学习潮流潮品资讯就来有货网!'
}, // 潮品
22: {
title: 'Buy TV潮流视频_潮流资讯-YOHO!BUY 有货',
keywords: '潮流视频,看潮流',
description: '有货网每天提供全球最新最潮最精彩的潮流视频,宣传潮流商品,潮流文化,潮流品牌等信息,想更多欣赏潮流视频就来有货网!'
} // 视频
};
/**
* [编辑页面]
*/
const editor = (req, res, next) => {
let uid = req.user.uid || req.query.uid,
udid = req.cookies.udid,
id = req.query.id || req.params[0] || 0,
title = '编辑简介',
parameter = {},
isApp = req.yoho.isApp,
gender = req.query.gender ||
req.query.channel && typeLib.channels[req.query.channel] ||
req.cookies._Channel && channels[req.cookies._Channel] ||
1;
if (!isApp) {
parameter = {
pageHeader: headerModel.setNav({
navTitle: title
})
};
}
return Promise.all([
req.ctx(IndexModel).getAuthor(id),
req.ctx(IndexModel).getArticleList(gender, 0, uid, udid, 1, null, id)]
).then(datas => {
let authorData = datas[0],
articleListData = datas[1];
let build = [];
let name = authorData.data ? authorData.data.name : '';
let total = articleListData.data ? articleListData.data.total : 0;
if (articleListData.data && articleListData.data.list && articleListData.data.list.artList) {
articleListData.data.list.artList.forEach(articleData => {
articleData.colparam = {
urlpath: req.path,
param: `?id=${id}`
};
build.push(guangProcess.formatArticle(articleData, true, isApp, false, uid));
});
if (!build.length) {
res.set('Cache-Control', 'no-cache');
}
res.render('index/list', Object.assign({
page: 'index-editor',
title: `【${name}】潮流编辑${name}-YOHO!BUY 有货网`,
keywords: `${name},潮流编辑${name},潮流编辑`,
description: `有货逛潮流,潮流编辑${name}分享大量原创潮流资讯,掌握大量不同类别的潮流文化知识信息,尽在有货逛潮流。`,
guangList: true,
gender: gender,
guang: {
infos: build,
isApp: isApp,
authorInfo: authorData.data,
total: total
},
localCss: true
}, parameter));
} else {
return next();
}
}).catch(next);
};
// 301到新路由
const editorRedirect = (req, res, next) => {
let id = req.query.id;
if (id) {
let redirectUrl = '/guang/author';
if (req.yoho.channel !== req.cookies._Channel) {
redirectUrl += `-${req.yoho.channel}`;
}
delete req.query.id;
let param = qs.stringify(req.query);
if (param) {
param = '?' + param;
}
redirectUrl += `-${id}/${param}`;
res.redirect(301, redirectUrl);
} else {
return next();
}
};
/**
* [逛列表页面的资讯分页]
* @param {[type]} req [description]
* @param {[type]} res [description]
* @param {Function} next [description]
* @return {[type]} [description]
*/
const pageData = (req, res, next) => {
/* 判断是不是AJAX请求 */
if (!req.xhr) {
res.json({
code: 400,
message: '非法请求',
data: ''
});
return;
}
/* 判断参数是否有效 */
let tag = req.query.tag,
sortId = req.query.type || 0,
page = req.query.page,
gender = req.query.gender,
authorId = req.query.authorId,
isApp = req.yoho.isApp || false,
isTab = req.query.isTab || false,
showAuthor = false;
let uid = req.user.uid || req.query.uid,
udid = req.cookies.udid;
if (!stringProcess.isNumeric(sortId)) {
res.json({
code: 400,
message: '参数错误',
data: ''
});
return;
}
if (!page && !isNaN(page)) {
res.json({
code: 400,
message: '参数错误',
data: ''
});
return;
}
if (!authorId && isNaN(authorId)) {
showAuthor = true;
}
return req.ctx(IndexModel).getPageData(gender,
sortId,
uid,
udid,
page,
tag,
authorId,
isApp,
showAuthor,
isTab).then(data => {
if (data) {
res.render('index/page', Object.assign(data, {
layout: false
}));
} else {
res.json({
code: 400,
message: '',
data: ''
});
}
}).catch(next);
};
/**
* 逛列表页
* @param req
* @param res
* @param next
*/
const index = (req, res, next) => {
let uid = req.user.uid || req.query.uid;
let responseData = {
module: 'guang',
page: 'index',
title: '逛潮流,最新原创潮流资讯 |YOHO!BUY有货',
keywords: '潮流资讯,潮流文章,有货潮流分享',
description: '来有货玩潮流,潮流资讯大分享!年轻人潮流购物中心,了解潮流趋势、掌握潮流文化知识信息,尽在有货逛潮流!',
showFooterTab: footerModel.getUrlData('guang'),
pageStyle: 'guang-bg'
};
let param = {
uid: uid,
udid: req.user.udid,
type: stringProcess.paramsFilter(req.query.type || req.query.id) || '0',
gender: req.query.gender || req.query.channel && typeLib.gender[req.query.channel] || '1,3'
};
responseData = Object.assign(responseData, listTDK[param.type]);
req.ctx(IndexModel).getArticle(param).then(result => {
if (result && result.guang && result.guang.infos) {
if (!result.guang.infos.length) {
res.set('Cache-Control', 'no-cache');
}
}
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy= {"action":"go.guangchannel","params":{"id":${param.type}}}`;
res.render('guang', Object.assign(responseData, result, {
localCss: true
}));
}).catch(next);
};
/**
* 逛标签页
* @param req
* @param res
* @param next
*/
const tag = (req, res, next) => {
let uid = req.user.uid || req.query.uid || 0;
let headerData = headerModel.setNav({
navTitle: '逛标签'
});
let tagTitle = req.query.query || '';
let responseData = {
pageHeader: headerData,
module: 'guang',
page: 'index-editor',
title: '【' + tagTitle + '】' + tagTitle + '潮流资讯-YOHO!BUY 有货网',
keywords: tagTitle + ',' + tagTitle + '潮流资讯,' + tagTitle + '文章',
description: '来有货逛潮流,' + tagTitle + '潮流资讯大分享!了解' + tagTitle + '潮流趋势,掌握' + tagTitle + '潮流文化知识信息,尽在有货逛潮流。'
};
let param = {
tag: req.query.query,
isApp: req.query.app_version || req.query.appVersion || false,
gender: req.query.gender || '1,3',
uid: uid,
udid: req.cookies.udid,
type: req.query.type || 0,
path: req.path
};
responseData.pageHeader.navTitle = param.tag || '标签';
req.ctx(IndexModel).getTagEditor(param).then(result => {
res.render('index/list', Object.assign(responseData, result, {
localCss: true
}));
}).catch(next);
};
/**
* 列表页(列表首页、标签列表页、作者列表页)动态数据,如:查看数,点赞数,评论数,是否点赞,是否回复
* @param req
* @param res
*/
const listDynamicData = (req, res) => {
let uid = req.user.uid || req.query.uid;
let ids = req.query.ids;
let udid = req.cookies.udid;
let other = {};
let query = req.query.query,
type = req.query.type;
other.uid = uid;
if (query) {
other.query = query;
}
if (type) {
other.type = type;
}
req.ctx(IndexModel).getDynamicDataByIds(ids, udid, other).then(ret => {
res.send(ret);
});
};
/**
* 详情页动态数据,如:评论数,回复数,是否点赞,是否收藏
* @param req
* @param res
*/
const detailDynamicData = (req, res) => {
let id = req.query.id,
uid = req.user.uid || req.query.uid,
udid = req.cookies.udid;
req.ctx(IndexModel).getDynamicDataById(id, uid, udid).then((ret) => {
res.status(200).send(ret);
}).catch(() => {
res.status(400);
});
};
module.exports = {
editor,
pageData,
index,
tag,
listDynamicData,
detailDynamicData,
editorRedirect
};