coupons.js 1.15 KB
// 优惠券 by acgpiano
'use strict';
const headerModel = require('../../../doraemon/models/header'), // 头部model
    model = require('../models/coupons');

// status为使用状态
const index = (req, res, next) => {
    req.ctx(model).couponData({
        method: 'app.coupons.li',
        uid: req.user.uid,
        status: req.body.status || 0,
        page: req.body.page || 1,
        limit: 10,
    }).then(result => {
        let options = {
            module: 'home',
            page: 'coupons',
            pageHeader: headerModel.setNav({
                navTitle: '优惠券'
            }),
            title: '优惠券',
            pageFooter: true,
            list: result,
            localCss: true
        };

        res.render('coupons', options);
    }).catch(next);
};

const couponsAjax = (req, res, next) => {
    req.ctx(model).couponData({
        method: 'app.coupons.li',
        uid: req.user.uid,
        status: parseInt(req.body.status || 0, 10),
        page: parseInt(req.body.page || 1, 10),
        limit: 10,
    }).then(result => {
        res.json(result);
    }).catch(next);
};

module.exports = {
    index,
    couponsAjax
};