Showing
35 changed files
with
196 additions
and
131 deletions
@@ -7,7 +7,6 @@ | @@ -7,7 +7,6 @@ | ||
7 | 7 | ||
8 | const config = require('./config/common'); | 8 | const config = require('./config/common'); |
9 | 9 | ||
10 | - | ||
11 | // use one apm | 10 | // use one apm |
12 | if (config.useOneapm) { | 11 | if (config.useOneapm) { |
13 | require('oneapm'); | 12 | require('oneapm'); |
@@ -20,16 +19,12 @@ const cookieParser = require('cookie-parser'); | @@ -20,16 +19,12 @@ const cookieParser = require('cookie-parser'); | ||
20 | const favicon = require('serve-favicon'); | 19 | const favicon = require('serve-favicon'); |
21 | const session = require('express-session'); | 20 | const session = require('express-session'); |
22 | const memcached = require('connect-memcached'); | 21 | const memcached = require('connect-memcached'); |
23 | -const _ = require('lodash'); | 22 | +const hbs = require('express-handlebars'); |
24 | const pkg = require('./package.json'); | 23 | const pkg = require('./package.json'); |
25 | -const cookie = require('./library/cookie'); | ||
26 | 24 | ||
27 | const app = express(); | 25 | const app = express(); |
28 | const MemcachedStore = memcached(session); | 26 | const MemcachedStore = memcached(session); |
29 | 27 | ||
30 | -const setChannel = require('./doraemon/middleware/set-channel'); | ||
31 | - | ||
32 | - | ||
33 | // 向模板注入变量 | 28 | // 向模板注入变量 |
34 | app.locals.devEnv = app.get('env') === 'development'; | 29 | app.locals.devEnv = app.get('env') === 'development'; |
35 | app.locals.version = pkg.version; | 30 | app.locals.version = pkg.version; |
@@ -37,8 +32,15 @@ app.locals.version = pkg.version; | @@ -37,8 +32,15 @@ app.locals.version = pkg.version; | ||
37 | // 指定libray目录 | 32 | // 指定libray目录 |
38 | global.library = path.resolve('./library/'); | 33 | global.library = path.resolve('./library/'); |
39 | 34 | ||
40 | - | ||
41 | app.set('view engine', '.hbs'); | 35 | app.set('view engine', '.hbs'); |
36 | +app.set('views', './doraemon/views'); | ||
37 | +app.engine('.hbs', hbs({ | ||
38 | + extname: '.hbs', | ||
39 | + defaultLayout: 'layout', | ||
40 | + layoutsDir: './doraemon/views', | ||
41 | + partialsDir: './doraemon/views/partial', | ||
42 | + helpers: require(`${global.library}/helpers`) | ||
43 | +})); | ||
42 | 44 | ||
43 | app.use(favicon(path.join(__dirname, '/public/favicon.ico'))); | 45 | app.use(favicon(path.join(__dirname, '/public/favicon.ico'))); |
44 | app.use(express.static(path.join(__dirname, 'public'))); | 46 | app.use(express.static(path.join(__dirname, 'public'))); |
@@ -65,35 +67,35 @@ app.use(session({ | @@ -65,35 +67,35 @@ app.use(session({ | ||
65 | }) | 67 | }) |
66 | })); | 68 | })); |
67 | 69 | ||
68 | - | ||
69 | -// req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等 | ||
70 | app.use((req, res, next) => { | 70 | app.use((req, res, next) => { |
71 | - req.yoho = {}; | ||
72 | - res.yoho = {}; | ||
73 | - next(); | ||
74 | -}); | 71 | + req.user = {}; // 全局的用户数据 |
72 | + req.yoho = {}; // req和res绑定yoho对象,用于传递全局数据, 如req.yoho.channel等 | ||
75 | 73 | ||
76 | -app.use((req, res, next) => { | ||
77 | - req.user = {}; | ||
78 | - | ||
79 | - // 从 PHP 写的 SESSION 中获取到当前登录用户的 UID | ||
80 | - if (req.session && _.isNumber(req.session._LOGIN_UID)) { | ||
81 | - req.user.uid = req.session._LOGIN_UID; | ||
82 | - } | ||
83 | - | ||
84 | - // session 没有读取到的时候,从 cookie 读取 UID | ||
85 | - if (!req.user.uid && req.cookies._UID) { | ||
86 | - req.user.uid = cookie.getUid(req); | ||
87 | - } | ||
88 | next(); | 74 | next(); |
89 | }); | 75 | }); |
90 | 76 | ||
77 | +const logger = require('./library/logger'); | ||
78 | +const user = require('./doraemon/middleware/user'); | ||
79 | +const setChannel = require('./doraemon/middleware/set-channel'); | ||
80 | +const errorHanlder = require('./doraemon/middleware/error-hanlder'); | ||
81 | + | ||
82 | +// YOHO 前置中间件 | ||
83 | +app.use(user()); | ||
91 | app.use(setChannel()); | 84 | app.use(setChannel()); |
92 | 85 | ||
93 | // dispatcher | 86 | // dispatcher |
94 | -require('./dispatch')(app); | 87 | +try { |
88 | + require('./dispatch')(app); | ||
89 | + | ||
90 | + app.all('*', errorHanlder.notFound()); // 404 | ||
91 | + | ||
92 | + // YOHO 后置中间件 | ||
93 | + app.use(errorHanlder.serverError()); | ||
94 | +} catch (err) { | ||
95 | + logger.error(err); | ||
96 | +} | ||
95 | 97 | ||
96 | // listener | 98 | // listener |
97 | app.listen(config.port, function() { | 99 | app.listen(config.port, function() { |
98 | - console.log('yohobuy start'); | 100 | + logger.info('yohobuy start'); |
99 | }); | 101 | }); |
@@ -23,13 +23,12 @@ const contentCode = { | @@ -23,13 +23,12 @@ const contentCode = { | ||
23 | special: '89cc20483ee2cbc8a716dcfe2b6c7603' | 23 | special: '89cc20483ee2cbc8a716dcfe2b6c7603' |
24 | }; | 24 | }; |
25 | 25 | ||
26 | -class Star { | ||
27 | - /** | 26 | +/** |
28 | * 获取资源位数据 | 27 | * 获取资源位数据 |
29 | * @param {[string]} page | 28 | * @param {[string]} page |
30 | * @return {[array]} | 29 | * @return {[array]} |
31 | */ | 30 | */ |
32 | - static getResources(page) { | 31 | +const _getResources = (page) => { |
33 | return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({ | 32 | return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({ |
34 | content_code: contentCode[page] | 33 | content_code: contentCode[page] |
35 | })).then((result) => { | 34 | })).then((result) => { |
@@ -40,14 +39,14 @@ class Star { | @@ -40,14 +39,14 @@ class Star { | ||
40 | return []; | 39 | return []; |
41 | } | 40 | } |
42 | }); | 41 | }); |
43 | - } | 42 | +}; |
44 | 43 | ||
45 | - /** | 44 | +/** |
46 | * 星潮教室首页数据处理 | 45 | * 星潮教室首页数据处理 |
47 | * @param {[array]} list | 46 | * @param {[array]} list |
48 | * @return {[array]} | 47 | * @return {[array]} |
49 | */ | 48 | */ |
50 | - static processIndexData(list) { | 49 | +const _processIndexData = (list) => { |
51 | const formatData = { | 50 | const formatData = { |
52 | ads: [], | 51 | ads: [], |
53 | starAvatar: [], | 52 | starAvatar: [], |
@@ -115,18 +114,18 @@ class Star { | @@ -115,18 +114,18 @@ class Star { | ||
115 | } | 114 | } |
116 | 115 | ||
117 | return formatData; | 116 | return formatData; |
118 | - } | 117 | +}; |
119 | 118 | ||
120 | - static processShareUrl(post) { | 119 | +const _processShareUrl = (post) => { |
121 | return `${post.share.url}&openby:yohobuy={"action":"go.share","params":{"pic":"${helpers.image(post.src, 640, 640)}","title":"${post.title}","url":"${post.share.url}","content":"潮流资讯,新鲜贩售,YOHO!Buy有货【逛】不停"}}`; // eslint-disable-line | 120 | return `${post.share.url}&openby:yohobuy={"action":"go.share","params":{"pic":"${helpers.image(post.src, 640, 640)}","title":"${post.title}","url":"${post.share.url}","content":"潮流资讯,新鲜贩售,YOHO!Buy有货【逛】不停"}}`; // eslint-disable-line |
122 | - } | 121 | +}; |
123 | 122 | ||
124 | - /** | 123 | +/** |
125 | * 明星专题列表数据处理 | 124 | * 明星专题列表数据处理 |
126 | * @param {[array]} list | 125 | * @param {[array]} list |
127 | * @return {[array]} | 126 | * @return {[array]} |
128 | */ | 127 | */ |
129 | - static processDetailData(list) { | 128 | +const _processDetailData = (list) => { |
130 | const formatData = []; | 129 | const formatData = []; |
131 | 130 | ||
132 | list = list || []; | 131 | list = list || []; |
@@ -135,19 +134,19 @@ class Star { | @@ -135,19 +134,19 @@ class Star { | ||
135 | _.forEach(list, (data) => { | 134 | _.forEach(list, (data) => { |
136 | data.publishTime = helpers.dateFormat('MM月DD日 hh:mm', data.publishTime); | 135 | data.publishTime = helpers.dateFormat('MM月DD日 hh:mm', data.publishTime); |
137 | if (data.share && data.share.url) { | 136 | if (data.share && data.share.url) { |
138 | - data.share.url = Star.processShareUrl(data); | 137 | + data.share.url = _processShareUrl(data); |
139 | } | 138 | } |
140 | formatData.push(data); | 139 | formatData.push(data); |
141 | }); | 140 | }); |
142 | 141 | ||
143 | return formatData; | 142 | return formatData; |
144 | - } | 143 | +}; |
145 | 144 | ||
146 | 145 | ||
147 | - /** | 146 | +/** |
148 | * 星搭配文章列表数据处理 | 147 | * 星搭配文章列表数据处理 |
149 | */ | 148 | */ |
150 | - static processCollocationData(list) { | 149 | +const _processCollocationData = (list) => { |
151 | const formatData = []; | 150 | const formatData = []; |
152 | 151 | ||
153 | list = list || []; | 152 | list = list || []; |
@@ -163,29 +162,29 @@ class Star { | @@ -163,29 +162,29 @@ class Star { | ||
163 | }); | 162 | }); |
164 | 163 | ||
165 | return formatData; | 164 | return formatData; |
166 | - } | 165 | +}; |
167 | 166 | ||
168 | - /** | 167 | +/** |
169 | * 星潮首页 | 168 | * 星潮首页 |
170 | */ | 169 | */ |
171 | - static getIndexData() { | 170 | +const getIndexData = () => { |
172 | return api.get('', sign.apiSign({ | 171 | return api.get('', sign.apiSign({ |
173 | method: 'app.starClass.index', | 172 | method: 'app.starClass.index', |
174 | code: '8adc27fcf5676f356602889afcfd2a8e' | 173 | code: '8adc27fcf5676f356602889afcfd2a8e' |
175 | })).then((result) => { | 174 | })).then((result) => { |
176 | if (result && result.code === 200) { | 175 | if (result && result.code === 200) { |
177 | - return Star.processIndexData(result.data); | 176 | + return _processIndexData(result.data); |
178 | } else { | 177 | } else { |
179 | logger.error('星潮教室首页数据返回 code 不是 200'); | 178 | logger.error('星潮教室首页数据返回 code 不是 200'); |
180 | return {}; | 179 | return {}; |
181 | } | 180 | } |
182 | }); | 181 | }); |
183 | - } | 182 | +}; |
184 | 183 | ||
185 | - /** | 184 | +/** |
186 | * 明星专题 | 185 | * 明星专题 |
187 | */ | 186 | */ |
188 | - static getDetailData(params) { | 187 | +const getDetailData = (params) => { |
189 | return api.get('', sign.apiSign({ | 188 | return api.get('', sign.apiSign({ |
190 | method: 'app.starClass.lastTagArticle', | 189 | method: 'app.starClass.lastTagArticle', |
191 | tag: params.tag, | 190 | tag: params.tag, |
@@ -196,21 +195,21 @@ class Star { | @@ -196,21 +195,21 @@ class Star { | ||
196 | if (params.page > result.data.totalPage) { | 195 | if (params.page > result.data.totalPage) { |
197 | return ''; | 196 | return ''; |
198 | } else { | 197 | } else { |
199 | - return Star.processDetailData(result.data.list); | 198 | + return _processDetailData(result.data.list); |
200 | } | 199 | } |
201 | } else { | 200 | } else { |
202 | logger.error('明星专题文章数据返回 code 不是 200'); | 201 | logger.error('明星专题文章数据返回 code 不是 200'); |
203 | return []; | 202 | return []; |
204 | } | 203 | } |
205 | }); | 204 | }); |
206 | - } | 205 | +}; |
207 | 206 | ||
208 | 207 | ||
209 | - /** | 208 | +/** |
210 | * 星专题 | 209 | * 星专题 |
211 | */ | 210 | */ |
212 | - static getSpecialData() { | ||
213 | - return Star.getResources('special').then((result) => { | 211 | +const getSpecialData = () => { |
212 | + return _getResources('special').then((result) => { | ||
214 | 213 | ||
215 | // 数据结构嵌套太深 | 214 | // 数据结构嵌套太深 |
216 | _.forEach(result, (data) => { | 215 | _.forEach(result, (data) => { |
@@ -224,27 +223,27 @@ class Star { | @@ -224,27 +223,27 @@ class Star { | ||
224 | }); | 223 | }); |
225 | return result; | 224 | return result; |
226 | }); | 225 | }); |
227 | - } | 226 | +}; |
228 | 227 | ||
229 | - /** | 228 | +/** |
230 | * 星搭配 | 229 | * 星搭配 |
231 | */ | 230 | */ |
232 | - static getCollocationListData(params, uid) { | 231 | +const getCollocationListData = (params, uid) => { |
233 | 232 | ||
234 | return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', sign.apiSign(Object.assign({ | 233 | return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', sign.apiSign(Object.assign({ |
235 | limit: '20', | 234 | limit: '20', |
236 | uid: uid | 235 | uid: uid |
237 | }, params))).then((result) => { | 236 | }, params))).then((result) => { |
238 | if (result && result.code === 200) { | 237 | if (result && result.code === 200) { |
239 | - return Star.processCollocationData(result.data.list.artList); | 238 | + return _processCollocationData(result.data.list.artList); |
240 | } else { | 239 | } else { |
241 | logger.error('获取星搭配文章列表返回 code 不是 200'); | 240 | logger.error('获取星搭配文章列表返回 code 不是 200'); |
242 | return []; | 241 | return []; |
243 | } | 242 | } |
244 | }); | 243 | }); |
245 | - } | 244 | +}; |
246 | 245 | ||
247 | - static setFavorite(params, uid) { | 246 | +const setFavorite = (params, uid) => { |
248 | if (!uid) { | 247 | if (!uid) { |
249 | return Promise.resolve({ | 248 | return Promise.resolve({ |
250 | code: 401, | 249 | code: 401, |
@@ -258,7 +257,12 @@ class Star { | @@ -258,7 +257,12 @@ class Star { | ||
258 | article_id: params.articleId, | 257 | article_id: params.articleId, |
259 | uid: uid | 258 | uid: uid |
260 | })); | 259 | })); |
261 | - } | ||
262 | -} | 260 | +}; |
263 | 261 | ||
264 | -module.exports = Star; | 262 | +module.exports = { |
263 | + getIndexData: getIndexData, | ||
264 | + getSpecialData: getSpecialData, | ||
265 | + getCollocationListData: getCollocationListData, | ||
266 | + setFavorite: setFavorite, | ||
267 | + getDetailData: getDetailData | ||
268 | +}; |
@@ -69,14 +69,12 @@ const contentCode = { | @@ -69,14 +69,12 @@ const contentCode = { | ||
69 | } | 69 | } |
70 | }; | 70 | }; |
71 | 71 | ||
72 | -class Sale { | ||
73 | - | ||
74 | - /** | 72 | +/** |
75 | * 折扣专场列表数据处理 | 73 | * 折扣专场列表数据处理 |
76 | * @param {[array]} list | 74 | * @param {[array]} list |
77 | * @return {[array]} | 75 | * @return {[array]} |
78 | */ | 76 | */ |
79 | - static processDiscount(list, channel) { | 77 | +const _processDiscount = (list, channel) => { |
80 | const formatData = []; | 78 | const formatData = []; |
81 | let flag = true; | 79 | let flag = true; |
82 | 80 | ||
@@ -97,14 +95,14 @@ class Sale { | @@ -97,14 +95,14 @@ class Sale { | ||
97 | }); | 95 | }); |
98 | 96 | ||
99 | return formatData; | 97 | return formatData; |
100 | - } | 98 | +}; |
101 | 99 | ||
102 | - /** | 100 | +/** |
103 | * 折扣专场接口调用 | 101 | * 折扣专场接口调用 |
104 | * @param {[object]} params | 102 | * @param {[object]} params |
105 | * @return {[array]} | 103 | * @return {[array]} |
106 | */ | 104 | */ |
107 | - static discount(params) { | 105 | +const _discount = (params) => { |
108 | params = params || {}; | 106 | params = params || {}; |
109 | 107 | ||
110 | return api.get('', sign.apiSign(Object.assign({ | 108 | return api.get('', sign.apiSign(Object.assign({ |
@@ -112,14 +110,14 @@ class Sale { | @@ -112,14 +110,14 @@ class Sale { | ||
112 | sort: 2, | 110 | sort: 2, |
113 | plateform: 2 | 111 | plateform: 2 |
114 | }, params))); | 112 | }, params))); |
115 | - } | 113 | +}; |
116 | 114 | ||
117 | - /** | 115 | +/** |
118 | * 断码区分类数据处理 | 116 | * 断码区分类数据处理 |
119 | * @param {[array]} list | 117 | * @param {[array]} list |
120 | * @return {[array]} | 118 | * @return {[array]} |
121 | */ | 119 | */ |
122 | - static processBreakingSort(list) { | 120 | +const _processBreakingSort = (list) => { |
123 | const formatData = {}; | 121 | const formatData = {}; |
124 | const sort = []; | 122 | const sort = []; |
125 | const sub = []; | 123 | const sub = []; |
@@ -148,14 +146,14 @@ class Sale { | @@ -148,14 +146,14 @@ class Sale { | ||
148 | formatData.sub = sub; | 146 | formatData.sub = sub; |
149 | 147 | ||
150 | return formatData; | 148 | return formatData; |
151 | - } | 149 | +}; |
152 | 150 | ||
153 | - /** | 151 | +/** |
154 | * 商品搜索接口请求 | 152 | * 商品搜索接口请求 |
155 | * @param {[object]} params | 153 | * @param {[object]} params |
156 | * @return {[array]} | 154 | * @return {[array]} |
157 | */ | 155 | */ |
158 | - static searchSales(params) { | 156 | +const _searchSales = (params) => { |
159 | 157 | ||
160 | let method = 'app.search.sales'; | 158 | let method = 'app.search.sales'; |
161 | 159 | ||
@@ -183,14 +181,14 @@ class Sale { | @@ -183,14 +181,14 @@ class Sale { | ||
183 | return api.get('', sign.apiSign(Object.assign({ | 181 | return api.get('', sign.apiSign(Object.assign({ |
184 | method: method | 182 | method: method |
185 | }, params)), true); | 183 | }, params)), true); |
186 | - } | 184 | +}; |
187 | 185 | ||
188 | - /** | 186 | +/** |
189 | * 获取用户数据信息 | 187 | * 获取用户数据信息 |
190 | * @param {[string]} uid | 188 | * @param {[string]} uid |
191 | * @return {[array]} | 189 | * @return {[array]} |
192 | */ | 190 | */ |
193 | - static getUserProfile(uid) { | 191 | +const _getUserProfile = (uid) => { |
194 | if (!uid) { | 192 | if (!uid) { |
195 | return Promise.resolve({ | 193 | return Promise.resolve({ |
196 | code: 200, | 194 | code: 200, |
@@ -201,14 +199,14 @@ class Sale { | @@ -201,14 +199,14 @@ class Sale { | ||
201 | method: 'app.passport.profile', | 199 | method: 'app.passport.profile', |
202 | uid: uid | 200 | uid: uid |
203 | }), true); | 201 | }), true); |
204 | - } | 202 | +}; |
205 | 203 | ||
206 | - /** | 204 | +/** |
207 | * 获取资源位数据 | 205 | * 获取资源位数据 |
208 | * @param {[string]} page | 206 | * @param {[string]} page |
209 | * @return {[array]} | 207 | * @return {[array]} |
210 | */ | 208 | */ |
211 | - static getResources(page, channel) { | 209 | +const _getResources = (page, channel) => { |
212 | return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({ | 210 | return serviceAPI.get('operations/api/v5/resource/get', sign.apiSign({ |
213 | content_code: contentCode[channel][page] | 211 | content_code: contentCode[channel][page] |
214 | })).then((result) => { | 212 | })).then((result) => { |
@@ -219,33 +217,33 @@ class Sale { | @@ -219,33 +217,33 @@ class Sale { | ||
219 | return []; | 217 | return []; |
220 | } | 218 | } |
221 | }); | 219 | }); |
222 | - } | 220 | +}; |
223 | 221 | ||
224 | - /** | 222 | +/** |
225 | * 获取断码区分类数据 | 223 | * 获取断码区分类数据 |
226 | * @param {[string]} yhChannel | 224 | * @param {[string]} yhChannel |
227 | * @return {[object]} | 225 | * @return {[object]} |
228 | */ | 226 | */ |
229 | - static getBreakingSort(yhChannel) { | 227 | +const _getBreakingSort = (yhChannel) => { |
230 | return api.get('', sign.apiSign({ | 228 | return api.get('', sign.apiSign({ |
231 | method: 'app.sale.getBreakingSort', | 229 | method: 'app.sale.getBreakingSort', |
232 | yh_channel: channelType[yhChannel] || '1' | 230 | yh_channel: channelType[yhChannel] || '1' |
233 | })).then((result) => { | 231 | })).then((result) => { |
234 | if (result && result.code === 200) { | 232 | if (result && result.code === 200) { |
235 | - return Sale.processBreakingSort(result.data); | 233 | + return _processBreakingSort(result.data); |
236 | } else { | 234 | } else { |
237 | logger.error('断码区分类接口返回 code 不是 200'); | 235 | logger.error('断码区分类接口返回 code 不是 200'); |
238 | return {}; | 236 | return {}; |
239 | } | 237 | } |
240 | }); | 238 | }); |
241 | - } | 239 | +}; |
242 | 240 | ||
243 | - /** | 241 | +/** |
244 | * 获取商品数据 | 242 | * 获取商品数据 |
245 | */ | 243 | */ |
246 | - static getSearchData(params, uid) { | 244 | +const getSearchData = (params, uid) => { |
247 | return Promise.all([ | 245 | return Promise.all([ |
248 | - Sale.searchSales(params).then((result) => { | 246 | + _searchSales(params).then((result) => { |
249 | if (result && result.code === 200) { | 247 | if (result && result.code === 200) { |
250 | return productProcess.processProductList(result.data.product_list || [], { | 248 | return productProcess.processProductList(result.data.product_list || [], { |
251 | yh_channel: params.yh_channel, | 249 | yh_channel: params.yh_channel, |
@@ -256,7 +254,7 @@ class Sale { | @@ -256,7 +254,7 @@ class Sale { | ||
256 | return []; | 254 | return []; |
257 | } | 255 | } |
258 | }), | 256 | }), |
259 | - Sale.getUserProfile(uid).then((result) => { | 257 | + _getUserProfile(uid).then((result) => { |
260 | if (result && result.code === 200) { | 258 | if (result && result.code === 200) { |
261 | return result.data.vip_info ? camelCase(result.data.vip_info) : {}; | 259 | return result.data.vip_info ? camelCase(result.data.vip_info) : {}; |
262 | } else { | 260 | } else { |
@@ -265,15 +263,15 @@ class Sale { | @@ -265,15 +263,15 @@ class Sale { | ||
265 | } | 263 | } |
266 | }) | 264 | }) |
267 | ]); | 265 | ]); |
268 | - } | 266 | +}; |
269 | 267 | ||
270 | - /** | 268 | +/** |
271 | * 获取筛选数据 | 269 | * 获取筛选数据 |
272 | * @param {[object]} params | 270 | * @param {[object]} params |
273 | * @return {[array]} | 271 | * @return {[array]} |
274 | */ | 272 | */ |
275 | - static getFilterData(params) { | ||
276 | - return Sale.searchSales(params).then((result) => { | 273 | +const getFilterData = (params) => { |
274 | + return _searchSales(params).then((result) => { | ||
277 | if (result && result.code === 200) { | 275 | if (result && result.code === 200) { |
278 | return productProcess.processFilter(result.data.filter || [], { | 276 | return productProcess.processFilter(result.data.filter || [], { |
279 | hideSize: params.saleType === '1', | 277 | hideSize: params.saleType === '1', |
@@ -284,78 +282,78 @@ class Sale { | @@ -284,78 +282,78 @@ class Sale { | ||
284 | return []; | 282 | return []; |
285 | } | 283 | } |
286 | }); | 284 | }); |
287 | - } | 285 | +}; |
288 | 286 | ||
289 | - /** | 287 | +/** |
290 | * 获取sale首页数据 | 288 | * 获取sale首页数据 |
291 | * @return {[array]} | 289 | * @return {[array]} |
292 | */ | 290 | */ |
293 | - static getSaleData(channel) { | ||
294 | - return Sale.getResources('sale', channel); | ||
295 | - } | 291 | +const getSaleData = (channel) => { |
292 | + return _getResources('sale', channel); | ||
293 | +}; | ||
296 | 294 | ||
297 | 295 | ||
298 | - /** | 296 | +/** |
299 | * 获取会员享数据 | 297 | * 获取会员享数据 |
300 | * @return {[array]} | 298 | * @return {[array]} |
301 | */ | 299 | */ |
302 | - static getVipData(channel) { | ||
303 | - return Sale.getResources('vip', channel); | ||
304 | - } | 300 | +const getVipData = (channel) => { |
301 | + return _getResources('vip', channel); | ||
302 | +}; | ||
305 | 303 | ||
306 | 304 | ||
307 | - /** | 305 | +/** |
308 | * 获取断码区数据 | 306 | * 获取断码区数据 |
309 | * @param {[object]} params | 307 | * @param {[object]} params |
310 | * @return {[object]} | 308 | * @return {[object]} |
311 | */ | 309 | */ |
312 | - static getBreakCodeData(params) { | 310 | +const getBreakCodeData = (params) => { |
313 | params = params || {}; | 311 | params = params || {}; |
314 | - return Promise.all([Sale.getResources('breakCode', params.yhChannel), Sale.getBreakingSort(params.yhChannel)]) | 312 | + return Promise.all([_getResources('breakCode', params.yhChannel), _getBreakingSort(params.yhChannel)]) |
315 | .then((result) => { | 313 | .then((result) => { |
316 | return { | 314 | return { |
317 | content: result[0], | 315 | content: result[0], |
318 | nav: result[1] | 316 | nav: result[1] |
319 | }; | 317 | }; |
320 | }); | 318 | }); |
321 | - } | 319 | +}; |
322 | 320 | ||
323 | - /** | 321 | +/** |
324 | * 获取折扣专场专题列表数据 | 322 | * 获取折扣专场专题列表数据 |
325 | * @param {[object]} params | 323 | * @param {[object]} params |
326 | * @return {[object]} | 324 | * @return {[object]} |
327 | */ | 325 | */ |
328 | - static getDiscountData(yhChannel) { | 326 | +const getDiscountData = (yhChannel) => { |
329 | const discountData = {}; | 327 | const discountData = {}; |
330 | 328 | ||
331 | - return Sale.discount({ | 329 | + return _discount({ |
332 | yh_channel: channelType[yhChannel] || '1' | 330 | yh_channel: channelType[yhChannel] || '1' |
333 | }).then((result) => { | 331 | }).then((result) => { |
334 | if (result && result.code === 200) { | 332 | if (result && result.code === 200) { |
335 | - discountData.data = Sale.processDiscount(result.data, yhChannel); | 333 | + discountData.data = _processDiscount(result.data, yhChannel); |
336 | return discountData; | 334 | return discountData; |
337 | } else { | 335 | } else { |
338 | logger.error('折扣专场专题列表返回 code 不是 200'); | 336 | logger.error('折扣专场专题列表返回 code 不是 200'); |
339 | return {}; | 337 | return {}; |
340 | } | 338 | } |
341 | }); | 339 | }); |
342 | - } | 340 | +}; |
343 | 341 | ||
344 | - /** | 342 | +/** |
345 | * 获取折扣专场专题详情数据 | 343 | * 获取折扣专场专题详情数据 |
346 | * @param {[string]} id | 344 | * @param {[string]} id |
347 | * @return {[object]} | 345 | * @return {[object]} |
348 | */ | 346 | */ |
349 | - static getDiscountDetailData(id, yhChannel) { | 347 | +const getDiscountDetailData = (id, yhChannel) => { |
350 | let res = {}; | 348 | let res = {}; |
351 | let param = { | 349 | let param = { |
352 | id: id, | 350 | id: id, |
353 | yh_channel: channelType[yhChannel] || '1' | 351 | yh_channel: channelType[yhChannel] || '1' |
354 | }; | 352 | }; |
355 | 353 | ||
356 | - return Sale.discount(param).then((result) => { | 354 | + return _discount(param).then((result) => { |
357 | if (result && result.code === 200) { | 355 | if (result && result.code === 200) { |
358 | - res = Sale.processDiscount(result.data); | 356 | + res = _processDiscount(result.data); |
359 | 357 | ||
360 | return { | 358 | return { |
361 | title: res[0].title, | 359 | title: res[0].title, |
@@ -370,7 +368,14 @@ class Sale { | @@ -370,7 +368,14 @@ class Sale { | ||
370 | return {}; | 368 | return {}; |
371 | } | 369 | } |
372 | }); | 370 | }); |
373 | - } | ||
374 | -} | 371 | +}; |
375 | 372 | ||
376 | -module.exports = Sale; | 373 | +module.exports = { |
374 | + getSaleData: getSaleData, | ||
375 | + getBreakCodeData: getBreakCodeData, | ||
376 | + getDiscountData: getDiscountData, | ||
377 | + getDiscountDetailData: getDiscountDetailData, | ||
378 | + getVipData: getVipData, | ||
379 | + getFilterData: getFilterData, | ||
380 | + getSearchData: getSearchData | ||
381 | +}; |
doraemon/middleware/error-hanlder.js
0 → 100644
1 | +/** | ||
2 | + * 404 错误 | ||
3 | + * @return {[type]} | ||
4 | + */ | ||
5 | +exports.notFound = () => { | ||
6 | + return (req, res) => { | ||
7 | + if (req.xhr) { | ||
8 | + return res.status(404).json({ | ||
9 | + code: 404, | ||
10 | + message: '页面不存在' | ||
11 | + }); | ||
12 | + } | ||
13 | + return res.render('error/404'); | ||
14 | + }; | ||
15 | +}; | ||
16 | + | ||
17 | +/** | ||
18 | + * 服务器错误 | ||
19 | + * @return {[type]} | ||
20 | + */ | ||
21 | +exports.serverError = () => { | ||
22 | + return (err, req, res, next) => { | ||
23 | + if (!res.headersSent) { | ||
24 | + if (req.xhr) { | ||
25 | + return res.status(500).json({ | ||
26 | + code: 500, | ||
27 | + message: '服务器错误' | ||
28 | + }); | ||
29 | + } | ||
30 | + | ||
31 | + return res.render('error/500', err); | ||
32 | + } | ||
33 | + next(err); | ||
34 | + }; | ||
35 | +}; |
doraemon/middleware/user.js
0 → 100644
1 | +const _ = require('lodash'); | ||
2 | +const cookie = require('../../library/cookie'); | ||
3 | + | ||
4 | +module.exports = () => { | ||
5 | + return (req, res, next) => { | ||
6 | + // 从 SESSION 中获取到当前登录用户的 UID | ||
7 | + if (req.session && _.isNumber(req.session._LOGIN_UID)) { | ||
8 | + req.user.uid = req.session._LOGIN_UID; | ||
9 | + } | ||
10 | + | ||
11 | + // session 没有读取到的时候,从 cookie 读取 UID | ||
12 | + if (!req.user.uid && req.cookies._UID) { | ||
13 | + req.user.uid = cookie.getUid(req); | ||
14 | + } | ||
15 | + | ||
16 | + next(); | ||
17 | + }; | ||
18 | +}; |
doraemon/views/error/404.hbs
0 → 100644
1 | +404 |
doraemon/views/error/500.hbs
0 → 100644
1 | +500 |
@@ -9,14 +9,14 @@ | @@ -9,14 +9,14 @@ | ||
9 | }, | 9 | }, |
10 | "scripts": { | 10 | "scripts": { |
11 | "start": "node app.js", | 11 | "start": "node app.js", |
12 | - "dev": "node_modules/.bin/nodemon -e js,hbs -i public/ app.js", | 12 | + "dev": "nodemon -e js,hbs -i public/ app.js", |
13 | "online": "NODE_ENV=\"production\" node app.js", | 13 | "online": "NODE_ENV=\"production\" node app.js", |
14 | - "debug": "DEBUG=\"express:*\" node_modules/.bin/nodemon -e js,hbs -i public/ app.js", | ||
15 | - "lint-js": "./node_modules/.bin/eslint -c .eslintrc --cache --fix .", | ||
16 | - "lint-css": "./node_modules/.bin/stylelint --config .stylelintrc public/scss/**/*.css", | 14 | + "debug": "DEBUG=\"express:*\" nodemon -e js,hbs -i public/ app.js", |
15 | + "lint-js": "eslint -c .eslintrc --cache --fix .", | ||
16 | + "lint-css": "stylelint --config .stylelintrc public/scss/**/*.css", | ||
17 | "precommit": "node lint.js", | 17 | "precommit": "node lint.js", |
18 | - "test": "NODE_ENV=test ./node_modules/.bin/nyc ./node_modules/.bin/ava", | ||
19 | - "posttest": "./node_modules/.bin/nyc report --reporter=html" | 18 | + "test": "NODE_ENV=test nyc ./node_modules/.bin/ava", |
19 | + "posttest": "nyc report --reporter=html" | ||
20 | }, | 20 | }, |
21 | "ava": { | 21 | "ava": { |
22 | "tap": true, | 22 | "tap": true, |
@@ -68,14 +68,13 @@ | @@ -68,14 +68,13 @@ | ||
68 | "gulp-util": "^3.0.7", | 68 | "gulp-util": "^3.0.7", |
69 | "husky": "^0.11.4", | 69 | "husky": "^0.11.4", |
70 | "nodemon": "1.9.2", | 70 | "nodemon": "1.9.2", |
71 | - "nyc": "^6.4.4", | 71 | + "nyc": "^6.6.1", |
72 | "postcss-assets": "^4.0.1", | 72 | "postcss-assets": "^4.0.1", |
73 | "postcss-cachebuster": "^0.1.3", | 73 | "postcss-cachebuster": "^0.1.3", |
74 | "postcss-calc": "^5.2.1", | 74 | "postcss-calc": "^5.2.1", |
75 | "postcss-center": "^1.0.0", | 75 | "postcss-center": "^1.0.0", |
76 | "postcss-clearfix": "^1.0.0", | 76 | "postcss-clearfix": "^1.0.0", |
77 | "postcss-crip": "^2.0.0", | 77 | "postcss-crip": "^2.0.0", |
78 | - "postcss-opacity": "^3.0.0", | ||
79 | "postcss-position": "^0.5.0", | 78 | "postcss-position": "^0.5.0", |
80 | "postcss-pxtorem": "^3.3.1", | 79 | "postcss-pxtorem": "^3.3.1", |
81 | "postcss-short": "^1.4.0", | 80 | "postcss-short": "^1.4.0", |
public/css/index.css
deleted
100644 → 0
This diff could not be displayed because it is too large.
public/css/index.css.map
deleted
100644 → 0
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | &:link, | 9 | &:link, |
10 | &:visited, | 10 | &:visited, |
11 | &:hover, | 11 | &:hover, |
12 | - &:actived { | 12 | + &:active { |
13 | color: #000; | 13 | color: #000; |
14 | } | 14 | } |
15 | } | 15 | } |
@@ -259,7 +259,7 @@ | @@ -259,7 +259,7 @@ | ||
259 | position: relative; | 259 | position: relative; |
260 | } | 260 | } |
261 | 261 | ||
262 | - li:first { | 262 | + li:first-child { |
263 | margin-left: 0; | 263 | margin-left: 0; |
264 | } | 264 | } |
265 | 265 |
-
Please register or login to post a comment