global.js
1.64 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
'use strict';
const headerModel = require('../../../doraemon/models/header');
const model = require('../models/global');
const list = (req, res, next) => {
let brand = req.query.brand;
let sort = req.query.sort;
let title = req.query.title;
if (!brand && !sort) {
return res.redirect('//m.yohobuy.com');
}
let param = {
limit: 12,
order: 's_t_desc',
page: 1,
uid: req.user.uid || 0
};
if (brand) {
param.brand = brand;
} else if (sort) {
param.sort = sort;
}
let arrs = [model.list(param)];
if (brand) {
arrs.push(model.getBrand({
brandId: brand,
uid: req.user.uid || 0,
client_type: 'iphone' // todo
}));
}
Promise.all(arrs).then((result) => {
res.render('global/list', {
module: 'product',
page: 'global-list',
pageHeader: headerModel.setNav({
navTitle: (result[1] || {}).brand_name || title
}),
list: result[0].list,
filter: result[0].filter,
pageFooter: true,
});
}).catch(next);
};
const search = (req, res, next) => {
let query = req.query;
if (query.type === 'new') {
query.order = 's_t_desc';
} else if (query.type === 'price') {
query.order = query.order === '1' ? 's_p_asc' : 's_p_desc';
}
model.list(query).then((result) => {
res.render('global/search', {
list: result.list,
layout: false
});
}).catch(next);
};
module.exports = {
list,
search,
detail: function() {
},
};