guochao.js 1.02 KB
/**
 * 优惠券管理controller
 * @author: leo <y.huang@yoho.cn>
 * @date: 08/08/2018
 */
const guoChaoModel = require('../models/guochao');

const guochaoController = {

    list: async function(req, res) {

        let list = await req.ctx(guoChaoModel).list();

        return res.json(list);

    },

    listPage(req, res) {
        res.render('guochao/list', {
            bodyClass: 'nav-md',
            module: 'admin',
            page: 'guochao'
        });
    },

    async updatePage(req, res) {
        let result = await req.ctx(guoChaoModel).findById(req.query.id);

        if (result instanceof Array) {
            result = result[0];
        }
        res.render('guochao/guochao-option', {
            bodyClass: 'nav-md',
            module: 'admin',
            content: result,
            page: 'guochao-option'
        });
    },

    update: async function(req, res) {
        let result = await req.ctx(guoChaoModel).update(req.body);

        return res.json(result);
    },
};

module.exports = guochaoController;