|
|
'use strict';
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const NewsAPi = require('./news-api');
|
|
|
const utils = require('./utils');
|
|
|
const moment = require('moment');
|
|
|
|
|
|
// 逛 ads code
|
|
|
const ADS_CODE = {
|
|
|
boys: '41777aa7ac86347692c5aa0d394b2f59',
|
|
|
girls: '722253573823ebb994e313e71b0a4fb9',
|
|
|
lifestyle: '02568b6042510e4be739cc688dc7d6ae',
|
|
|
kids: '1ffdd6ea22c58af52ee6408cd353c2d5'
|
|
|
};
|
|
|
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
_formatArticle(rdata, params) {
|
|
|
let list = _.get(rdata, 'data.content', []);
|
|
|
let total = _.get(rdata, 'data.total', 0);
|
|
|
let lresult = {};
|
|
|
let width = 360;
|
|
|
let height = 240;
|
|
|
|
|
|
let result = _.map(list, (articleData) => {
|
|
|
articleData.image += '?imageView2/{mode}/w/{width}/h/{height}';
|
|
|
|
|
|
lresult = {
|
|
|
id: articleData.id,
|
|
|
classification: _.get(articleData, 'min_category_name', '') || _.get(articleData, 'category_name', ''),
|
|
|
url: helpers.urlFormat(`/news/${articleData.id}_${articleData.cid}.html`),
|
|
|
img: helpers.image(articleData.image, width, height, 1),
|
|
|
title: articleData.title,
|
|
|
pTime: articleData.update_time && moment(articleData.update_time * 1000).format('YYYY年MM月DD HH:mm'),
|
|
|
pView: articleData.views_num,
|
|
|
content: articleData.summary,
|
|
|
isVideo: articleData.videoUrl ? true : false
|
|
|
};
|
|
|
|
|
|
return lresult;
|
|
|
});
|
|
|
|
|
|
return {msgs: result, totalCount: total};
|
|
|
}
|
|
|
|
|
|
getIndexList(channel, param) {
|
|
|
let newsAPi = new NewsAPi(this.ctx);
|
|
|
let params = {
|
|
|
type: 'wechat',
|
|
|
atype: param.atype || 'yohogroup',
|
|
|
limit: 20,
|
|
|
page: param.page || 1
|
|
|
};
|
|
|
|
|
|
let apiMethod = [
|
|
|
newsAPi.getPolymerizationList(Object.assign({}, params, {id: param.atype || 'yohogroup'})),
|
|
|
];
|
|
|
|
|
|
return Promise.all(apiMethod).then(result => {
|
|
|
let responseData = {};
|
|
|
|
|
|
// 列表数据
|
|
|
Object.assign(responseData, this._formatArticle(result[3], params));
|
|
|
|
|
|
return responseData;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
_formatDetail(rdata) {
|
|
|
let contents = _.get(rdata, 'data.contents', {});
|
|
|
let header = {
|
|
|
title: contents.title,
|
|
|
summary: contents.summary,
|
|
|
tag: contents.tag,
|
|
|
time: contents.update_time && moment(contents.update_time * 1000).format('YYYY年MM月DD HH:mm'),
|
|
|
};
|
|
|
let content = utils.filterPhtml(contents.content, [
|
|
|
'阅读原文',
|
|
|
'点击这里',
|
|
|
'点这里'
|
|
|
]);
|
|
|
|
|
|
return {header: header, content: utils.filterAhtml(content)};
|
|
|
}
|
|
|
|
|
|
detail(channel, param) {
|
|
|
let params = {
|
|
|
id: param.id,
|
|
|
cid: param.cid
|
|
|
};
|
|
|
let newsAPi = new NewsAPi(this.ctx);
|
|
|
let apiMethod = [
|
|
|
newsAPi.getContentDetail(params)
|
|
|
];
|
|
|
|
|
|
return Promise.all(apiMethod).then(result => {
|
|
|
let responseData = {};
|
|
|
|
|
|
// 详情页数据
|
|
|
Object.assign(responseData, this._formatDetail(result[3], params));
|
|
|
|
|
|
// seo
|
|
|
let title = _.get(responseData, 'header.title', '新闻详情页');
|
|
|
let keywords = [];
|
|
|
let tags = _.compact(_.get(responseData, 'header.tag', []).map(el => {
|
|
|
return el.tag_name;
|
|
|
}));
|
|
|
|
|
|
keywords.push(title, tags.slice(0, 3).join('、'), 'YOHO!BUY有货');
|
|
|
Object.assign(responseData, {
|
|
|
title: `${title} | YOHO!BUY有货`,
|
|
|
keywords: keywords.join('、'),
|
|
|
description: _.get(responseData, 'header.summary', _.get(this.ctx, 'res.locals.description'))
|
|
|
});
|
|
|
|
|
|
return responseData;
|
|
|
});
|
|
|
}
|
|
|
}; |
...
|
...
|
|