Authored by OF1706

guang ctx

... ... @@ -31,13 +31,15 @@ exports.index = (req, res, next) => {
let isHotDegrade = _.get(req.app.locals.pc, 'guang.removeHotTag', false);
let isAdDegrade = _.get(req.app.locals.pc, 'guang.removeAd', false);
const reqCtx = req.ctx(guangModel);
Promise.all([
req.ctx(guangModel).getBanner(channel),
req.ctx(guangModel).getCategory(type, channel),
req.ctx(guangModel).getArticleList(gender, type, uid, udid, page, '', '', pageSize, channel, true),
req.ctx(guangModel).getHotTags(page, pageSize, channel, isHotDegrade),
req.ctx(guangModel).getAds(channel, isAdDegrade),
req.ctx(guangModel).getRecoArticles(gender, 1, 10, channel),
reqCtx.getBanner(channel),
reqCtx.getCategory(type, channel),
reqCtx.getArticleList(gender, type, uid, udid, page, '', '', pageSize, channel, true),
reqCtx.getHotTags(page, pageSize, channel, isHotDegrade),
reqCtx.getAds(channel, isAdDegrade),
reqCtx.getRecoArticles(gender, 1, 10, channel),
headerModel.requestHeaderData(channel)
]).then(ret => {
... ...
... ... @@ -265,15 +265,6 @@ module.exports = class extends global.yoho.BaseModel {
client_type: 'web'
};
let options = {
url: 'guang/api/v2/article/getList',
data: param,
param: {
cache: useCache ? 300 : false
},
api: global.yoho.ServiceAPI
};
if (sortId) {
param.sort_id = sortId;
}
... ... @@ -290,7 +281,15 @@ module.exports = class extends global.yoho.BaseModel {
param.limit = limit;
}
return this.get(options).then(res => {
return this.get({
url: 'guang/api/v2/article/getList',
data: param,
param: {
cache: useCache ? 300 : false
},
api: global.yoho.ServiceAPI
}).then(res => {
if (res && res.data) {
... ... @@ -341,16 +340,15 @@ module.exports = class extends global.yoho.BaseModel {
return null;
}
let options = {
return this.get({
url: 'guang/api/v2/article/getTagTop',
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
return _.map((res && res.data) || [], it => {
let param = {
query: it.tag_name
... ... @@ -385,16 +383,15 @@ module.exports = class extends global.yoho.BaseModel {
content_code: contentCode
};
let options = {
return this.get({
url: URL_OPERATIONS_RESOURCE_GET,
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
let list = [];
if (res && res.code === 200 && res.data && res.data[0] && res.data[0].data) {
... ... @@ -423,16 +420,15 @@ module.exports = class extends global.yoho.BaseModel {
content_code: contentCode
};
let options = {
return this.get({
url: URL_OPERATIONS_RESOURCE_GET,
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
let list = [];
... ... @@ -453,15 +449,14 @@ module.exports = class extends global.yoho.BaseModel {
currentSortId = currentSortId || 0;
let options = {
return this.get({
url: 'guang/api/v1/category/get',
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
let list = [];
if (res && res.code === 200 && res.data) {
... ... @@ -498,16 +493,15 @@ module.exports = class extends global.yoho.BaseModel {
limit: limit
};
let options = {
return this.get({
url: 'guang/api/v2/article/getArticleByViewsNum',
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
let list = [];
... ... @@ -541,16 +535,15 @@ module.exports = class extends global.yoho.BaseModel {
author_id: authorId
};
let options = {
return this.get({
url: 'guang/service/v1/author/getAuthor',
data: data,
param: {
cache: 3600
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
if (res && res.data) {
let d = res.data;
... ... @@ -574,16 +567,15 @@ module.exports = class extends global.yoho.BaseModel {
article_id: aid
};
let options = {
return this.get({
url: 'guang/service/v2/article/getArticle',
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
if (res && res.code === 200 && res.data) {
let d = res.data;
let tags = [];
... ... @@ -643,22 +635,20 @@ module.exports = class extends global.yoho.BaseModel {
getProductList(params, arr) {
let data = {
method: 'web.search.search',
order: 's_n_desc',
limit: 60
};
Object.assign(data, params);
let options = {
url: 'web.search.search',
return this.get({
data: data,
param: {
cache: true
},
api: global.yoho.API
};
}
return this.get(options).then(ret => {
}).then(ret => {
if (ret && ret.code === 200 && ret.data && ret.data.product_list) {
return this._formatProduct(ret.data.product_list, arr);
}
... ... @@ -763,16 +753,15 @@ module.exports = class extends global.yoho.BaseModel {
article_id: aid
};
let options = {
return this.get({
url: 'guang/service/v2/article/getArticleContent',
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => { // 内容内推荐的商品
}).then(res => { // 内容内推荐的商品
let gpromises = [], ggpromises = [];
... ... @@ -845,13 +834,12 @@ module.exports = class extends global.yoho.BaseModel {
udid: udid
};
let options = {
return this.get({
url: 'guang/api/v1/article/getArticleBaseInfo',
data: data,
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => ({
}).then(res => ({
isLike: res && res.isPraise === 'Y',
likeNum: res.praise_num || 0,
isCollected: res && res.isFavor === 'Y'
... ... @@ -870,16 +858,15 @@ module.exports = class extends global.yoho.BaseModel {
article_id: aid
};
let options = {
return this.get({
url: 'guang/service/v2/article/getBrand',
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
if (res && res.code === 200 && res.data) {
return _.map(res.data, it => {
... ... @@ -909,16 +896,15 @@ module.exports = class extends global.yoho.BaseModel {
limit: size
};
let options = {
return this.get({
url: 'guang/service/v2/article/getOtherArticle',
data: data,
param: {
cache: true
},
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
if (res && res.code === 200 && res.data) {
return _.map(res.data, it => {
it.thumb = helpers.image(it.thumb, 264, 173, 1);
... ... @@ -942,13 +928,12 @@ module.exports = class extends global.yoho.BaseModel {
limit: pageSize
};
let options = {
return this.get({
url: 'guang/api/v1/comments/getList',
data: data,
api: global.yoho.ServiceAPI
};
return this.get(options).then(res => {
}).then(res => {
let num = (res.data && res.data.total) || 0;
let list = [];
... ... @@ -995,13 +980,12 @@ module.exports = class extends global.yoho.BaseModel {
content: content
};
let options = {
this.get({
url: 'guang/api/v1/comments/add',
data: data,
api: global.yoho.ServiceAPI
};
this.get(options).then(res => {
}).then(res => {
if (res && res.code === 200) {
return res.data;
} else {
... ... @@ -1023,13 +1007,11 @@ module.exports = class extends global.yoho.BaseModel {
udid: udid
};
let options = {
return this.get({
url: 'guang/api/v2/praise/setPraise',
data: data,
api: global.yoho.ServiceAPI
};
return this.get(options);
});
}
/**
... ... @@ -1045,13 +1027,11 @@ module.exports = class extends global.yoho.BaseModel {
udid: udid
};
let options = {
return this.get({
url: 'guang/api/v2/praise/cancel',
data: data,
api: global.yoho.ServiceAPI
};
return this.get(options);
});
}
/**
... ... @@ -1067,13 +1047,11 @@ module.exports = class extends global.yoho.BaseModel {
uid: uid
};
let options = {
return this.get({
url: 'guang/api/v1/favorite/setFavorite',
data: data,
api: global.yoho.ServiceAPI
};
return this.get(options);
});
}
/**
... ... @@ -1089,13 +1067,11 @@ module.exports = class extends global.yoho.BaseModel {
uid: uid
};
let options = {
return this.get({
url: 'guang/api/v1/favorite/cancelFavorite',
data: data,
api: global.yoho.ServiceAPI
};
return this.get(options);
});
}
/**
... ... @@ -1111,13 +1087,11 @@ module.exports = class extends global.yoho.BaseModel {
udid: udid
};
let options = {
return this.get({
url: 'guang/api/*/article/getArticlePraiseAndFavor',
data: data,
api: global.yoho.ServiceAPI
};
return this.get(options);
});
}
/**
... ... @@ -1151,13 +1125,11 @@ module.exports = class extends global.yoho.BaseModel {
});
}
let options = {
return this.get({
url: 'guang/api/*/article/getSimpleArticleList',
data: params,
api: global.yoho.ServiceAPI
};
return this.get(options);
});
}
};
... ...