coupon511.js
1.18 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
/**
* 0元抽奖活动
* @author: yyq <yanqing.yang@yoho.cn>
* @date: 19/07/2018
*/
const coupon511Model = require('../../api/models/coupon511');
const valid = require('../../../utils/validator');
const logger = global.yoho.logger;
module.exports = {
status(req, res, next) {
let data = valid(req.body, {
uid: {type: 'number', empty: false},
});
if (!data.uid) {
return res.json({
code: 400,
message: '参数错误'
});
}
return req.ctx(coupon511Model).getStatus(data.uid).then(result => {
res.json(result);
}).catch(next);
},
take(req, res, next) {
const inx = +req.query.couponInx;
let data = valid(req.body, {
uid: {type: 'number', empty: false},
sessionKey: {type: 'string', empty: false},
appVersion: {type: 'string', empty: false},
appSessionType: {type: 'string', empty: true}
});
logger.warn(`inx: ${inx}, data: ${JSON.stringify(data)}`);
if (!inx || !data.uid) {
return res.json({
code: 400,
message: '参数错误'
});
}
return req.ctx(coupon511Model).takeCoupon(data, inx).then(result => {
res.json(result);
}).catch(next);
}
};