...
|
...
|
@@ -4,12 +4,23 @@ const _ = require('lodash'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
const NewsAPi = require('./news-api');
|
|
|
const moment = require('moment');
|
|
|
const searchHandler = require('../../product/models/search-handler');
|
|
|
|
|
|
console.log(global.utils);
|
|
|
const BOYS = 'boys';
|
|
|
const GIRLS = 'girls';
|
|
|
const KIDS = 'kids';
|
|
|
const LIFESTYLE = 'lifestyle';
|
|
|
|
|
|
// 逛 ads code
|
|
|
const ADS_CODE = {
|
|
|
boys: '41777aa7ac86347692c5aa0d394b2f59',
|
|
|
girls: '722253573823ebb994e313e71b0a4fb9',
|
|
|
lifestyle: '02568b6042510e4be739cc688dc7d6ae',
|
|
|
kids: '1ffdd6ea22c58af52ee6408cd353c2d5'
|
|
|
};
|
|
|
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
...
|
...
|
@@ -54,9 +65,10 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
return {pathNav: pathNav};
|
|
|
}
|
|
|
|
|
|
_formatArticle(rdata) {
|
|
|
_formatArticle(rdata, params) {
|
|
|
let list = _.get(rdata, 'data.content', []);
|
|
|
let total = _.get(rdata, 'data.total', 0);
|
|
|
let pagerData = searchHandler.handlePagerData(total, params);
|
|
|
let lresult = {};
|
|
|
let width = 360;
|
|
|
let height = 240;
|
...
|
...
|
@@ -70,7 +82,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
url: helpers.urlFormat(`/news/${articleData.id}_${articleData.cid}.html`),
|
|
|
img: helpers.image(articleData.image, width, height, 1),
|
|
|
title: articleData.title,
|
|
|
pTime: articleData.update_time,
|
|
|
pTime: moment(articleData.update_time * 1000).format('YYYY年MM月DD HH:mm'),
|
|
|
pView: articleData.views_num,
|
|
|
content: articleData.summary,
|
|
|
isVideo: articleData.videoUrl ? true : false
|
...
|
...
|
@@ -79,32 +91,68 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
return lresult;
|
|
|
});
|
|
|
|
|
|
return {msgs: result, total: total};
|
|
|
return {msgs: result, totalCount: total, footPager: pagerData};
|
|
|
}
|
|
|
|
|
|
_formatAds(res) {
|
|
|
let list = _.map(_.get(res, 'data[0].data', []), (it) => {
|
|
|
return {
|
|
|
img: helpers.image(it.src, 640, 640, 1),
|
|
|
url: it.url
|
|
|
};
|
|
|
});
|
|
|
|
|
|
return {ads: (list.length > 5 ? list.slice(0, 4) : list)};
|
|
|
}
|
|
|
|
|
|
_formatRecoArticles(res) {
|
|
|
let ldata = _.map(_.get(res, 'data', []), it => {
|
|
|
return {
|
|
|
url: helpers.urlFormat(`/guang/${it.id}.html`),
|
|
|
title: it.title,
|
|
|
img: it.src && helpers.image(it.src, 90, 60, 1) || ''
|
|
|
};
|
|
|
});
|
|
|
|
|
|
return {exRecos: ldata};
|
|
|
}
|
|
|
|
|
|
getIndexList(channel, param) {
|
|
|
let newsAPi = new NewsAPi(this.ctx);
|
|
|
let params = {
|
|
|
type: 'wechat',
|
|
|
limit: 20,
|
|
|
page: param.page || 1
|
|
|
};
|
|
|
|
|
|
let apiMethod = [
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
new NewsAPi(this.ctx).getPolymerizationList(params)
|
|
|
newsAPi.getPolymerizationList(params),
|
|
|
newsAPi.getRecoArticles(params),
|
|
|
newsAPi.getAds({
|
|
|
content_code: ADS_CODE[channel] || ADS_CODE.boys,
|
|
|
isAdDegrade: _.get(this.ctx, 'req.app.locals.pc.guang.removeAd', false)
|
|
|
}),
|
|
|
];
|
|
|
|
|
|
return Promise.all(apiMethod).then(result => {
|
|
|
let responseData = {};
|
|
|
|
|
|
// 头部数据
|
|
|
Object.assign(responseData, result[0]);
|
|
|
|
|
|
// 列表数据
|
|
|
Object.assign(responseData, this._formatArticle(result[1]));
|
|
|
Object.assign(responseData, this._formatArticle(result[1], params));
|
|
|
|
|
|
// 获取精彩推荐
|
|
|
Object.assign(responseData, this._formatRecoArticles(result[2]));
|
|
|
|
|
|
// 获取广告数据
|
|
|
Object.assign(responseData, this._formatAds(result[3]));
|
|
|
|
|
|
// 导航pathNav
|
|
|
Object.assign(responseData, this.getPathNav(channel));
|
|
|
|
|
|
// 头部数据
|
|
|
Object.assign(responseData, result[0]);
|
|
|
|
|
|
return responseData;
|
|
|
});
|
|
|
}
|
...
|
...
|
|