...
|
...
|
@@ -15,258 +15,256 @@ const api = global.yoho.API; |
|
|
|
|
|
const contentCode = contentCodeConfig.guang;
|
|
|
|
|
|
/**
|
|
|
* 获取资源位数据
|
|
|
* @param {[string]} page
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
const _getResources = (page) => {
|
|
|
return serviceAPI.get('operations/api/v5/resource/get', {
|
|
|
content_code: contentCode[page],
|
|
|
platform: 'iphone'
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return resourcesProcess(result.data);
|
|
|
} else {
|
|
|
logger.error('star class content resource return code no 200');
|
|
|
return [];
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 星潮教室首页数据处理
|
|
|
* @param {[array]} dataList
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
const _processIndexData = (dataList) => {
|
|
|
const formatData = {
|
|
|
ads: [],
|
|
|
starAvatar: [],
|
|
|
articles: []
|
|
|
};
|
|
|
|
|
|
let list = dataList.data || {};
|
|
|
|
|
|
|
|
|
formatData.md5 = dataList.md5;
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
// 首页资源位数据处理
|
|
|
if (list.ads) {
|
|
|
_.forEach(list.ads.data, (data) => {
|
|
|
formatData.ads.push({
|
|
|
src: data.src.replace('imageView/', 'imageView2/'),
|
|
|
url: data.url
|
|
|
});
|
|
|
/**
|
|
|
* 获取资源位数据
|
|
|
* @param {[string]} page
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
_getResources(page) {
|
|
|
return serviceAPI.get('operations/api/v5/resource/get', {
|
|
|
content_code: contentCode[page],
|
|
|
platform: 'iphone'
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return resourcesProcess(result.data);
|
|
|
} else {
|
|
|
logger.error('star class content resource return code no 200');
|
|
|
return [];
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// 首页明星文章数据处理
|
|
|
if (list.list) {
|
|
|
_.forEach(list.list, (data, index) => {
|
|
|
const avatar = {
|
|
|
tags: []
|
|
|
};
|
|
|
/**
|
|
|
* 星潮教室首页数据处理
|
|
|
* @param {[array]} dataList
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
_processIndexData(dataList) {
|
|
|
const formatData = {
|
|
|
ads: [],
|
|
|
starAvatar: [],
|
|
|
articles: []
|
|
|
};
|
|
|
|
|
|
let list = dataList.data || {};
|
|
|
|
|
|
|
|
|
formatData.md5 = dataList.md5;
|
|
|
|
|
|
// 首页资源位数据处理
|
|
|
if (list.ads) {
|
|
|
_.forEach(list.ads.data, (data) => {
|
|
|
formatData.ads.push({
|
|
|
src: data.src.replace('imageView/', 'imageView2/'),
|
|
|
url: data.url
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (data.ext.tags.length > 1) {
|
|
|
avatar.isSwiper = true;
|
|
|
}
|
|
|
// 首页明星文章数据处理
|
|
|
if (list.list) {
|
|
|
_.forEach(list.list, (data, index) => {
|
|
|
const avatar = {
|
|
|
tags: []
|
|
|
};
|
|
|
|
|
|
_.forEach(data.ext.tags, (tags, i) => {
|
|
|
if (i >= 1) {
|
|
|
return;
|
|
|
if (data.ext.tags.length > 1) {
|
|
|
avatar.isSwiper = true;
|
|
|
}
|
|
|
|
|
|
avatar.tags.push({
|
|
|
avatarUrl: `/guang/star/detail?tag=${tags.tagName}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line
|
|
|
cover: tags.cover ? (tags.cover + '?imageView2/2/w/104/h/104') : tags.cover,
|
|
|
tagName: tags.tagName
|
|
|
_.forEach(data.ext.tags, (tags, i) => {
|
|
|
if (i >= 1) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
avatar.tags.push({
|
|
|
avatarUrl: `/guang/star/detail?tag=${tags.tagName}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${tags.tagName}"}}}`, // eslint-disable-line
|
|
|
cover: tags.cover ? (tags.cover + '?imageView2/2/w/104/h/104') : tags.cover,
|
|
|
tagName: tags.tagName
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
if (formatData.articles.length > 30) {
|
|
|
return;
|
|
|
}
|
|
|
if (formatData.articles.length > 30) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
formatData.articles.push(_.merge({
|
|
|
noLazy: index < 2,
|
|
|
id: data.id,
|
|
|
url: data.url,
|
|
|
title: data.title,
|
|
|
articeTxt: data.intro,
|
|
|
src: data.src,
|
|
|
publish_time: helpers.dateFormat('MM月DD日 hh:mm', data.publish_time),
|
|
|
views_num: data.views_num
|
|
|
}, avatar));
|
|
|
});
|
|
|
}
|
|
|
formatData.articles.push(_.merge({
|
|
|
noLazy: index < 2,
|
|
|
id: data.id,
|
|
|
url: data.url,
|
|
|
title: data.title,
|
|
|
articeTxt: data.intro,
|
|
|
src: data.src,
|
|
|
publish_time: helpers.dateFormat('MM月DD日 hh:mm', data.publish_time),
|
|
|
views_num: data.views_num
|
|
|
}, avatar));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
// 首页明星头像数据处理
|
|
|
if (list.tags) {
|
|
|
_.forEach(list.tags, (data) => {
|
|
|
let url = `/guang/star/detail?tag=${data.tagName}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line
|
|
|
// 首页明星头像数据处理
|
|
|
if (list.tags) {
|
|
|
_.forEach(list.tags, (data) => {
|
|
|
let url = `/guang/star/detail?tag=${data.tagName}&openby:yohobuy={"action":"go.h5","params":{"id":"","share":"","shareparam":{},"islogin":"N","type":0,"updateflag":"N","url":"http://m.yohobuy.com/guang/star/detail","param":{"tag":"${data.tagName}"}}}`; // eslint-disable-line
|
|
|
|
|
|
formatData.starAvatar.push({
|
|
|
// noLazy: index < 6,
|
|
|
url: url,
|
|
|
cover: data.cover ? (data.cover +
|
|
|
'?imageView2/2/w/180/h/180/q/90').replace('http:', '') : data.cover.replace('http:', '')
|
|
|
formatData.starAvatar.push({
|
|
|
// noLazy: index < 6,
|
|
|
url: url,
|
|
|
cover: data.cover ? (data.cover +
|
|
|
'?imageView2/2/w/180/h/180/q/90').replace('http:', '') : data.cover.replace('http:', '')
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return formatData;
|
|
|
};
|
|
|
return formatData;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 明星专题列表及星搭配数据处理
|
|
|
* @param {[array]} list
|
|
|
* @param {[boolean]} flag 明星专题列表需要转换下日期格式
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
const _processGuangData = (list, flag) => {
|
|
|
const formatData = [];
|
|
|
/**
|
|
|
* 明星专题列表及星搭配数据处理
|
|
|
* @param {[array]} list
|
|
|
* @param {[boolean]} flag 明星专题列表需要转换下日期格式
|
|
|
* @return {[array]}
|
|
|
*/
|
|
|
_processGuangData(list, flag) {
|
|
|
const formatData = [];
|
|
|
|
|
|
list = list || [];
|
|
|
list = list || [];
|
|
|
|
|
|
_.forEach(list, (data, key) => {
|
|
|
if (flag) {
|
|
|
data.publish_time = helpers.dateFormat('MM月DD日 hh:mm', data.publish_time);
|
|
|
}
|
|
|
_.forEach(list, (data, key) => {
|
|
|
if (flag) {
|
|
|
data.publish_time = helpers.dateFormat('MM月DD日 hh:mm', data.publish_time);
|
|
|
}
|
|
|
|
|
|
if (data.isFavor === 'N') {
|
|
|
data.isCollected = false;
|
|
|
} else {
|
|
|
data.isCollected = true;
|
|
|
}
|
|
|
if (data.isFavor === 'N') {
|
|
|
data.isCollected = false;
|
|
|
} else {
|
|
|
data.isCollected = true;
|
|
|
}
|
|
|
|
|
|
// data.src += '/q/80';
|
|
|
// data.src += '/q/80';
|
|
|
|
|
|
if (key < 2) {
|
|
|
data.islazy = true;
|
|
|
}
|
|
|
if (key < 2) {
|
|
|
data.islazy = true;
|
|
|
}
|
|
|
|
|
|
formatData.push(data);
|
|
|
});
|
|
|
formatData.push(data);
|
|
|
});
|
|
|
|
|
|
return formatData;
|
|
|
};
|
|
|
return formatData;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 星潮首页
|
|
|
*/
|
|
|
const getIndexData = () => {
|
|
|
return api.get('', {
|
|
|
method: 'app.starClass.index',
|
|
|
code: '8adc27fcf5676f356602889afcfd2a8e'
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return _processIndexData(result);
|
|
|
} else {
|
|
|
logger.error('star class content resource return code no 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
|
* 星潮首页
|
|
|
*/
|
|
|
getIndexData() {
|
|
|
return api.get('', {
|
|
|
method: 'app.starClass.index',
|
|
|
code: '8adc27fcf5676f356602889afcfd2a8e'
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return this._processIndexData(result);
|
|
|
} else {
|
|
|
logger.error('star class content resource return code no 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 明星专题
|
|
|
*/
|
|
|
const getDetailData = (params, uid) => {
|
|
|
return api.get('', {
|
|
|
method: 'app.starClass.lastTagArticle',
|
|
|
tag: params.tag,
|
|
|
page: params.page || 1,
|
|
|
size: 10,
|
|
|
uid: uid
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
if (params.page > result.data.totalPage) {
|
|
|
return '';
|
|
|
/**
|
|
|
* 明星专题
|
|
|
*/
|
|
|
getDetailData(params, uid) {
|
|
|
return api.get('', {
|
|
|
method: 'app.starClass.lastTagArticle',
|
|
|
tag: params.tag,
|
|
|
page: params.page || 1,
|
|
|
size: 10,
|
|
|
uid: uid
|
|
|
}, {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
if (params.page > result.data.totalPage) {
|
|
|
return '';
|
|
|
} else {
|
|
|
return this._processGuangData(result.data.list, true);
|
|
|
}
|
|
|
} else {
|
|
|
return _processGuangData(result.data.list, true);
|
|
|
logger.error('api app.starClass.lastTagArticle code no 200');
|
|
|
return [];
|
|
|
}
|
|
|
} else {
|
|
|
logger.error('api app.starClass.lastTagArticle code no 200');
|
|
|
return [];
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
});
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 星专题
|
|
|
*/
|
|
|
const getSpecialData = () => {
|
|
|
return _getResources('special').then((result) => {
|
|
|
/**
|
|
|
* 星专题
|
|
|
*/
|
|
|
getSpecialData() {
|
|
|
return this._getResources('special').then((result) => {
|
|
|
|
|
|
// 数据结构嵌套太深
|
|
|
_.forEach(result, (data, key) => {
|
|
|
_.map(data.data, (item) => {
|
|
|
if (!_.isObject(item)) {
|
|
|
return;
|
|
|
}
|
|
|
// 数据结构嵌套太深
|
|
|
_.forEach(result, (data, key) => {
|
|
|
_.map(data.data, (item) => {
|
|
|
if (!_.isObject(item)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// item.src += '/q/80';
|
|
|
// item.src += '/q/80';
|
|
|
|
|
|
if (key < 4) {
|
|
|
item.islazy = true;
|
|
|
}
|
|
|
return item;
|
|
|
if (key < 4) {
|
|
|
item.islazy = true;
|
|
|
}
|
|
|
return item;
|
|
|
});
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
/**
|
|
|
* 星搭配
|
|
|
*/
|
|
|
getCollocationListData(params, uid) {
|
|
|
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', Object.assign({
|
|
|
limit: '20',
|
|
|
uid: uid
|
|
|
}, params), {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return this._processGuangData(result.data.list.artList);
|
|
|
} else {
|
|
|
logger.error('getStarClassroomArticleList code no 200');
|
|
|
return [];
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 星搭配
|
|
|
*/
|
|
|
const getCollocationListData = (params, uid) => {
|
|
|
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', Object.assign({
|
|
|
limit: '20',
|
|
|
uid: uid
|
|
|
}, params), {
|
|
|
cache: true
|
|
|
}).then((result) => {
|
|
|
if (result && result.code === 200) {
|
|
|
return _processGuangData(result.data.list.artList);
|
|
|
} else {
|
|
|
logger.error('getStarClassroomArticleList code no 200');
|
|
|
return [];
|
|
|
setFavorite(params, uid) {
|
|
|
if (!uid) {
|
|
|
return Promise.resolve({
|
|
|
code: 400,
|
|
|
message: '未登录'
|
|
|
});
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const setFavorite = (params, uid) => {
|
|
|
if (!uid) {
|
|
|
return Promise.resolve({
|
|
|
code: 400,
|
|
|
message: '未登录'
|
|
|
return api.get('', {
|
|
|
method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
|
|
|
client_type: 'h5',
|
|
|
article_id: params.articleId,
|
|
|
uid: uid
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return api.get('', {
|
|
|
method: params.type === 'del' ? 'app.sns.cancelFavorBackCount' : 'app.sns.setFavorBackCount',
|
|
|
client_type: 'h5',
|
|
|
article_id: params.articleId,
|
|
|
uid: uid
|
|
|
});
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
getIndexData,
|
|
|
getSpecialData,
|
|
|
getCollocationListData,
|
|
|
setFavorite,
|
|
|
getDetailData
|
|
|
}; |
...
|
...
|
|