plusstar.js
4.67 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/**
* 潮流优选
* @author: xiaoxiao<xiaoxiao.hao@yoho.cn>
* @date: 2016/08/04
*/
'use strict';
const mRoot = '../models';
const typeLib = require('../../../config/type-lib');
const plusstarModel = require(`${mRoot}/plusstar`);
const headerModel = require('../../../doraemon/models/header'); // 头部model
const _ = require('lodash');
const qs = require('querystring');
let channels = {
boys: 1,
girl: 2,
kids: 3,
lifestyle: 4
};
/**
* 潮流优选首页
*/
exports.index = (req, res, next) => {
let isApp = req.query.app_version || req.query.appVersion || false;
let parameter = {};
let title = '潮流优选';
let gender = req.query.gender ||
req.query.channel && typeLib.channels[req.query.channel] ||
req.cookies._Channel && channels[req.cookies._Channel] ||
1;
if (isApp === false) {
parameter = {
pageHeader: headerModel.setNav({
navTitle: title
}),
pageFooter: true
};
}
let result = {};
switch (gender) {
case typeLib.gender.boys:
gender = 1;
break;
case typeLib.gender.girls:
gender = 2;
break;
case typeLib.gender.kids:
gender = 3;
break;
case typeLib.gender.lifestyle:
gender = 4;
break;
default:
break;
}
// 唤起 APP 的路径
res.locals.appPath = `yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.h5","params":{"url":"http://guang.m.yohobuy.com${req.path}","param":${JSON.stringify(req.query)}}}`;
req.ctx(plusstarModel).getAllChannels({
gender: gender,
app_type: 0
}).then(data => {
result = Object.assign(result, data);
let focus = _.find(result.channel, d => d.focus) || {};
let code = focus.code || '';
return req.ctx(plusstarModel).getResourcesData({
content_code: code,
yh_channel: 1
}, {
isApp: isApp
});
}).then(data => {
result = Object.assign(result, data);
// 此处 channel 需要读取 cookies 的 channel
if (req.cookies._Channel) {
res.locals.pageChannel = {};
res.locals.pageChannel[req.cookies._Channel] = true;
}
res.render('plusstar/index', Object.assign({
page: 'plusstar-index',
result: result,
isApp: isApp,
title: title,
localCss: true
}, parameter));
}).catch(next);
};
// 301到新路由
exports.indexRedirect = (req, res) => {
let param = qs.stringify(req.query);
if (param) {
param = '?' + param;
}
res.redirect(301, `/guang/${req.yoho.channel}-plusstar/${param}`);
};
exports.userSkn = (req, res, next) => {
let isApp = req.body.app_version || req.body.appVersion || false;
let uid = req.user.uid;
let param = {};
let skns = req.body.skns || '';
skns = skns.split(',') || [];
if (uid) {
param.uid = uid;
param.content_code = req.body.code || '';
param.yh_channel = req.body.yh_channel || 1;
req.ctx(plusstarModel).getFashionPrefer(param, {
isApp: isApp
}).then(result => {
let preferSkns = result.data || [];
skns = _.uniq(skns.concat(preferSkns));
res.json(skns);
}).catch(next);
} else {
res.json(skns);
}
};
/**
* 潮流优选首页-资源位
*/
exports.resourcesTemplate = (req, res, next) => {
let isApp = req.query.app_version || req.query.appVersion || false;
let uid = req.user.uid || req.query.uid;
let param = {};
if (uid) {
param.uid = uid;
}
param.content_code = req.query.code || '';
param.yh_channel = req.query.yh_channel || 1;
req.ctx(plusstarModel).getResourcesData(param, {
isApp: isApp
}).then(result => {
res.render('plusstar/resources-template', {
layout: false,
result: result,
title: '潮流优选'
});
}).catch(next);
};
/**
* 潮流优选首页-资源位-商品列表
*/
exports.resourcesGoodsList = (req, res, next) => {
let productSkn = req.body.productSkn || '';
let isApp = req.body.app_version || req.body.appVersion || false;
let param = {};
param = {
productSkn: productSkn.split(',')
};
req.ctx(plusstarModel).getProductBatch(param, {
isApp: isApp,
showSimilar: true
}).then(result => {
res.render('plusstar/resources-goodsList', {
layout: false,
result: result,
title: '潮流优选',
_noLazy: true
});
}).catch(next);
};