global.js
3.94 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
'use strict';
const headerModel = require('../../../doraemon/models/header');
const model = require('../models/global');
const _ = require('lodash');
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: 24,
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
}));
}
Promise.all(arrs).then((result) => {
let t = (result[1] || {}).brand_name || title;
param.title = t;
res.render('global/list', {
title: `${t}| ${t}全球购 |正品保证, YOHO!BUY 有货`,
keywords: `${t},${t}全球购,${t}正品`,
description: `有货网${t}全球购销售${t}正品商品,100%质量保证,支持货到付款,想了解${t}价格、图片、评价等信息,就上YOHO!BUY 有货中国最大的潮流商品购物网站!`, // eslint-disable-line
module: 'product',
page: 'global-list',
pageHeader: headerModel.setNav({
navTitle: t
}),
list: result[0].list,
filter: result[0].filter,
pageFooter: true,
localCss: true,
appPath: `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.globalpurchase","params":${JSON.stringify(param)}}`
});
}).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);
};
const detail = (req, res, next) => {
let skn = req.params[0];
let params = {
product_skn: skn,
uid: req.user.uid || 0
};
model.detail(params).then((result) => {
let appParams = {
skn: skn
};
let appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.globalpurchase","params":${JSON.stringify(appParams)}}`;
res.render('global/detail', {
title: (_.get(result, 'brand_info.brand_name', '') ? '【' + result.brand_info.brand_name + '】' : '') +
_.get(result, 'product_name', '') + '|YOHO!BUY 有货',
keywords: _.get(result, 'brand_info.brand_name', '') + ',' + _.get(result, 'brand_info.brand_name', '') +
'价格,' + _.get(result, 'brand_info.brand_name', '') + '图片,',
description: _.get(result, 'product_name', '') + ' 有货网仅售' + _.get(result, 'sales_price', '') + '元,购买' +
_.get(result, 'brand_info.brand_name', '') + ',了解' + _.get(result, 'brand_info.brand_name', '') +
'商品信息就上有货网!',
module: 'product',
page: 'global-detail',
pageHeader: headerModel.setNav({
navTitle: '商品详情'
}),
result: result,
cartUrl: '//m.yohobuy.com/cart/index/index',
pageFooter: true,
localCss: true,
appPath: appPath
});
}).catch(next);
};
const gethtml = (req, res, next) => {
let skn = req.query.skn;
if (!skn) {
return next();
}
let params = {
product_skn: skn,
uid: req.user.uid || 0
};
model.gethtml(params).then((html) => {
res.send(html);
}).catch(next);
};
module.exports = {
list,
search,
detail,
gethtml
};