brand.js
2.89 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
/**
* 品牌页
* <jing.li@yoho.cn>
* 2016/09/19
*/
'use strict';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const indexModel = require('../models/brand');
/**
* 品牌一览
*
* @param string gender 老版本中使用的参数, 做兼容判断
* @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
*/
let index = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '品牌一览'
});
let responseData = {
pageHeader: headerData,
module: 'channel',
page: 'brand',
title: '品牌一览 | Yoho!Buy有货 | 潮流购物逛不停',
//pageFooter: true
};
let param = {
channel: req.query.channel || '1',
gender: req.query.gender || '1,3'
};
indexModel.getBrandByChannel(param.channel).then(result => {
res.render('brand/index', Object.assign(responseData, result));
}).catch(next);
};
/**
* 品牌一览搜索页
*
* @param string gender 老版本中使用的参数, 做兼容判断
* @param int channel 1表示男生频道, 2表示女生频道, 3表示潮童频道, 4表示创意生活频道
*/
let search = (req, res, next) => {
let headerData = headerModel.setNav({
navTitle: '品牌一览'
});
let responseData = {
pageHeader: headerData,
module: 'channel',
page: 'brand',
title: '品牌一览 | Yoho!Buy有货 | 潮流购物逛不停',
pageFooter: true
};
let param = {
uid: req.user.uid,
channel: req.query.channel || '1'
};
indexModel.branchSearch(param).then(result => {
res.render('brand/search', Object.assign(responseData, result));
}).catch(next);
};
/**
* 添加品牌搜索记录
*/
let addBrandSearch = (req, res, next) => {
let uid = req.user.uid;
let brandName = req.body.brandName;
let timestamp = Date.parse(new Date());
timestamp = timestamp / 1000;
let records = timestamp + '_' + brandName;
let param = {uid, records};
indexModel.addSearchHistory(param).then((result) => {
res.json(result);
}).catch(next);
};
/**
* 删除品牌搜索记录
*/
let delBrandHistory = (req, res, next) => {
let param = {
uid: req.user.uid,
};
indexModel.delBrandSearchHistory(param).then((result) => {
res.json(result);
}).catch(next);
};
/**
* [品牌搜索异步数据]
*/
let searchAsync = (req, res, next) => {
let uid = req.user.uid;
if (!req.xhr) {
return next();
}
if (!uid) {
return res.json({code: 200, data: {}});
}
return indexModel.branchSearchHistoryAsync(uid).then((result) => {
return res.json({code: 200, data: { history: result }});
});
};
module.exports = {
index,
search,
delBrandHistory,
addBrandSearch,
searchAsync
};