...
|
...
|
@@ -6,36 +6,36 @@ |
|
|
'use strict';
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const moment = require('moment');
|
|
|
|
|
|
// const dataMap = require('../../../config/data-map');
|
|
|
|
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const serviceApi = global.yoho.ServiceAPI;
|
|
|
const searchApi = global.yoho.SearchAPI;
|
|
|
const cache = global.yoho.cache;
|
|
|
|
|
|
const KEY_WEB_GUANG_BANNER_DATA = 'key_web_guang_banner_data';//逛的首页banner
|
|
|
const KEY_WEB_GUANG_ADS_DATA = 'key_web_guang_ads_data';//逛的首页ads
|
|
|
|
|
|
const KEY_WEB_GUANG_BANNER_DATA = 'key_web_guang_banner_data';// 逛的首页banner
|
|
|
const KEY_WEB_GUANG_ADS_DATA = 'key_web_guang_ads_data';// 逛的首页ads
|
|
|
const URL_OPERATIONS_RESOURCE_GET = 'operations/api/v5/resource/get';
|
|
|
|
|
|
// const headerModel = require('../../../doraemon/models/header');
|
|
|
|
|
|
//guang banner code
|
|
|
// guang banner code
|
|
|
const BANNER_CODE = {
|
|
|
'boys': '15a288635c2ed9f6c807417be90f5d2d',
|
|
|
'girls': 'e14e12e35af8626650979f7af8a0de2b',
|
|
|
'lifestyle': '1d398e899f759c6d88971be680521a6f',
|
|
|
'kids': 'ad14ee01ad048ce308aa3ca416133d2a'
|
|
|
}
|
|
|
};
|
|
|
|
|
|
//逛 ads code
|
|
|
// 逛 ads code
|
|
|
const ADS_CODE = {
|
|
|
'boys': '41777aa7ac86347692c5aa0d394b2f59',
|
|
|
'girls': '722253573823ebb994e313e71b0a4fb9',
|
|
|
'lifestyle': '02568b6042510e4be739cc688dc7d6ae',
|
|
|
'kids': '1ffdd6ea22c58af52ee6408cd353c2d5'
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取首页频道nav
|
...
|
...
|
@@ -89,19 +89,19 @@ const getPathNav = (channelType, query) => { |
|
|
}]
|
|
|
);
|
|
|
|
|
|
return query ? _.concat(path, [{ name : query, pathTitle : query}]) : path;
|
|
|
}
|
|
|
return query ? _.concat(path, [{ name: query, pathTitle: query}]) : path;
|
|
|
};
|
|
|
|
|
|
const _formatTag = (tagData, isApp, uid) => {
|
|
|
return {
|
|
|
tag : tagData['name'],
|
|
|
url : helpers.urlFormat('/tags/index', { query : tagData['name']}, 'guang') //urlencode(tagData['name'])
|
|
|
}
|
|
|
}
|
|
|
tag: tagData['name'],
|
|
|
url: helpers.urlFormat('/tags/index', { query: tagData['name']}, 'guang') // urlencode(tagData['name'])
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 格式化资讯文章
|
|
|
*
|
|
|
*
|
|
|
* @param array $articleData 需要格式化的资讯数据
|
|
|
* @param bool $showTag 是否显示左上角标签
|
|
|
* @param mixed $isApp 是否显示分享,在APP客户端里嵌入需要传url链接
|
...
|
...
|
@@ -111,11 +111,11 @@ const _formatTag = (tagData, isApp, uid) => { |
|
|
*/
|
|
|
const _formatArticle = (articleData, showTag, isApp, showAuthor, uid) => {
|
|
|
|
|
|
if(showTag !== false) {
|
|
|
if (showTag !== false) {
|
|
|
showTag = true;
|
|
|
}
|
|
|
|
|
|
if(showAuthor !== false) {
|
|
|
if (showAuthor !== false) {
|
|
|
showAuthor = true;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -127,41 +127,41 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid) => { |
|
|
let width, height, isSquareImage = true, tags = [];
|
|
|
width = height = 360;
|
|
|
|
|
|
if(articleData['conver_image_type'] === 2) {
|
|
|
if (articleData['conver_image_type'] === 2) {
|
|
|
width = 360;
|
|
|
height = 240;
|
|
|
isSquareImage = false;
|
|
|
}
|
|
|
|
|
|
let result = {
|
|
|
id : articleData.id,
|
|
|
classification :articleData.category_name,
|
|
|
isReco : articleData.is_recommended ? true : false,
|
|
|
url : isApp ? articleData.url : helpers.urlFormat(`/${articleData.id}.html`, null, 'guang'),
|
|
|
img : helpers.image(articleData.src, width, height, 1),
|
|
|
isSquareImg : isSquareImage,
|
|
|
title : articleData.title,
|
|
|
pTime : articleData['publish_time'],
|
|
|
pView : articleData['views_num'],
|
|
|
content : articleData['intro'],
|
|
|
showTags : showTag,
|
|
|
comment : articleData['comment_num']
|
|
|
}
|
|
|
id: articleData.id,
|
|
|
classification: articleData.category_name,
|
|
|
isReco: articleData.is_recommended ? true : false,
|
|
|
url: isApp ? articleData.url : helpers.urlFormat(`/${articleData.id}.html`, null, 'guang'),
|
|
|
img: helpers.image(articleData.src, width, height, 1),
|
|
|
isSquareImg: isSquareImage,
|
|
|
title: articleData.title,
|
|
|
pTime: articleData['publish_time'],
|
|
|
pView: articleData['views_num'],
|
|
|
content: articleData['intro'],
|
|
|
showTags: showTag,
|
|
|
comment: articleData['comment_num']
|
|
|
};
|
|
|
|
|
|
if(!articleData['author']){
|
|
|
if (!articleData['author']) {
|
|
|
articleData['author'] = {
|
|
|
name : '',
|
|
|
avatar : ''
|
|
|
}
|
|
|
name: '',
|
|
|
avatar: ''
|
|
|
};
|
|
|
}
|
|
|
result['author'] = articleData.author.name;
|
|
|
if (articleData['author']['author_id']) {
|
|
|
let author_id = articleData['author']['author_id'];
|
|
|
result['editorUrl'] = helpers.urlFormat('/Index/editor', {'author_id' : author_id}, 'guang');
|
|
|
result['editorUrl'] = helpers.urlFormat('/Index/editor', {'author_id': author_id}, 'guang');
|
|
|
}
|
|
|
|
|
|
if (articleData['tags']) {
|
|
|
for(let tag of articleData['tags']) {
|
|
|
for (let tag of articleData['tags']) {
|
|
|
tags.push(_formatTag(tag, isApp));
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -170,9 +170,9 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid) => { |
|
|
// 收藏
|
|
|
if (isApp) {
|
|
|
result['collect'] = {
|
|
|
isCollected : articleData['isFavor'] && articleData['isFavor'] === 'Y',
|
|
|
url : uid ? 'javascript:;' : articleData['url'].replace('"islogin":"N"', '"islogin":"Y"')
|
|
|
}
|
|
|
isCollected: articleData['isFavor'] && articleData['isFavor'] === 'Y',
|
|
|
url: uid ? 'javascript:;' : articleData['url'].replace('"islogin":"N"', '"islogin":"Y"')
|
|
|
};
|
|
|
} else { // 点赞
|
|
|
result['like'] = articleData['praise_num'];
|
|
|
result['liked'] = articleData['isPraise'] && articleData['isPraise'] === 'Y';
|
...
|
...
|
@@ -184,7 +184,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'];// Helpers::getFilterUrl($articleData['author']['url']);
|
|
|
}
|
|
|
result['author'] = articleData['author'];
|
|
|
}
|
...
|
...
|
@@ -211,17 +211,17 @@ const _formatArticle = (articleData, showTag, isApp, showAuthor, uid) => { |
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const _formatAd = (adData, isApp, uid ) => {
|
|
|
const _formatAd = (adData, isApp, uid) => {
|
|
|
|
|
|
return {
|
|
|
img : helpers.image(adData['src'], 640, 640),
|
|
|
url : isApp ? adData['url'] : helpers.urlFormat('/info/index', { 'id' : adData['id'] }, 'guang'),
|
|
|
title : adData['title'],
|
|
|
bgColor : adData['bgColor']
|
|
|
}
|
|
|
}
|
|
|
img: helpers.image(adData['src'], 640, 640),
|
|
|
url: isApp ? adData['url'] : helpers.urlFormat('/info/index', { 'id': adData['id'] }, 'guang'),
|
|
|
title: adData['title'],
|
|
|
bgColor: adData['bgColor']
|
|
|
};
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取页文章数据
|
...
|
...
|
@@ -236,17 +236,17 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u |
|
|
useCache = useCache || false;
|
|
|
|
|
|
let param = {
|
|
|
gender : gender,
|
|
|
page : page,
|
|
|
uid : uid,
|
|
|
udid : udid,
|
|
|
client_type : "web"
|
|
|
}
|
|
|
gender: gender,
|
|
|
page: page,
|
|
|
uid: uid,
|
|
|
udid: udid,
|
|
|
client_type: 'web'
|
|
|
};
|
|
|
|
|
|
// $param['private_key'] = Yohobuy::$privateKeyList['web'];
|
|
|
//param['client_secret'] =
|
|
|
// param['client_secret'] =
|
|
|
|
|
|
if(sortId) {
|
|
|
if (sortId) {
|
|
|
param.sort_id = sortId;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -254,49 +254,49 @@ const getArticleList = (gender, sortId, uid, udid, page, tag, authorId, limit, u |
|
|
param.tag = tag;
|
|
|
}
|
|
|
|
|
|
if(_.isNumber(authorId)) {
|
|
|
if (_.isNumber(authorId)) {
|
|
|
param.author_id = authorId;
|
|
|
}
|
|
|
|
|
|
if(limit) {
|
|
|
if (limit) {
|
|
|
param.limit = limit;
|
|
|
}
|
|
|
|
|
|
let cache = useCache ? 300 : false;
|
|
|
|
|
|
return serviceApi.get('guang/api/v2/article/getList', param, {
|
|
|
cache : cache
|
|
|
cache: cache
|
|
|
}).then(res => {
|
|
|
|
|
|
if(res && res.data) {
|
|
|
if (res && res.data) {
|
|
|
|
|
|
let artList, adsList, total = 0;
|
|
|
if(res.data.total) {
|
|
|
if (res.data.total) {
|
|
|
total = _.parseInt(res.data.total);
|
|
|
}
|
|
|
|
|
|
if(res.data.list) {
|
|
|
if (res.data.list) {
|
|
|
let list = res.data.list;
|
|
|
if(list.artList) {
|
|
|
if (list.artList) {
|
|
|
artList = _.map(list.artList, it => {
|
|
|
return _formatArticle(it, true, false, false, uid);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(list.adlist) {
|
|
|
if (list.adlist) {
|
|
|
adsList = _.map(list.artList, it => {
|
|
|
return _formatAd(it, true, false, false, uid);
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
return {
|
|
|
msgs : artList,
|
|
|
ads : adsList,
|
|
|
total : total
|
|
|
}
|
|
|
msgs: artList,
|
|
|
ads: adsList,
|
|
|
total: total
|
|
|
};
|
|
|
}
|
|
|
})
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -320,7 +320,7 @@ const getHotTags = (page, limit) => { |
|
|
return _.map(tags, it => {
|
|
|
return {
|
|
|
tagName: it.tag_name,
|
|
|
url: helpers.urlFormat('/tags/index', { query : it.tag_name}, 'guang')
|
|
|
url: helpers.urlFormat('/tags/index', { query: it.tag_name}, 'guang')
|
|
|
};
|
|
|
});
|
|
|
});
|
...
|
...
|
@@ -332,34 +332,34 @@ const getHotTags = (page, limit) => { |
|
|
* @return {Object}
|
|
|
*/
|
|
|
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 => {
|
|
|
// $data = Cache::get($key);
|
|
|
// if(empty($data)) {
|
|
|
// $resource = IndexData::getResourceData($contentCode);
|
|
|
return serviceApi.get(URL_OPERATIONS_RESOURCE_GET, {
|
|
|
content_code: contentCode
|
|
|
}).then(res => {
|
|
|
|
|
|
let list = [];
|
|
|
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']));
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
let list = [];
|
|
|
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']));
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
//格式化数据
|
|
|
//Cache::set($key, $data, 1800);
|
|
|
return list.length > 5 ? list.slice(0, 4) : list;
|
|
|
});
|
|
|
|
|
|
//}
|
|
|
//master没有数据,资源位没有数据, 取二层缓存
|
|
|
// 格式化数据
|
|
|
// Cache::set($key, $data, 1800);
|
|
|
return list.length > 5 ? list.slice(0, 4) : list;
|
|
|
});
|
|
|
|
|
|
// }
|
|
|
// master没有数据,资源位没有数据, 取二层缓存
|
|
|
// if(empty($data)) {
|
|
|
// $data = Cache::get($key, 'slave');
|
|
|
// }
|
...
|
...
|
@@ -375,29 +375,30 @@ 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) => {
|
|
|
// return cache.get(ckey).then((data) => {
|
|
|
// if(!data) {
|
|
|
return serviceApi.get(URL_OPERATIONS_RESOURCE_GET, {
|
|
|
content_code : contentCode
|
|
|
}).then(res => {
|
|
|
return serviceApi.get(URL_OPERATIONS_RESOURCE_GET, {
|
|
|
content_code: contentCode
|
|
|
}).then(res => {
|
|
|
|
|
|
let list = [];
|
|
|
if(res && res['code'] === 200 && res['data'] && res['data'][0] && res['data'][0]['data']) {
|
|
|
let list = [];
|
|
|
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, 830, 327, 1), //Images::getImageUrl($val['src'], 830, 327, 1),
|
|
|
url : it.url //Helpers::getUrlSafe($val['url']));
|
|
|
}
|
|
|
});
|
|
|
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']));
|
|
|
};
|
|
|
});
|
|
|
|
|
|
// cache.set(); //Cache::set($key, $data, 3600);
|
|
|
}
|
|
|
return list;
|
|
|
});
|
|
|
|
|
|
//cache.set(); //Cache::set($key, $data, 3600);
|
|
|
}
|
|
|
return list;
|
|
|
})
|
|
|
// }
|
|
|
// return data;
|
|
|
//});
|
|
|
// });
|
|
|
};
|
|
|
|
|
|
const getCategory = currentSortId => {
|
...
|
...
|
@@ -405,17 +406,17 @@ const getCategory = currentSortId => { |
|
|
currentSortId = currentSortId || 0;
|
|
|
return serviceApi.get('guang/api/v1/category/get', {}).then(res => {
|
|
|
let list = [];
|
|
|
if(res && res.code === 200 && res.data) {
|
|
|
for(let cat of res.data) {
|
|
|
if(cat.name === '专题') {
|
|
|
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,
|
|
|
isActive : cat.id == currentSortId,
|
|
|
navUrl : helpers.urlFormat('/index/index', { type : cat.id }, 'guang')
|
|
|
typeId: cat.id,
|
|
|
type: cat.name,
|
|
|
isActive: cat.id == currentSortId,
|
|
|
navUrl: helpers.urlFormat('/index/index', { type: cat.id }, 'guang')
|
|
|
});
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -424,26 +425,29 @@ const getCategory = currentSortId => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
const getExcellectRecos = (gender, page, limit) => {
|
|
|
/**
|
|
|
* 得到推荐文章
|
|
|
*/
|
|
|
const getTjArticles = (gender, page, limit) => {
|
|
|
|
|
|
return serviceApi.get('guang/api/v2/article/getArticleByViewsNum', {
|
|
|
gender : gender,
|
|
|
page : page,
|
|
|
limit : limit
|
|
|
gender: gender,
|
|
|
page: page,
|
|
|
limit: limit
|
|
|
}).then(res => {
|
|
|
|
|
|
let list = [];
|
|
|
|
|
|
if(res && res['data']) {
|
|
|
for(let it of res['data']) {
|
|
|
if (res && res['data']) {
|
|
|
for (let it of res['data']) {
|
|
|
|
|
|
let reco = {
|
|
|
url : helpers.urlFormat(`/${it.id}.html`, {}, 'guang'), // Helpers::url('/'.$article['id'].'.html', '', 'guang'),
|
|
|
title : it['title']
|
|
|
url: helpers.urlFormat(`/${it.id}.html`, {}, 'guang'), // Helpers::url('/'.$article['id'].'.html', '', 'guang'),
|
|
|
title: it['title']
|
|
|
};
|
|
|
|
|
|
if(it['src']) {
|
|
|
reco['img'] = helpers.image(it.src, 90, 60, 1);//Images::getImageUrl($article['src'], 90, 60, 1);
|
|
|
if (it['src']) {
|
|
|
reco['img'] = helpers.image(it.src, 90, 60, 1);// Images::getImageUrl($article['src'], 90, 60, 1);
|
|
|
}
|
|
|
|
|
|
list.push(reco);
|
...
|
...
|
@@ -452,33 +456,364 @@ const getExcellectRecos = (gender, page, limit) => { |
|
|
|
|
|
return list;
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取作者信息
|
|
|
*/
|
|
|
const getAuthor = authorId => {
|
|
|
|
|
|
return serviceApi.get('guang/service/v1/author/getAuthor', {
|
|
|
author_id : authorId
|
|
|
author_id: authorId
|
|
|
}, {
|
|
|
cache : 3600
|
|
|
cache: 3600
|
|
|
}).then(res => {
|
|
|
|
|
|
if(res && res['data']) {
|
|
|
if (res && res.data) {
|
|
|
let d = res.data;
|
|
|
return {
|
|
|
avatar : res['data']['avatar'],
|
|
|
name : res['data']['name'],
|
|
|
intro : res['data']['author_desc']
|
|
|
authorId : authorId,
|
|
|
avatar: d.avatar,
|
|
|
name: d.name,
|
|
|
intro: d.author_desc,
|
|
|
authorUrl : d.name ? helpers.urlFormat('/Index/editor', { 'author_id' : authorId }, 'guang') : ''
|
|
|
};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取文章基本信息,文章标题(不含内容)
|
|
|
*/
|
|
|
const getArticleInfo = aid => {
|
|
|
|
|
|
return serviceApi.get('guang/service/v2/article/getArticle', {
|
|
|
article_id : aid
|
|
|
}).then(res => {
|
|
|
|
|
|
if(res && res.code === 200 && res.data) {
|
|
|
let d = res.data;
|
|
|
|
|
|
let tags = [];
|
|
|
if (d.tags) {
|
|
|
|
|
|
for(let t of d.tags) {
|
|
|
tags.push(_formatTag(t));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
title : d.article_title,
|
|
|
time : moment(d.publish_time).format('YYYY年MM月DD HH:mm'), //date('Y年m月d日 H:i', $article['publish_time']),
|
|
|
click : d.pageViews,
|
|
|
shareImg : helpers.image(d.cover_image, 600, 600),
|
|
|
desc : d.article_summary,
|
|
|
weixinUrl : d.url,
|
|
|
tags : tags,
|
|
|
shareImg : 'http:' + helpers.image(d.cover_image, 600, 600)
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
const _articleContentFormat = {
|
|
|
goods : goods => {
|
|
|
|
|
|
let result = [],
|
|
|
productSkn = [],
|
|
|
arr = {}
|
|
|
|
|
|
_.forEach(goods, (val, key) => {
|
|
|
productSkn.push(val.id);
|
|
|
arr[val.id] = val.src;
|
|
|
})
|
|
|
|
|
|
if (productSkn.length > 0) {
|
|
|
|
|
|
return null; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// return searchApi.get('', {
|
|
|
// query : productSkn.join(',')
|
|
|
// }).then(products => {
|
|
|
|
|
|
// if (isset($product['data']['product_list'])) {
|
|
|
// $result = self::formatProduct($product['data']['product_list'], $arr);
|
|
|
// }
|
|
|
// return {};
|
|
|
// });
|
|
|
//$product = SearchData::searchElasticByCondition(array({'query' : productSkn.join(',')}));
|
|
|
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
},
|
|
|
goodsGroup : goodsGroup => {
|
|
|
$result = $groupSkn = array();
|
|
|
|
|
|
let result = {}, groupSkn = {};
|
|
|
_.forEach(goodsGroup, (val, key) => {
|
|
|
if(val && val.list) {
|
|
|
|
|
|
let productSkn = [];
|
|
|
let arr = {};
|
|
|
groupSkn[key] = [];
|
|
|
for(let it of val.list) {
|
|
|
groupSkn[key].push(it.id);
|
|
|
productSkn.push(it.id);
|
|
|
arr[it.id]=it.src;
|
|
|
}
|
|
|
|
|
|
if(productSkn.length) {
|
|
|
|
|
|
return null; //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
// $product = SearchData::searchElasticByCondition(array('query' => implode(',', $productSkn)));
|
|
|
// if (isset($product['data']['product_list'])) {
|
|
|
// $result[$key]['recos'] = array_slice(self::formatProduct($product['data']['product_list'], $arr), 0, 4);
|
|
|
// }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
},
|
|
|
text : data => {
|
|
|
return data;
|
|
|
},
|
|
|
singleImage : data => {
|
|
|
if(data && data[0] && data[0]['src']) {
|
|
|
return {
|
|
|
pic : helpers.image(data[0]['src'], 640, 640)
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
},
|
|
|
smallPic : data => {
|
|
|
|
|
|
let result = { smallPic : [] };
|
|
|
_.forEach(data, (it, key) => {
|
|
|
if(key < 2) {
|
|
|
result.smallPic.push(helpers.image(it.src, 600, 600));
|
|
|
}
|
|
|
});
|
|
|
return result;
|
|
|
},
|
|
|
link : data => {
|
|
|
return {};
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
|
* 获取文章内容详情
|
|
|
*/
|
|
|
const getArticleContent = aid => {
|
|
|
|
|
|
let result = {
|
|
|
content : []
|
|
|
},
|
|
|
index = 0;
|
|
|
|
|
|
return serviceApi.get('guang/service/v2/article/getArticleContent', {
|
|
|
article_id : aid
|
|
|
}).then(res => { //内容内推荐的商品
|
|
|
|
|
|
let gpromises = [], ggpromises = [];
|
|
|
|
|
|
if(res && res.contents) {
|
|
|
for(let cnt of res.contents) {
|
|
|
_.forEach(cnt, (it, key) => {
|
|
|
if(key === 'goods') {
|
|
|
//goods.push(_articleContentFormat.goods(it.data));
|
|
|
gpromises.push(_articleContentFormat.goods(it.data));
|
|
|
} else if(key === 'goodsGroup') {
|
|
|
for(let gg of it.data) {
|
|
|
ggpromises.push(_articleContentFormat.goodsGroup(gg.recos));
|
|
|
//goodsGroup.push(_articleContentFormat.goodsGroup(gg.recos));
|
|
|
}
|
|
|
} else {
|
|
|
let other = _.isFunction(_articleContentFormat[key]) ? _articleContentFormat[key](it.data) : '';
|
|
|
result.content.push(other);
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
index = gpromises.length;
|
|
|
|
|
|
return Promise.all(gpromises.concat(ggpromises)).then(ret => {
|
|
|
return ret;
|
|
|
});
|
|
|
|
|
|
}).then(res => {
|
|
|
|
|
|
let goodsResult,
|
|
|
goodsGroupResult;
|
|
|
|
|
|
let goods = [], goodsGroup = [];
|
|
|
|
|
|
goodsResult = res.slice(0, index);
|
|
|
goodsGroupResult = res.slice(index);
|
|
|
|
|
|
if(goods.length > 0) {
|
|
|
result.content['relatedReco'] = {
|
|
|
recos : goods
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(goodsGroup.length > 0) {
|
|
|
result.content['relatedReco'] = {
|
|
|
recos : goodsGroup
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断用户是否收藏文章地址,应该是文章与用户关联的信息
|
|
|
* @param $articleId
|
|
|
* @param $uid
|
|
|
* @param $udid
|
|
|
* @param bool $onlyUrl
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const getArticleBaseInfo = (aId, uid, udid) => {
|
|
|
return serviceApi.get('guang/api/v1/article/getArticleBaseInfo', {
|
|
|
id : aid,
|
|
|
uid : uid,
|
|
|
udid : udid
|
|
|
}).then(res => {
|
|
|
return {
|
|
|
isLike : res && res.isPraise === 'Y',
|
|
|
likeNum : res.praise_num || 0,
|
|
|
isCollected : res && res.isFavor === 'Y'
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 文章相关品牌
|
|
|
* @param $articleId
|
|
|
* @param bool $onlyUrl
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const getArticleRelateBrand = aid => {
|
|
|
return serviceApi.get('guang/service/v2/article/getBrand', {
|
|
|
article_id : aid
|
|
|
}).then(res => {
|
|
|
|
|
|
return _.map(res, it => {
|
|
|
return {
|
|
|
thumb : it.thumb, //Helpers::getUrlSafe($val['thumb']);
|
|
|
url : it.url //Helpers::getUrlSafe($val['url']);
|
|
|
}
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 相关文章列表
|
|
|
* @param $articleId
|
|
|
* @param $tag
|
|
|
* @param int $limit
|
|
|
* @param bool $onlyUrl
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const getRelateArticleList = (aId, tag, size) => {
|
|
|
size = size || 3;
|
|
|
|
|
|
return serviceApi.get('guang/service/v2/article/getOtherArticle', {
|
|
|
article_id : aid,
|
|
|
tags : tag,
|
|
|
limit : size
|
|
|
}).then(res => {
|
|
|
return res;
|
|
|
|
|
|
if(res && res.relate) {
|
|
|
return _.map(res.relate, it => {
|
|
|
return {
|
|
|
id : it.id,
|
|
|
title : it.title,
|
|
|
thumb : helpers.image(it.thumb, 264, 173, 1),
|
|
|
url : helpers.urlFormat(`/${it.id}.html`, null, 'guang')
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取文章评论数据
|
|
|
*/
|
|
|
const getArticleComments = (aid, page, pageSize) => {
|
|
|
let result = {};
|
|
|
|
|
|
page = page || 1;
|
|
|
pageSize = pageSize || 20;
|
|
|
|
|
|
return serviceApi.get('guang/api/v1/comments/getList', {
|
|
|
article_id : aid,
|
|
|
page : page,
|
|
|
pageSize : pageSize
|
|
|
}).then(res => {
|
|
|
|
|
|
if(res && res.code === 200) {
|
|
|
result = {
|
|
|
commentNum : (res['data'] && res['data']['total']) || 0
|
|
|
}
|
|
|
|
|
|
let list = [];
|
|
|
if(result.commentNum > 0 && res['data']['list']) {
|
|
|
for(let it of res['data']['list']) {
|
|
|
list.push({
|
|
|
avatar : helpers.image(it.avator, 100, 100),
|
|
|
name : it.username,
|
|
|
content : it.content,
|
|
|
time : it.create_time
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
result.list = list;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 收藏文章
|
|
|
* @param $id
|
|
|
* @param $uid
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const collectArticle = (aid, uid) => {
|
|
|
|
|
|
return serviceApi.get('guang/api/v1/favorite/setFavorite', {
|
|
|
article_id : aid,
|
|
|
uid : uid
|
|
|
}).then(res => {
|
|
|
return res;
|
|
|
})
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
|
getArticleList: getArticleList,
|
|
|
getArticleList: getArticleList,
|
|
|
getHotTags: getHotTags,
|
|
|
getAds: getAds,
|
|
|
getBanner: getBanner,
|
|
|
getCategory: getCategory,
|
|
|
getExcellectRecos: getExcellectRecos,
|
|
|
getTjArticles: getTjArticles,
|
|
|
getPathNav: getPathNav,
|
|
|
getAuthor : getAuthor
|
|
|
getAuthor: getAuthor,
|
|
|
getArticleComments : getArticleComments,
|
|
|
collectArticle : collectArticle,
|
|
|
|
|
|
getArticleInfo : getArticleInfo,
|
|
|
getArticleContent : getArticleContent,
|
|
|
getArticleBaseInfo : getArticleBaseInfo,
|
|
|
getArticleRelateBrand : getArticleRelateBrand,
|
|
|
getRelateArticleList : getRelateArticleList,
|
|
|
getArticleComments : getArticleComments
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
|