list.js
3.58 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
/*
* @Author: sefon
* @Date: 2016-07-24 11:40:21
*/
'use strict';
const mRoot = '../models';
const list = require(`${mRoot}/list`);
const helpers = global.yoho.helpers;
// 搜索相关接口
const searchApi = require(`${mRoot}/search-api`);
// 店铺页
const shop = (shopId, uid, res, next) => {
let resData = {};
list.getShopInfo(shopId, uid).then(result => {
console.log(result);
return list.getShopData();
}).then(result =>{
Object.assign(resData, result);
res.render('list/shop-index', resData);
}).catch(next);
};
/**
* 商品分类列表页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.index = (req, res, next) => {
let resData = {};
list.getListData(req.query).then(result => {
Object.assign(resData, result);
res.render('list/index', resData);
}).catch(next);
};
/**
* 新品到着
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.new = (req, res, next) => {
let resData = {};
list.getListNewData(Object.assign({order: 's_t_desc'}, req.query)).then(result => {
Object.assign(resData, result);
res.render('list/index', resData);
}).catch(next);
};
/**
* 品牌页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.brand = (req, res, next) => {
let resData = {};
// shopId存在,直接走店铺
if (req.shopId) {
shop(req.shopId, req.user.id, res, next);
}
let brandDomain = req.brandDomain || 'vans';
// 获取品牌信息
list.getBrandInfo({domain: brandDomain}).then(brandInfo => {
brandInfo.type = 2;
brandInfo.shopId = 702;
switch (brandInfo.type) {
case 1:
// 搜索
res.location(helpers.urlFormat('', {query: brandInfo.brandDomain}, 'search'));
break;
case 2:
// 店铺
shop(brandInfo.shopId, req.user.id, res, next);
break;
default:
// 品牌
return list.getBrandData(req.query, Object.assign({uid: req.user.id}, brandInfo));
// break;
}
}).then(result => {
Object.assign(resData, result);
res.render('list/brand', resData);
}).catch(next);
};
/**
* ajax调用品牌页左侧水牌
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.getNodeContent = (req, res, next) => {
if (!req.xhr || !req.body.node) {
return next();
}
list.getNodeContentData(req.body).then(result => {
res.json(result);
}).catch(next);
};
/**
* ajax调用品牌页左侧series folder
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.getAdnav = (req, res, next) => {
if (!req.xhr || !req.body.brandId) {
return next();
}
list.getAdnav(req.body).then(result => {
res.json(result);
}).catch(next);
};
/**
* 判断用户是否收藏品牌页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.isFavoriteBrand = (req, res, next) => {
if (!req.xhr || !req.body.brandId || req.user.id) {
return next();
}
searchApi.isFavoriteBrand(req.user.id, req.body).then(result => {
res.json(result);
}).catch(next);
};