message.js 1.97 KB
// 消息 by acgpiano
'use strict';
const headerModel = require('../../../doraemon/models/header'), // 头部model
    model = require('../models/message');

const _getList = (req, res, next) => {
    model.getList({
        page: req.body.page,
        size: 20,
        uid: req.user.uid,
    }).then(result => {
        let options = {
            module: 'home',
            page: 'message',
            pageHeader: headerModel.setNav({
                navTitle: '我的消息'
            }),
            title: '我的消息',
            pageFooter: true,
            list: result,
        };

        req.body.page && req.body.page !== '1' && (options.layout = false);
        res.render('message', options);
    }).catch(next);
};

const _msgDetail = (req, res, next) => {
    model.getList({
        page: req.body.page,
        size: 1000,
        msgid: req.query.id,
        uid: req.user.uid,
    }).then(result => {
        let options = {
            module: 'home',
            page: 'message',
            pageHeader: headerModel.setNav({
                navTitle: '我的消息'
            }),
            title: '我的消息',
            pageFooter: true,
            info: result,
        };

        if (result && result.isCollar && result.isCollar === true) {
            res.redirect('/home/message');
        } else {
            res.render('message-detail', options);
        }
        
    }).catch(next);
};

exports.index = (req, res, next) => {
    if (!req.query.id) {
        _getList(req, res, next);
    } else {
        _msgDetail(req, res, next);
    }
};

exports.ajaxDelMes = (req, res, next) => {
    model.delMsg({
        uid: req.user.uid,
        msgid: req.body.id,
    }).then(result => {
        res.send(result);
        res.end();
    }).catch(next);
};

exports.pickCoupon = (req, res, next) => {
    model.pickCoupon({
        uid: req.user.uid,
        couponId: req.body.id,
    }).then(result => {
        res.send(result);
        res.end();
    }).catch(next);
};