getBanner.js
1.32 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
/**
* 获取资源位 banner广告 controller
* @author: gxh<xuhui.ge@yoho.cn>
* @date: 2016/11/30
*/
'use strict';
const getBannerModel = require('../models/getBanner');
const helpers = global.yoho.helpers;
const index = (req, res, next) => {
let contentCode = req.query.content_code || '';
let width = req.query.width || '';
let height = req.query.height || '';
req.ctx(getBannerModel).getResource(contentCode).then(data => {
let banner = '';
if (data.data) {
// 获取banner数据
let result = data.data[0];
if (result && result.data) {
if (result.template_name === 'single_image') {
banner = result.data[0];
} else if (result.template_name === 'single_name_image') {
banner = result.data;
}
if (banner) {
if (!width || !height) {
width = 2600;
height = 60;
}
}
banner.src = helpers.image(banner.src, width, height, 2);
banner.url = banner.url;
}
}
res.jsonp({
code: banner ? 200 : 400,
data: banner
});
}).catch(next);
};
module.exports = {
index
};