Authored by zhangxiaoru

star

... ... @@ -45,12 +45,12 @@ const _processPublicData = (req, title) => {
* @param {[object]} res
* @return {[type]}
*/
let index = (req, res, next) => {
exports.index = (req, res, next) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[0].cur = true;
starModel.getIndexData().then((result) => {
req.ctx(starModel).getIndexData().then((result) => {
md5Str = result.md5;
res.render('star/index', _.assign({
page: 'star',
... ... @@ -67,8 +67,8 @@ let index = (req, res, next) => {
}).catch(next);
};
let getIndexHtml = (req, res, next) => {
starModel.getIndexData().then((result) => {
exports.getIndexHtml = (req, res, next) => {
req.ctx(starModel).getIndexData().then((result) => {
if (md5Str !== result.md5) {
md5Str = result.md5;
... ... @@ -93,8 +93,8 @@ let getIndexHtml = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let special = (req, res, next) => {
starModel.getSpecialData().then((result) => {
exports.special = (req, res, next) => {
req.ctx(starModel).getSpecialData().then((result) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[1].cur = true;
... ... @@ -115,7 +115,7 @@ let special = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let collocation = (req, res) => {
exports.collocation = (req, res) => {
const pageHeadTab = _.cloneDeep(headTab);
pageHeadTab[2].cur = true;
... ... @@ -134,11 +134,11 @@ let collocation = (req, res) => {
* @param {[object]} res
* @return {[type]}
*/
let collocationList = (req, res, next) => {
exports.collocationList = (req, res, next) => {
let params = req.query;
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0; // 客户端访问,不能使用 cookie
starModel.getCollocationListData(params, uid).then((result) => {
req.ctx(starModel).getCollocationListData(params, uid).then((result) => {
res.render('star/list', _.assign({
layout: false,
params: params,
... ... @@ -154,14 +154,14 @@ let collocationList = (req, res, next) => {
* @param {[type]} res [description]
* @return {[type]}
*/
let setFavorite = (req, res, next) => {
exports.setFavorite = (req, res, next) => {
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0;
let params = {
articleId: req.body.articleId,
type: req.body.type
};
starModel.setFavorite(params, uid).then((result) => {
req.ctx(starModel).setFavorite(params, uid).then((result) => {
if (result.code === 400) {
if (req.body.pageType === '1') {
let urlEncode = '\/guang\/star\/collocation';
... ... @@ -185,7 +185,7 @@ let setFavorite = (req, res, next) => {
* @param {[object]} res
* @return {[type]}
*/
let detail = (req, res) => {
exports.detail = (req, res) => {
res.render('star/detail', _.assign({
isStarDetailPage: true,
page: 'detail-list'
... ... @@ -198,11 +198,11 @@ let detail = (req, res) => {
* @param {[object]} res
* @return {[type]}
*/
let detailList = (req, res, next) => {
exports.detailList = (req, res, next) => {
let params = req.query;
let uid = req.user.uid || req.query.uid || req.cookies.guangStarUid || 0;
starModel.getDetailData(params, uid).then((result) => {
req.ctx(starModel).getDetailData(params, uid).then((result) => {
res.render('star/list', _.assign({
layout: false,
params: params,
... ... @@ -211,14 +211,3 @@ let detailList = (req, res, next) => {
}));
}).catch(next);
};
module.exports = {
index,
getIndexHtml,
special,
collocation,
collocationList,
setFavorite,
detail,
detailList
};
... ...
... ... @@ -15,12 +15,17 @@ const api = global.yoho.API;
const contentCode = contentCodeConfig.guang;
/**
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
const _getResources = (page) => {
_getResources(page) {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode[page],
platform: 'iphone'
... ... @@ -34,14 +39,14 @@ const _getResources = (page) => {
return [];
}
});
};
}
/**
/**
* 星潮教室首页数据处理
* @param {[array]} dataList
* @return {[array]}
*/
const _processIndexData = (dataList) => {
_processIndexData(dataList) {
const formatData = {
ads: [],
starAvatar: [],
... ... @@ -119,16 +124,16 @@ const _processIndexData = (dataList) => {
}
return formatData;
};
}
/**
/**
* 明星专题列表及星搭配数据处理
* @param {[array]} list
* @param {[boolean]} flag 明星专题列表需要转换下日期格式
* @return {[array]}
*/
const _processGuangData = (list, flag) => {
_processGuangData(list, flag) {
const formatData = [];
list = list || [];
... ... @@ -154,12 +159,12 @@ const _processGuangData = (list, flag) => {
});
return formatData;
};
}
/**
/**
* 星潮首页
*/
const getIndexData = () => {
getIndexData() {
return api.get('', {
method: 'app.starClass.index',
code: '8adc27fcf5676f356602889afcfd2a8e'
... ... @@ -167,18 +172,18 @@ const getIndexData = () => {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return _processIndexData(result);
return this._processIndexData(result);
} else {
logger.error('star class content resource return code no 200');
return {};
}
});
};
}
/**
/**
* 明星专题
*/
const getDetailData = (params, uid) => {
getDetailData(params, uid) {
return api.get('', {
method: 'app.starClass.lastTagArticle',
tag: params.tag,
... ... @@ -192,21 +197,21 @@ const getDetailData = (params, uid) => {
if (params.page > result.data.totalPage) {
return '';
} else {
return _processGuangData(result.data.list, true);
return this._processGuangData(result.data.list, true);
}
} 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) => {
... ... @@ -226,12 +231,12 @@ const getSpecialData = () => {
return result;
});
};
}
/**
/**
* 星搭配
*/
const getCollocationListData = (params, uid) => {
getCollocationListData(params, uid) {
return serviceAPI.get('guang/api/v5/article/getStarClassroomArticleList', Object.assign({
limit: '20',
uid: uid
... ... @@ -239,15 +244,15 @@ const getCollocationListData = (params, uid) => {
cache: true
}).then((result) => {
if (result && result.code === 200) {
return _processGuangData(result.data.list.artList);
return this._processGuangData(result.data.list.artList);
} else {
logger.error('getStarClassroomArticleList code no 200');
return [];
}
});
};
}
const setFavorite = (params, uid) => {
setFavorite(params, uid) {
if (!uid) {
return Promise.resolve({
code: 400,
... ... @@ -261,12 +266,5 @@ const setFavorite = (params, uid) => {
article_id: params.articleId,
uid: uid
});
};
module.exports = {
getIndexData,
getSpecialData,
getCollocationListData,
setFavorite,
getDetailData
}
};
... ...