info.js
3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/**
* 逛详情models
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 2016/09/07
*/
'use strict';
const serviceAPI = global.yoho.ServiceAPI;
const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
/**
* [逛资讯详情页数据封装]
* @param {[int]} id [内容ID]
* @param {Boolean} isApp [标识是否是APP访问]
* @return {[array]}
*/
const _package = (id, isApp) => {
let result = {
getAuthor: {},
getArticle: {},
getArticleContent: {},
getBrand: {},
getOtherArticle: {}
};
// 客户端类型
let clientType = isApp ? 'iphone' : 'h5';
// 获取资讯
let param = {
article_id: id,
client_type: clientType,
// private_key: sign.privateKey[clientType]
};
return serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticle`, param, {
cache: true
}).then(data => {
// 接口要判断一下返回状态是否成功,OK,I 服了 YOU
if (data.code !== 200) {
result.code = 400;
return result;
}
let article = data.data;
result.getArticle = article;
let promises = [];
// 获取作者信息
param = {
author_id: article.author_id
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_AUTHOR}getAuthor`, param, {
cache: true
}));
// 获取资讯内容
param = {
article_id: id,
client_type: clientType,
// private_key: sign.privateKey[clientType]
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getArticleContent`, param, {
cache: true
}));
// 获取资讯相关的品牌
param = {
article_id: id,
client_type: clientType,
// private_key: sign.privateKey[clientType]
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getBrand`, param, {
cache: true
}));
// 获取资讯相关的其它资讯
if (article.tag) {
param = {
article_id: id,
client_type: clientType,
tags: article.tag,
offset: 0,
limit: 3,
// private_key: sign.privateKey[clientType]
};
// param.client_secret = sign.apiSign(param);
promises.push(serviceAPI.get(`${URI_PACKAGE_ARTICLE}getOtherArticle`, param, {
cache: true
}));
}
return Promise.all(promises).then(datas => {
result.getAuthor = datas[0].data;
result.getArticleContent = datas[1].data;
result.getBrand = datas[2].data;
if (datas.length === 4) {
result.getOtherArticle = datas[3].data;
}
return result;
});
});
};
module.exports = {
package: _package
};