coupon-new.js 1.51 KB
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 coupons = yield req.ctx(CouponNewModel).couponData({
                uid, type, filter, page
            });

            res.json(coupons);
        })().catch(next);
    }
}

module.exports = new CouponNew();