Showing
7 changed files
with
138 additions
and
9 deletions
apps/mip/controllers/hot.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const css = require('../css'); | ||
4 | +const mRoot = '../models'; | ||
5 | +const listModel = require(`${mRoot}/hot`); | ||
6 | +const co = require('bluebird').coroutine; | ||
7 | + | ||
8 | +exports.index = (req, res, next) => { | ||
9 | + co(function* () { | ||
10 | + let params = { | ||
11 | + page: 1, | ||
12 | + limit: 100, | ||
13 | + sales: 'Y', | ||
14 | + outlets: 2, | ||
15 | + stocknumber: 1, | ||
16 | + need_filter: 'no', | ||
17 | + type: 'default', | ||
18 | + order: 's_t_desc', | ||
19 | + id: req.params.id | ||
20 | + }; | ||
21 | + | ||
22 | + let list = yield req.ctx(listModel).index(params); | ||
23 | + let goodsList = { | ||
24 | + name: list.name || '', | ||
25 | + list: list.list, | ||
26 | + fuzzyWord: list.fuzzyWord | ||
27 | + }; | ||
28 | + | ||
29 | + return res.render('hot', Object.assign({ | ||
30 | + css: yield css('chanpin.css'), | ||
31 | + title: `${goodsList.name}价格_图片_品牌_怎么样-YOHO!BUY有货`, | ||
32 | + mipUrl: `https://m.yohobuy.com${req.originalUrl}`, | ||
33 | + mipFooter: true, | ||
34 | + canonical: { | ||
35 | + currentHref: `https://www.yohobuy.com/hot/${req.params.id}.html` | ||
36 | + } | ||
37 | + }, goodsList)); | ||
38 | + })().catch(next); | ||
39 | +}; |
apps/mip/models/hot.js
0 → 100644
1 | +'use strict'; | ||
2 | + | ||
3 | +const utils = '../../../utils'; | ||
4 | +const redis = require(`${utils}/redis`); | ||
5 | +const _ = require('lodash'); | ||
6 | +const helpers = global.yoho.helpers; | ||
7 | +const camelCase = global.yoho.camelCase; | ||
8 | + | ||
9 | +class Hot extends global.yoho.BaseModel { | ||
10 | + constructor(ctx) { | ||
11 | + super(ctx); | ||
12 | + } | ||
13 | + | ||
14 | + list(params) { | ||
15 | + let options = { | ||
16 | + data: { | ||
17 | + method: 'web.search.forseo', | ||
18 | + sales: params.sales, | ||
19 | + outlets: params.outlets, | ||
20 | + stocknumber: params.stocknumber, | ||
21 | + need_filter: params.need_filter, | ||
22 | + query: params.query, | ||
23 | + type: params.type, | ||
24 | + page: params.page || 1, | ||
25 | + limit: params.limit || 24, | ||
26 | + order: params.order || 0 | ||
27 | + }, | ||
28 | + param: { | ||
29 | + code: 200 | ||
30 | + } | ||
31 | + }; | ||
32 | + | ||
33 | + return this.get(options).then(result => { | ||
34 | + return result; | ||
35 | + }); | ||
36 | + } | ||
37 | + | ||
38 | + getSearchKeywordDataById(params) { | ||
39 | + return redis.all([ | ||
40 | + ['get', `global:yoho:seo:hot:keywords:id:${params.id}`] | ||
41 | + ]).then(redisData => { | ||
42 | + return redisData; | ||
43 | + }); | ||
44 | + } | ||
45 | + | ||
46 | + index(params) { | ||
47 | + return Promise.all([ | ||
48 | + this.getSearchKeywordDataById(params), | ||
49 | + ]).then(result => { | ||
50 | + let resu = { | ||
51 | + list: [], | ||
52 | + fuzzyWord: [] | ||
53 | + }; | ||
54 | + | ||
55 | + if (_.get(result, '[0][0]')) { | ||
56 | + let build = []; | ||
57 | + let redisData = JSON.parse(result[0][0]); | ||
58 | + | ||
59 | + return this.list(Object.assign(params, {query: redisData.name})).then(listData => { | ||
60 | + _.forEach(_.slice(redisData.data, 0, 12), value => { | ||
61 | + build.push({ | ||
62 | + name: value.keyword, | ||
63 | + link: helpers.urlFormat(`/mip/hot/${value.id}.html`, null) | ||
64 | + }); | ||
65 | + }); | ||
66 | + resu.name = redisData.name; | ||
67 | + resu.fuzzyWord = build; | ||
68 | + if (_.get(listData, 'data.product_list')) { | ||
69 | + resu.list = camelCase(listData.data.product_list); | ||
70 | + _.forEach(resu.list, value => { | ||
71 | + value.isSoonSoldOut = value.isSoonSoldOut === 'Y'; | ||
72 | + }); | ||
73 | + } | ||
74 | + return resu; | ||
75 | + }); | ||
76 | + } else { | ||
77 | + return resu; | ||
78 | + } | ||
79 | + }); | ||
80 | + } | ||
81 | +} | ||
82 | + | ||
83 | +module.exports = Hot; |
@@ -13,6 +13,7 @@ const rewrite = require('../../doraemon/middleware/rewrite'); | @@ -13,6 +13,7 @@ const rewrite = require('../../doraemon/middleware/rewrite'); | ||
13 | const mip = require('../../doraemon/middleware/mip'); | 13 | const mip = require('../../doraemon/middleware/mip'); |
14 | const guang = require(`${cRoot}/guang`); | 14 | const guang = require(`${cRoot}/guang`); |
15 | const chanpin = require(`${cRoot}/chanpin`); | 15 | const chanpin = require(`${cRoot}/chanpin`); |
16 | +const hot = require(`${cRoot}/hot`); | ||
16 | const productDetail = require(`${cRoot}/product-detail`); | 17 | const productDetail = require(`${cRoot}/product-detail`); |
17 | 18 | ||
18 | router.use(mip); | 19 | router.use(mip); |
@@ -25,4 +26,6 @@ router.get('/list/:id.html', chanpin.redirect); | @@ -25,4 +26,6 @@ router.get('/list/:id.html', chanpin.redirect); | ||
25 | 26 | ||
26 | router.get('/product/:skn.html', productDetail.index); | 27 | router.get('/product/:skn.html', productDetail.index); |
27 | 28 | ||
29 | +router.get('/hot/:id.html', hot.index); | ||
30 | + | ||
28 | module.exports = router; | 31 | module.exports = router; |
apps/mip/views/action/hot.hbs
0 → 100644
@@ -13,10 +13,10 @@ const isTest = process.env.NODE_ENV === 'test'; | @@ -13,10 +13,10 @@ const isTest = process.env.NODE_ENV === 'test'; | ||
13 | 13 | ||
14 | const domains = { | 14 | const domains = { |
15 | 15 | ||
16 | - api: 'http://api.yoho.cn/', | ||
17 | - service: 'http://service.yoho.cn/', | ||
18 | - liveApi: 'http://testapi.live.yohops.com:9999/', | ||
19 | - singleApi: 'http://api-test3.yohops.com:9999/', | 16 | + // api: 'http://api.yoho.cn/', |
17 | + // service: 'http://service.yoho.cn/', | ||
18 | + // liveApi: 'http://testapi.live.yohops.com:9999/', | ||
19 | + // singleApi: 'http://api-test3.yohops.com:9999/', | ||
20 | 20 | ||
21 | // gray | 21 | // gray |
22 | // api: 'http://apigray.yoho.cn/', | 22 | // api: 'http://apigray.yoho.cn/', |
@@ -24,10 +24,10 @@ const domains = { | @@ -24,10 +24,10 @@ const domains = { | ||
24 | // platformApi: 'http://172.16.6.210:8088/', | 24 | // platformApi: 'http://172.16.6.210:8088/', |
25 | 25 | ||
26 | 26 | ||
27 | - // api: 'http://api-test3.yohops.com:9999/', | ||
28 | - // service: 'http://service-test3.yohops.com:9999/', | ||
29 | - // liveApi: 'http://testapi.live.yohops.com:9999/', | ||
30 | - // singleApi: 'http://api-test3.yohops.com:9999/', | 27 | + api: 'http://api-test3.yohops.com:9999/', |
28 | + service: 'http://service-test3.yohops.com:9999/', | ||
29 | + liveApi: 'http://testapi.live.yohops.com:9999/', | ||
30 | + singleApi: 'http://api-test3.yohops.com:9999/', | ||
31 | 31 | ||
32 | imSocket: 'ws://socket.yohobuy.com:10240', | 32 | imSocket: 'ws://socket.yohobuy.com:10240', |
33 | imCs: 'http://im.yohobuy.com/api', | 33 | imCs: 'http://im.yohobuy.com/api', |
-
Please register or login to post a comment