coupon-new.js
1.58 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
const co = Promise.coroutine;
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const CouponNewModel = require('../models/coupon-new');
class CouponNew {
page(req, res, next) {
let uid = req.user.uid;
co(function* () {
let [couponsApi, couponNumApi] = yield Promise.all([
req.ctx(CouponNewModel).couponGet({ uid }),
req.ctx(CouponNewModel).getCouponNums({ uid })
]);
let pageData = _.get(couponsApi, 'data', {});
let couponNum = _.get(couponNumApi, 'data', {});
res.render('coupons/page', {
module: 'home',
page: 'coupon-new',
localCss: true,
width750: true,
pageData,
couponNum,
pageHeader: headerModel.setNav({
navTitle: '优惠券',
myConponPageNavBtn: true,
navBtn: false
})
});
})().catch(next);
}
/**
* 优惠券数据
*/
coupons(req, res, next) {
let uid = req.user.uid;
let type = req.body.type;
let filter = req.body.filter;
let page = req.body.page;
co(function* () {
let couponApi = yield req.ctx(CouponNewModel).couponGet({
uid, type, filter, page
});
let coupons = _.get(couponApi, 'data.couponList', []);
res.json(coupons);
})().catch(next);
}
}
module.exports = new CouponNew();