suggest.js 1.87 KB
/**
* 个人中心意见反馈
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/09/01
*/

'use strict';

const suggestModel = require('../models/suggest');
const headerModel = require('../../../doraemon/models/header'); // 头部model
const _ = require('lodash');

exports.suggestData = (req, res, next) => {
    let uid = req.user.uid;
    let udid = req.sessionID || 'yoho';
    let page = req.query.page || 1;
    let limit = 10;

    req.ctx(suggestModel).suggestData(uid, udid, page, limit).then((result) => {

        res.render('suggest', {
            module: 'home',
            page: 'suggest',
            pageHeader: _.assign(headerModel.setNav({
                navTitle: '意见反馈'
            }), {
                navBtn: false
            }),
            title: '意见反馈',
            pageFooter: true,
            suggestContent: result
        });
    }).catch(next);
};

exports.upAndDown = (req, res, next) => {
    let uid = req.user.uid;
    let udid = req.sessionID;
    let reliable = req.body.reliable || 1;
    let suggestId = req.body.suggest_id;

    req.ctx(suggestModel).upAndDown(uid, udid, reliable, suggestId).then((result) => {

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

exports.suggestSub = (req, res) => {
    res.render('suggest-sub', {
        module: 'home',
        page: 'suggest',
        pageHeader: _.assign(headerModel.setNav({
            navTitle: '反馈问题'
        }), {
            navBtn: false,
            suggestSub: true
        }),
        title: '反馈问题',
        pageFooter: true
    });
};

exports.saveSuggest = (req, res, next) => {
    let uid = req.user.uid;
    let content = req.body.content;
    let image = req.body.image;
    let suggestType = req.body.suggest_type || 2;

    req.ctx(suggestModel).saveSuggest(uid, content, image, suggestType).then((result) => {

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