index.js
2.65 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
/**
* girls controller
* @author: 赵彪<bill.zhao@yoho.cn>
* @date: 2016/05/16
*/
'use strict';
const _ = require('lodash');
const channelModel = require('../models/index');
exports.index = (req, res, next) => {
let channelType = req.path.substring(1) || 'boys';
// 将woman转换为girls,以便model层进行处理
channelType === 'woman' ? channelType = 'girls' : null;
channelModel.getContent(channelType).then(data => {
// channel为空不缓存
if (_.isEmpty(data.channel)) {
res.set('Cache-Control', 'no-cache');
}
res.render('channel', data);
}).catch(next);
};
// 日韩馆频道页
exports.japanKorean = (req, res, next) => {
channelModel.getJKContent(req).then(data => {
// channel为空不缓存
if (_.isEmpty(data.channel)) {
res.set('Cache-Control', 'no-cache');
}
res.render('channel', data);
}).catch(next);
};
exports.getbrandFloorDataAjax = (req, res, next) => {
const channelType = req.query.channelType || 'boys',
contentCode = req.query.contentCode || '';
channelModel.getbrandFloorDataAjax(channelType, contentCode).then(data => {
res.json(data);
}).catch(next);
};
exports.getNewArrival = (req, res, next) => {
let reqBody = req.body,
pageIndex = reqBody.pageIndex,
pageCount = reqBody.pageCount,
channel = reqBody.type || req.yoho.channel,
goods = [],
result = {},
isJKChannel = reqBody.mChannel === 'japanKorean' ? true : false,
poolId = reqBody.poolId;
if (pageIndex < 0) {
pageIndex = 0;
}
if (pageCount < 0 || pageCount > 50) {
pageCount = 20;
}
channelModel.getNewArrival(channel, isJKChannel, poolId).then(data => {
goods = _.slice(data, pageIndex, pageIndex + pageCount);
if (goods.length !== 0) {
result = {
code: 200,
goods: goods
};
}
res.send(result);
}).catch(next);
};
exports.getIndexGuide = (req, res, next) => {
channelModel.getIndexGuideData().then(data => {
if (data.code !== 200) {
const err = new Error('异常');
throw err;
}
return channelModel.formatIndexGuideData(data.data);
}).then(data => {
return channelModel.getResourceData(data);
}).then(data => {
let result = {list: data, layout: false};
res.render('guide', result);
}).catch(next);
};
exports.hasNewUserFloor = (req, res, next) => {
channelModel.hasNewUserFloor(req.yoho.channel, req.user.uid).then(data => {
res.send(data);
}).catch(next);
};