...
|
...
|
@@ -12,7 +12,7 @@ const moment = require('moment'); |
|
|
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const serviceApi = global.yoho.ServiceAPI;
|
|
|
const searchApi = global.yoho.SearchAPI;
|
|
|
const yohoApi = global.yoho.API;
|
|
|
const cache = global.yoho.cache;
|
|
|
|
|
|
const KEY_WEB_GUANG_BANNER_DATA = 'key_web_guang_banner_data';// 逛的首页banner
|
...
|
...
|
@@ -95,6 +95,7 @@ const getPathNav = (channelType, query) => { |
|
|
const _formatTag = (tagData, isApp, uid) => {
|
|
|
return {
|
|
|
tag: tagData['name'],
|
|
|
name : tagData['name'],
|
|
|
url: helpers.urlFormat('/tags/index', { query: tagData['name']}, 'guang') // urlencode(tagData['name'])
|
|
|
};
|
|
|
};
|
...
|
...
|
@@ -268,6 +269,7 @@ 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;
|
...
|
...
|
@@ -406,11 +408,12 @@ 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 === '专题') {
|
|
|
continue;
|
|
|
}
|
|
|
// if (cat.name === '专题') {
|
|
|
// continue;
|
|
|
// }
|
|
|
|
|
|
list.push({
|
|
|
typeId: cat.id,
|
...
|
...
|
@@ -504,11 +507,13 @@ const getArticleInfo = aid => { |
|
|
|
|
|
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']),
|
|
|
time: moment(d.publish_time * 1000).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,
|
|
|
authorId : d.author_id,
|
|
|
weixinUrl: d.url,
|
|
|
tag : d.tag, //tags 的字符串
|
|
|
tags: tags,
|
|
|
shareImg: 'http:' + helpers.image(d.cover_image, 600, 600)
|
|
|
};
|
...
|
...
|
@@ -516,11 +521,62 @@ const getArticleInfo = aid => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
const _formatProduct = (products, arr) => {
|
|
|
|
|
|
let result = [];
|
|
|
|
|
|
|
|
|
_.forEach(products, (val, key) => {
|
|
|
|
|
|
let goods = {
|
|
|
thumb : helpers.image(val.default_images, 235, 314),
|
|
|
name : val.product_name,
|
|
|
salePrice : val.sales_price,
|
|
|
url : helpers.getUrlBySkc(val.product_id, val.goods_list[0]['goods_id'], val.cn_alphabet),
|
|
|
};
|
|
|
|
|
|
if(val.market_price !== val.sales_price) {
|
|
|
goods.marketPrice = val.market_price;
|
|
|
}
|
|
|
|
|
|
_.forEach(arr, (v, k) => {
|
|
|
if(k == val.product_skn) {
|
|
|
goods.thumb = helpers.image(v, 235, 314);
|
|
|
return false;
|
|
|
}
|
|
|
})
|
|
|
|
|
|
result.push(goods);
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 按照skn string 来查询 query=skn1,skn2,skn3
|
|
|
*/
|
|
|
const getProductList = (params, arr) => {
|
|
|
let finalParams = {
|
|
|
method: 'web.search.search',
|
|
|
|
|
|
// method: 'app.search.li',
|
|
|
order: 's_n_desc',
|
|
|
limit: 60
|
|
|
};
|
|
|
|
|
|
Object.assign(finalParams, params);
|
|
|
return yohoApi.get('', finalParams).then(ret => {
|
|
|
|
|
|
if(ret && ret.code === 200 && ret.data && ret.data.product_list) {
|
|
|
return _formatProduct(ret.data.product_list, arr);
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const _articleContentFormat = {
|
|
|
goods: goods => {
|
|
|
|
|
|
let result = [],
|
|
|
productSkn = [],
|
|
|
let productSkn = [],
|
|
|
arr = {};
|
|
|
|
|
|
_.forEach(goods, (val, key) => {
|
...
|
...
|
@@ -530,45 +586,39 @@ const _articleContentFormat = { |
|
|
|
|
|
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(',')}));
|
|
|
return getProductList({
|
|
|
query: productSkn.join(',')
|
|
|
}, arr);
|
|
|
|
|
|
} else {
|
|
|
return null;
|
|
|
}
|
|
|
},
|
|
|
goodsGroup: goodsGroup => {
|
|
|
$result = $groupSkn = array();
|
|
|
|
|
|
let result = {}, groupSkn = {};
|
|
|
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);
|
|
|
// }
|
|
|
//包含多个对象,每对象里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);
|
|
|
}
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -606,9 +656,7 @@ const _articleContentFormat = { |
|
|
*/
|
|
|
const getArticleContent = aid => {
|
|
|
|
|
|
let result = {
|
|
|
content: []
|
|
|
},
|
|
|
let content = [],
|
|
|
index = 0;
|
|
|
|
|
|
return serviceApi.get('guang/service/v2/article/getArticleContent', {
|
...
|
...
|
@@ -617,31 +665,26 @@ const getArticleContent = aid => { |
|
|
|
|
|
let gpromises = [], ggpromises = [];
|
|
|
|
|
|
if (res && res.contents) {
|
|
|
for (let cnt of res.contents) {
|
|
|
_.forEach(cnt, (it, key) => {
|
|
|
if(res && res.code === 200 && res.data) {
|
|
|
_.forEach(res.data, (it) => {
|
|
|
|
|
|
_.forEach(it, (val, key) => {
|
|
|
if (key === 'goods') {
|
|
|
// goods.push(_articleContentFormat.goods(it.data));
|
|
|
gpromises.push(_articleContentFormat.goods(it.data));
|
|
|
gpromises.push(_articleContentFormat.goods(val.data));
|
|
|
} else if (key === 'goodsGroup') {
|
|
|
for (let gg of it.data) {
|
|
|
ggpromises.push(_articleContentFormat.goodsGroup(gg.recos));
|
|
|
|
|
|
// goodsGroup.push(_articleContentFormat.goodsGroup(gg.recos));
|
|
|
}
|
|
|
//可能包含多个list,则有多个promise
|
|
|
ggpromises = ggpromises.concat(_articleContentFormat.goodsGroup(val.data));
|
|
|
} else {
|
|
|
let other = _.isFunction(_articleContentFormat[key]) ? _articleContentFormat[key](it.data) : '';
|
|
|
result.content.push(other);
|
|
|
let other = _.isFunction(_articleContentFormat[key]) ? _articleContentFormat[key](val.data) : '';
|
|
|
content.push(other);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
index = gpromises.length;
|
|
|
|
|
|
return Promise.all(gpromises.concat(ggpromises)).then(ret => {
|
|
|
return ret;
|
|
|
});
|
|
|
return Promise.all(gpromises.concat(ggpromises));
|
|
|
|
|
|
}).then(res => {
|
|
|
|
...
|
...
|
@@ -653,19 +696,31 @@ const getArticleContent = aid => { |
|
|
goodsResult = res.slice(0, index);
|
|
|
goodsGroupResult = res.slice(index);
|
|
|
|
|
|
for(let gl of goodsResult) {
|
|
|
goods = goods.concat(gl);
|
|
|
}
|
|
|
|
|
|
for(let ggl of goodsGroupResult) {
|
|
|
goodsGroup = goodsGroup.concat(ggl);
|
|
|
}
|
|
|
|
|
|
if (goods.length > 0) {
|
|
|
result.content['relatedReco'] = {
|
|
|
recos: goods
|
|
|
};
|
|
|
content.push({
|
|
|
relatedReco : {
|
|
|
recos: goods
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (goodsGroup.length > 0) {
|
|
|
result.content['relatedReco'] = {
|
|
|
recos: goodsGroup
|
|
|
};
|
|
|
content.push({
|
|
|
relatedReco : {
|
|
|
recos: goodsGroup
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
return content;
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -677,7 +732,7 @@ const getArticleContent = aid => { |
|
|
* @param bool $onlyUrl
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const getArticleBaseInfo = (aId, uid, udid) => {
|
|
|
const getArticleBaseInfo = (aid, uid, udid) => {
|
|
|
return serviceApi.get('guang/api/v1/article/getArticleBaseInfo', {
|
|
|
id: aid,
|
|
|
uid: uid,
|
...
|
...
|
@@ -702,12 +757,15 @@ const getArticleRelateBrand = aid => { |
|
|
article_id: aid
|
|
|
}).then(res => {
|
|
|
|
|
|
return _.map(res, it => {
|
|
|
return {
|
|
|
thumb: it.thumb, // Helpers::getUrlSafe($val['thumb']);
|
|
|
url: it.url // Helpers::getUrlSafe($val['url']);
|
|
|
};
|
|
|
});
|
|
|
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']);
|
|
|
return it;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -719,7 +777,7 @@ const getArticleRelateBrand = aid => { |
|
|
* @param bool $onlyUrl
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const getRelateArticleList = (aId, tag, size) => {
|
|
|
const getRelateArticleList = (aid, tag, size) => {
|
|
|
size = size || 3;
|
|
|
|
|
|
return serviceApi.get('guang/service/v2/article/getOtherArticle', {
|
...
|
...
|
@@ -727,16 +785,12 @@ const getRelateArticleList = (aId, tag, size) => { |
|
|
tags: tag,
|
|
|
limit: size
|
|
|
}).then(res => {
|
|
|
return res;
|
|
|
if (res && res.code === 200 && res.data) {
|
|
|
return _.map(res.data, it => {
|
|
|
|
|
|
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')
|
|
|
};
|
|
|
it.thumb = helpers.image(it.thumb, 264, 173, 1);
|
|
|
it.url = helpers.urlFormat(`/detail/${it.id}.html`, null, 'guang')
|
|
|
return it;
|
|
|
});
|
|
|
}
|
|
|
});
|
...
|
...
|
@@ -781,6 +835,66 @@ const getArticleComments = (aid, page, pageSize) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 文章评论提交
|
|
|
* @param $id
|
|
|
* @param $uid
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const addComment = (aid, uid, content) => {
|
|
|
|
|
|
return serviceApi.get('guang/api/v1/comments/add', {
|
|
|
article_id: aid,
|
|
|
uid: uid,
|
|
|
content : content
|
|
|
}).then(res => {
|
|
|
if(res && res.code === 200) {
|
|
|
return res.data;
|
|
|
} else {
|
|
|
return Promise.reject('评论失败');
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 文章点赞
|
|
|
* @param $id
|
|
|
* @param $uid
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const praise = (aid, udid) => {
|
|
|
|
|
|
return serviceApi.get('guang/api/v2/praise/setPraise', {
|
|
|
article_id: aid,
|
|
|
udid: udid
|
|
|
}).then(res => {
|
|
|
if(res && res.code === 200) {
|
|
|
return res.data;
|
|
|
} else {
|
|
|
return Promise.reject('点赞失败');
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 文章点赞
|
|
|
* @param $id
|
|
|
* @param $uid
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const cancelPraise = (aid, udid) => {
|
|
|
|
|
|
return serviceApi.get('guang/api/v2/praise/cancel', {
|
|
|
article_id: aid,
|
|
|
udid: udid
|
|
|
}).then(res => {
|
|
|
if(res && res.code === 200) {
|
|
|
return res.data;
|
|
|
} else {
|
|
|
return Promise.reject('点赞失败');
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 收藏文章
|
...
|
...
|
@@ -788,13 +902,37 @@ const getArticleComments = (aid, page, pageSize) => { |
|
|
* @param $uid
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const collectArticle = (aid, uid) => {
|
|
|
const collect = (aid, uid) => {
|
|
|
|
|
|
return serviceApi.get('guang/api/v1/favorite/setFavorite', {
|
|
|
article_id: aid,
|
|
|
uid: uid
|
|
|
}).then(res => {
|
|
|
return res;
|
|
|
if(res && res.code === 200) {
|
|
|
return res.data;
|
|
|
} else {
|
|
|
return Promise.reject('收藏失败');
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 取消收藏文章
|
|
|
* @param $id
|
|
|
* @param $uid
|
|
|
* @return mixed
|
|
|
*/
|
|
|
const cancelCollect = (aid, uid) => {
|
|
|
|
|
|
return serviceApi.get('guang/api/v1/favorite/cancelFavorite', {
|
|
|
article_id: aid,
|
|
|
uid: uid
|
|
|
}).then(res => {
|
|
|
if(res && res.code === 200) {
|
|
|
return res.data;
|
|
|
} else {
|
|
|
return Promise.reject('取消收藏失败');
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
...
|
...
|
@@ -807,15 +945,19 @@ module.exports = { |
|
|
getTjArticles: getTjArticles,
|
|
|
getPathNav: getPathNav,
|
|
|
getAuthor: getAuthor,
|
|
|
getArticleComments: getArticleComments,
|
|
|
collectArticle: collectArticle,
|
|
|
|
|
|
getArticleInfo: getArticleInfo,
|
|
|
getArticleContent: getArticleContent,
|
|
|
getArticleBaseInfo: getArticleBaseInfo,
|
|
|
getArticleRelateBrand: getArticleRelateBrand,
|
|
|
getRelateArticleList: getRelateArticleList,
|
|
|
getArticleComments: getArticleComments
|
|
|
getArticleComments: getArticleComments,
|
|
|
|
|
|
addComment : addComment,
|
|
|
praise : praise,
|
|
|
cancelPraise : cancelPraise,
|
|
|
collect : collect,
|
|
|
cancelCollect : cancelCollect
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
|