...
|
...
|
@@ -97,7 +97,7 @@ const _formatTag = (tagData, isApp, uid) => { |
|
|
return {
|
|
|
tag: tagData['name'],
|
|
|
name: tagData['name'],
|
|
|
url: helpers.urlFormat('/tags/index', { query: tagData['name']}, 'guang') // urlencode(tagData['name'])
|
|
|
url: helpers.urlFormat('/tags/index', { query: tagData['name']}, 'guang')
|
|
|
};
|
|
|
};
|
|
|
|
...
|
...
|
@@ -139,7 +139,7 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid) => { |
|
|
id: articleData.id,
|
|
|
classification: articleData.category_name,
|
|
|
isReco: articleData.is_recommended ? true : false,
|
|
|
url: ghelper.getArticleUrl(articleData.url, articleData.id), // isApp ? articleData.url : helpers.urlFormat(`/${articleData.id}.html`, null, 'guang'),
|
|
|
url: ghelper.getArticleUrl(articleData.url, articleData.id),
|
|
|
img: helpers.image(articleData.src, width, height, 1),
|
|
|
isSquareImg: isSquareImage,
|
|
|
title: articleData.title,
|
...
|
...
|
@@ -186,7 +186,7 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid) => { |
|
|
// 判断是否显示作者信息
|
|
|
if (showAuthor && articleData['author']) {
|
|
|
if (!isApp) {
|
|
|
articleData['author']['url'] = articleData['author']['url'];// Helpers::getFilterUrl($articleData['author']['url']);
|
|
|
articleData['author']['url'] = articleData['author']['url'];
|
|
|
}
|
|
|
result['author'] = articleData['author'];
|
|
|
}
|
...
|
...
|
@@ -245,9 +245,6 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u |
|
|
client_type: 'web'
|
|
|
};
|
|
|
|
|
|
// $param['private_key'] = Yohobuy::$privateKeyList['web'];
|
|
|
// param['client_secret'] =
|
|
|
|
|
|
if (sortId) {
|
|
|
param.sort_id = sortId;
|
|
|
}
|
...
|
...
|
@@ -270,10 +267,12 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u |
|
|
cache: cache
|
|
|
}).then(res => {
|
|
|
|
|
|
// console.log(JSON.stringify(res));
|
|
|
if (res && res.data) {
|
|
|
|
|
|
let artList, adsList, total = 0;
|
|
|
let artList,
|
|
|
adsList,
|
|
|
total = 0;
|
|
|
|
|
|
if (res.data.total) {
|
|
|
total = _.parseInt(res.data.total);
|
|
|
}
|
...
|
...
|
@@ -281,15 +280,11 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u |
|
|
if (res.data.list) {
|
|
|
let list = res.data.list;
|
|
|
if (list.artList) {
|
|
|
artList = _.map(list.artList, it => {
|
|
|
return _formatArticle(it, true, false, false, uid);
|
|
|
});
|
|
|
artList = _.map(list.artList, it => _formatArticle(it, true, false, false, uid));
|
|
|
}
|
|
|
|
|
|
if (list.adlist) {
|
|
|
adsList = _.map(list.artList, it => {
|
|
|
return _formatAd(it, true, false, false, uid);
|
|
|
});
|
|
|
adsList = _.map(list.artList, it => _formatAd(it, true, false, false, uid));
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -319,8 +314,8 @@ const getHotTags = (page, limit) => { |
|
|
cache: true,
|
|
|
code: 200
|
|
|
}).then(res => {
|
|
|
let tags = (res && res.data) || [];
|
|
|
return _.map(tags, it => {
|
|
|
|
|
|
return _.map((res && res.data) || [], it => {
|
|
|
return {
|
|
|
tagName: it.tag_name,
|
|
|
url: helpers.urlFormat('/tags/index', { query: it.tag_name}, 'guang')
|
...
|
...
|
@@ -339,9 +334,6 @@ const getAds = channelType => { |
|
|
let contentCode = ADS_CODE[channelType] || ADS_CODE.boys;
|
|
|
let ckey = KEY_WEB_GUANG_ADS_DATA + '_' + contentCode;
|
|
|
|
|
|
// $data = Cache::get($key);
|
|
|
// if(empty($data)) {
|
|
|
// $resource = IndexData::getResourceData($contentCode);
|
|
|
return serviceApi.get(URL_OPERATIONS_RESOURCE_GET, {
|
|
|
content_code: contentCode
|
|
|
}).then(res => {
|
...
|
...
|
@@ -350,22 +342,14 @@ const getAds = channelType => { |
|
|
if (res && res['code'] === 200 && res['data'] && res['data'][0] && res['data'][0]['data']) {
|
|
|
list = _.map(res['data'][0]['data'], (it) => {
|
|
|
return {
|
|
|
img: helpers.image(it.src, 640, 640, 1), // Images::getImageUrl($val['src'], 830, 327, 1),
|
|
|
url: it.url // Helpers::getUrlSafe($val['url']));
|
|
|
img: helpers.image(it.src, 640, 640, 1),
|
|
|
url: it.url
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 格式化数据
|
|
|
// Cache::set($key, $data, 1800);
|
|
|
return list.length > 5 ? list.slice(0, 4) : list;
|
|
|
});
|
|
|
|
|
|
// }
|
|
|
// master没有数据,资源位没有数据, 取二层缓存
|
|
|
// if(empty($data)) {
|
|
|
// $data = Cache::get($key, 'slave');
|
|
|
// }
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -378,8 +362,6 @@ const getBanner = channelType => { |
|
|
let contentCode = BANNER_CODE[channelType] || BANNER_CODE.boys;
|
|
|
let ckey = KEY_WEB_GUANG_BANNER_DATA + '_' + contentCode;
|
|
|
|
|
|
// return cache.get(ckey).then((data) => {
|
|
|
// if(!data) {
|
|
|
return serviceApi.get(URL_OPERATIONS_RESOURCE_GET, {
|
|
|
content_code: contentCode
|
|
|
}).then(res => {
|
...
|
...
|
@@ -389,19 +371,13 @@ const getBanner = channelType => { |
|
|
|
|
|
list = _.map(res['data'][0]['data'], (it) => {
|
|
|
return {
|
|
|
img: helpers.image(it.src, 830, 327, 1), // Images::getImageUrl($val['src'], 830, 327, 1),
|
|
|
url: it.url // Helpers::getUrlSafe($val['url']));
|
|
|
img: helpers.image(it.src, 830, 327, 1),
|
|
|
url: it.url
|
|
|
};
|
|
|
});
|
|
|
|
|
|
// cache.set(); //Cache::set($key, $data, 3600);
|
|
|
}
|
|
|
return list;
|
|
|
});
|
|
|
|
|
|
// }
|
|
|
// return data;
|
|
|
// });
|
|
|
};
|
|
|
|
|
|
const getCategory = currentSortId => {
|
...
|
...
|
@@ -412,10 +388,6 @@ const getCategory = currentSortId => { |
|
|
|
|
|
if (res && res.code === 200 && res.data) {
|
|
|
for (let cat of res.data) {
|
|
|
// if (cat.name === '专题') {
|
|
|
// continue;
|
|
|
// }
|
|
|
|
|
|
list.push({
|
|
|
typeId: cat.id,
|
|
|
type: cat.name,
|
...
|
...
|
@@ -446,12 +418,12 @@ const getTjArticles = (gender, page, limit) => { |
|
|
for (let it of res['data']) {
|
|
|
|
|
|
let reco = {
|
|
|
url: ghelper.getArticleUrl(it.url, it.id), // helpers.urlFormat(`/${it.id}.html`, {}, 'guang'), // Helpers::url('/'.$article['id'].'.html', '', 'guang'),
|
|
|
url: ghelper.getArticleUrl(it.url, it.id),
|
|
|
title: it['title']
|
|
|
};
|
|
|
|
|
|
if (it['src']) {
|
|
|
reco['img'] = helpers.image(it.src, 90, 60, 1);// Images::getImageUrl($article['src'], 90, 60, 1);
|
|
|
reco['img'] = helpers.image(it.src, 90, 60, 1);
|
|
|
}
|
|
|
|
|
|
list.push(reco);
|
...
|
...
|
@@ -508,15 +480,14 @@ const getArticleInfo = aid => { |
|
|
|
|
|
return {
|
|
|
title: d.article_title,
|
|
|
time: moment(d.publish_time * 1000).format('YYYY年MM月DD HH:mm'), // date('Y年m月d日 H:i', $article['publish_time']),
|
|
|
time: moment(d.publish_time * 1000).format('YYYY年MM月DD HH:mm'),
|
|
|
click: d.pageViews,
|
|
|
shareImg: helpers.image(d.cover_image, 600, 600),
|
|
|
desc: d.article_summary,
|
|
|
authorId: d.author_id,
|
|
|
weixinUrl: d.url,
|
|
|
tag: d.tag, // tags 的字符串
|
|
|
tags: tags,
|
|
|
shareImg: 'http:' + helpers.image(d.cover_image, 600, 600)
|
|
|
tags: tags
|
|
|
};
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -557,16 +528,12 @@ const _formatProduct = (products, arr) => { |
|
|
* 按照skn string 来查询 query=skn1,skn2,skn3
|
|
|
*/
|
|
|
const getProductList = (params, arr) => {
|
|
|
let finalParams = {
|
|
|
method: 'web.search.search',
|
|
|
|
|
|
// method: 'app.search.li',
|
|
|
return yohoApi.get('', Object.assign({
|
|
|
method: 'web.search.search',
|
|
|
order: 's_n_desc',
|
|
|
limit: 60
|
|
|
};
|
|
|
|
|
|
Object.assign(finalParams, params);
|
|
|
return yohoApi.get('', finalParams).then(ret => {
|
|
|
}, params)).then(ret => {
|
|
|
|
|
|
if (ret && ret.code === 200 && ret.data && ret.data.product_list) {
|
|
|
return _formatProduct(ret.data.product_list, arr);
|
...
|
...
|
@@ -591,9 +558,9 @@ const _articleContentFormat = { |
|
|
query: productSkn.join(',')
|
|
|
}, arr);
|
|
|
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
},
|
|
|
goodsGroup: goodsGroup => {
|
|
|
|
...
|
...
|
@@ -610,13 +577,13 @@ const _articleContentFormat = { |
|
|
}
|
|
|
|
|
|
if (productSkn.length) {
|
|
|
|
|
|
// 包含多个对象,每对象里list都取数据,最终每个list只取前4个
|
|
|
let pms = getProductList({
|
|
|
query: productSkn.join(',')
|
|
|
}, arr).then(products => {
|
|
|
let p = products.slice(0, 4);
|
|
|
|
|
|
// console.log(JSON.stringify(p));
|
|
|
return p;
|
|
|
});
|
|
|
result.push(pms);
|
...
|
...
|
@@ -676,8 +643,7 @@ const getArticleContent = aid => { |
|
|
// 可能包含多个list,则有多个promise
|
|
|
ggpromises = ggpromises.concat(_articleContentFormat.goodsGroup(val.data));
|
|
|
} else {
|
|
|
let other = _.isFunction(_articleContentFormat[key]) ? _articleContentFormat[key](val.data) : '';
|
|
|
content.push(other);
|
|
|
content.push(_.isFunction(_articleContentFormat[key]) ? _articleContentFormat[key](val.data) : '');
|
|
|
}
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -761,8 +727,8 @@ const getArticleRelateBrand = aid => { |
|
|
if (res && res.code === 200 && res.data) {
|
|
|
return _.map(res.data, it => {
|
|
|
|
|
|
it.thumb = it.thumb; // Helpers::getUrlSafe($val['thumb']);
|
|
|
it.url = it.url; // Helpers::getUrlSafe($val['url']);
|
|
|
it.thumb = it.thumb;
|
|
|
it.url = it.url;
|
|
|
return it;
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -790,7 +756,7 @@ const getRelateArticleList = (aid, tag, size) => { |
|
|
return _.map(res.data, it => {
|
|
|
|
|
|
it.thumb = helpers.image(it.thumb, 264, 173, 1);
|
|
|
it.url = ghelper.getArticleUrl(it.url, it.id); // helpers.urlFormat(`/detail/${it.id}.html`, null, 'guang');
|
|
|
it.url = ghelper.getArticleUrl(it.url, it.id);
|
|
|
return it;
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -801,7 +767,6 @@ const getRelateArticleList = (aid, tag, size) => { |
|
|
* 获取文章评论数据
|
|
|
*/
|
|
|
const getArticleComments = (aid, page, pageSize) => {
|
|
|
let result = {};
|
|
|
|
|
|
page = page || 1;
|
|
|
pageSize = pageSize || 20;
|
...
|
...
|
@@ -811,15 +776,15 @@ const getArticleComments = (aid, page, pageSize) => { |
|
|
page: page,
|
|
|
pageSize: pageSize
|
|
|
}).then(res => {
|
|
|
let result = {};
|
|
|
|
|
|
if (res && res.code === 200) {
|
|
|
result = {
|
|
|
commentNum: (res['data'] && res['data']['total']) || 0
|
|
|
};
|
|
|
let num = (res.data && res.data.total) || 0;
|
|
|
|
|
|
let list = [];
|
|
|
if (result.commentNum > 0 && res['data']['list']) {
|
|
|
for (let it of res['data']['list']) {
|
|
|
|
|
|
if (num > 0 && res.data.list) {
|
|
|
for (let it of res.data.list) {
|
|
|
list.push({
|
|
|
avatar: helpers.image(it.avator, 100, 100),
|
|
|
name: it.username,
|
...
|
...
|
@@ -829,8 +794,10 @@ const getArticleComments = (aid, page, pageSize) => { |
|
|
}
|
|
|
}
|
|
|
|
|
|
result.list = list;
|
|
|
return result;
|
|
|
return {
|
|
|
commentNum: num,
|
|
|
list: list
|
|
|
};
|
|
|
}
|
|
|
|
|
|
});
|
...
|
...
|
@@ -920,27 +887,27 @@ const cancelCollect = (aid, uid) => { |
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getArticleList: getArticleList,
|
|
|
getHotTags: getHotTags,
|
|
|
getAds: getAds,
|
|
|
getBanner: getBanner,
|
|
|
getCategory: getCategory,
|
|
|
getTjArticles: getTjArticles,
|
|
|
getPathNav: getPathNav,
|
|
|
getAuthor: getAuthor,
|
|
|
|
|
|
getArticleInfo: getArticleInfo,
|
|
|
getArticleContent: getArticleContent,
|
|
|
getArticleBaseInfo: getArticleBaseInfo,
|
|
|
getArticleRelateBrand: getArticleRelateBrand,
|
|
|
getRelateArticleList: getRelateArticleList,
|
|
|
getArticleComments: getArticleComments,
|
|
|
|
|
|
addComment: addComment,
|
|
|
praise: praise,
|
|
|
cancelPraise: cancelPraise,
|
|
|
collect: collect,
|
|
|
cancelCollect: cancelCollect
|
|
|
getArticleList,
|
|
|
getHotTags,
|
|
|
getAds,
|
|
|
getBanner,
|
|
|
getCategory,
|
|
|
getTjArticles,
|
|
|
getPathNav,
|
|
|
getAuthor,
|
|
|
|
|
|
getArticleInfo,
|
|
|
getArticleContent,
|
|
|
getArticleBaseInfo,
|
|
|
getArticleRelateBrand,
|
|
|
getRelateArticleList,
|
|
|
getArticleComments,
|
|
|
|
|
|
addComment,
|
|
|
praise,
|
|
|
cancelPraise,
|
|
|
collect,
|
|
|
cancelCollect
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
|