common.js
1015 Bytes
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
/**
* common model
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/08/03
*/
'use strict';
const _ = require('lodash');
const serviceApi = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
/**
* 获取资源数据api
* @function _getResourceData
* @param { string } code 资源码
* @return object
*/
const _getResourceDataAsync = (code) => {
return serviceApi.get('operations/api/v5/resource/get', {
content_code: code
}, {code: 200});
};
const getBannerData = (code) => {
return _getResourceDataAsync(code).then(result => {
let resData = {
code: 404,
message: '获取资源信息失败'
};
if (!_.isEmpty(result.data)) {
resData = Object.assign({code: 200}, result.data[0]);
if (resData.data && resData.data.src) {
resData.data.src = helpers.image(resData.data.src, 330, 390);
}
}
return resData;
});
};
module.exports = {
getBannerData
};