plustar.js
4.74 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
157
158
159
160
161
162
163
164
165
166
167
168
/**
* 国际优选
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/09/12
*/
'use strict';
const mRoot = '../models';
const plustarModel = require(`${mRoot}/plustar`);
const htmlProcess = require(`${global.utils}/html-process`);
const headerModel = require('../../../doraemon/models/header'); // 头部model
const _ = require('lodash');
let channels = {
boys: '1,3',
girl: '2,3',
kids: '3,3',
lifestyle: '4'
};
let yhChannel = {
boys: 1,
girl: 2
};
const getListData = (req, res, next) => {
let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || '1,3';
let recom = '4';
let all = '1';
let type = req.query.type;
let channel = req.cookies._Channel && yhChannel[req.cookies._Channel] || 1;
let isRecommend = '0';
let starBrand = '2';
let originalBrand = '3';
if (type === '2') {
plustarModel.getBrandsData(gender, starBrand, originalBrand, channel, isRecommend).then((result) => {
_.forEach(result, r => {
let list = r.list || [];
let head3 = _.take(list, 3);
_.forEach(head3, d => d._noLazy = true);
});
res.render('plustar/list', {
module: 'guang',
page: 'plustar-list',
title: '明星原创',
pageHeader: headerModel.setNav({
navTitle: '明星原创'
}),
pageFooter: true,
ps: result,
localCss: true
});
}).catch(next);
} else {
plustarModel.getListData(gender, recom, all).then((result) => {
_.forEach(result, r => {
let list = r.list || [];
let head3 = _.take(list, 3);
_.forEach(head3, d => d._noLazy = true);
});
res.render('plustar/list', {
module: 'guang',
page: 'plustar-list',
title: '国际优选',
pageHeader: headerModel.setNav({
navTitle: '国际优选'
}),
pageFooter: true,
ps: result,
localCss: true
});
}).catch(next);
}
};
const getDetailData = (req, res, next) => {
let id = req.query.id;
let uid = '';
let udid = req.sessionID || 'yoho';
let gender = req.query.gender || req.cookies._Channel && channels[req.cookies._Channel] || '1,3';
let isApp = req.query.app_version || req.query.appVersion || false;
let clientType = (req.body.client_type || '').toLowerCase();
let userAgent = req.get('User-Agent');
let isWeixin = userAgent.includes('MicroMessenger'); // 标识是否是微信访问
if (isApp) {
if (req.query.uid) {
uid = req.query.uid;
}
} else {
uid = req.user.uid;
}
if (clientType === 'ios' && isApp) {
clientType = 'iphone';
} else if (clientType === 'android' && isApp) {
clientType = 'android';
} else {
clientType = 'h5';
}
plustarModel.getDetailData(id, uid, udid, gender, isApp, clientType).then((result) => {
result.brand_intro = htmlProcess.removeHtml(result.brand_intro);
if (!isApp & !isWeixin) {
res.render('plustar/detail', {
module: 'guang',
page: 'plustar-detail',
title: result.brand_name,
pageHeader: headerModel.setNav({
navTitle: result.brand_name
}),
ps: result,
localCss: true
});
} else {
res.render('plustar/detail', {
module: 'guang',
page: 'plustar-detail',
title: result.brand_name,
ps: result,
uid: uid,
isApp: isApp ? true : false,
localCss: true
});
}
}).catch(next);
};
/**
* [品牌详情异步数据]
*/
const getDetailDataAsync = (req, res, next) => {
let uid;
let udid = req.sessionID || 'yoho';
let clientType = req.body.client_type || '';
let brandId = req.body.brand_id || 0;
let isApp = req.body.isApp || false;
if (isApp) {
if (req.body.uid) {
uid = parseInt(req.body.uid, 10);
}
} else {
uid = parseInt(req.user.uid, 10);
}
if (!brandId) {
return res.json({code: 400, message: '参数错误'});
}
plustarModel.getDetailDataAsync(brandId, uid, udid, clientType, isApp).then((result) => {
res.json({
isLike: result.isLike,
infos: result.infos
});
}).catch(next);
};
module.exports = {
getListData,
getDetailData,
getDetailDataAsync
};