Authored by 郝肖肖

'mip-hbs'

'use strict';
const css = require('../css');
const mRoot = '../models';
const listModel = require(`${mRoot}/hot`);
const co = require('bluebird').coroutine;
exports.index = (req, res, next) => {
co(function* () {
let params = {
page: 1,
limit: 100,
sales: 'Y',
outlets: 2,
stocknumber: 1,
need_filter: 'no',
type: 'default',
order: 's_t_desc',
id: req.params.id
};
let list = yield req.ctx(listModel).index(params);
let goodsList = {
name: list.name || '',
list: list.list,
fuzzyWord: list.fuzzyWord
};
return res.render('hot', Object.assign({
css: yield css('chanpin.css'),
title: `${goodsList.name}价格_图片_品牌_怎么样-YOHO!BUY有货`,
mipUrl: `https://m.yohobuy.com${req.originalUrl}`,
mipFooter: true,
canonical: {
currentHref: `https://www.yohobuy.com/hot/${req.params.id}.html`
}
}, goodsList));
})().catch(next);
};
... ...
'use strict';
const utils = '../../../utils';
const redis = require(`${utils}/redis`);
const _ = require('lodash');
const helpers = global.yoho.helpers;
const camelCase = global.yoho.camelCase;
class Hot extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
list(params) {
let options = {
data: {
method: 'web.search.forseo',
sales: params.sales,
outlets: params.outlets,
stocknumber: params.stocknumber,
need_filter: params.need_filter,
query: params.query,
type: params.type,
page: params.page || 1,
limit: params.limit || 24,
order: params.order || 0
},
param: {
code: 200
}
};
return this.get(options).then(result => {
return result;
});
}
getSearchKeywordDataById(params) {
return redis.all([
['get', `global:yoho:seo:hot:keywords:id:${params.id}`]
]).then(redisData => {
return redisData;
});
}
index(params) {
return Promise.all([
this.getSearchKeywordDataById(params),
]).then(result => {
let resu = {
list: [],
fuzzyWord: []
};
if (_.get(result, '[0][0]')) {
let build = [];
let redisData = JSON.parse(result[0][0]);
return this.list(Object.assign(params, {query: redisData.name})).then(listData => {
_.forEach(_.slice(redisData.data, 0, 12), value => {
build.push({
name: value.keyword,
link: helpers.urlFormat(`/mip/hot/${value.id}.html`, null)
});
});
resu.name = redisData.name;
resu.fuzzyWord = build;
if (_.get(listData, 'data.product_list')) {
resu.list = camelCase(listData.data.product_list);
_.forEach(resu.list, value => {
value.isSoonSoldOut = value.isSoonSoldOut === 'Y';
});
}
return resu;
});
} else {
return resu;
}
});
}
}
module.exports = Hot;
... ...
... ... @@ -13,6 +13,7 @@ const rewrite = require('../../doraemon/middleware/rewrite');
const mip = require('../../doraemon/middleware/mip');
const guang = require(`${cRoot}/guang`);
const chanpin = require(`${cRoot}/chanpin`);
const hot = require(`${cRoot}/hot`);
const productDetail = require(`${cRoot}/product-detail`);
router.use(mip);
... ... @@ -25,4 +26,6 @@ router.get('/list/:id.html', chanpin.redirect);
router.get('/product/:skn.html', productDetail.index);
router.get('/hot/:id.html', hot.index);
module.exports = router;
... ...
<div class="good-list-page search-page yoho-page">
{{> chanpin}}
{{> mip}}
{{> mip-footer}}
</div>
... ...
<div class="good-list-page search-page yoho-page">
{{> mip}}
{{> mip-footer}}
</div>
... ...
... ... @@ -13,10 +13,10 @@ const isTest = process.env.NODE_ENV === 'test';
const domains = {
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/',
// gray
// api: 'http://apigray.yoho.cn/',
... ... @@ -24,10 +24,10 @@ const domains = {
// platformApi: 'http://172.16.6.210:8088/',
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
imSocket: 'ws://socket.yohobuy.com:10240',
imCs: 'http://im.yohobuy.com/api',
... ...