question.js 2.05 KB
'use strict';

const questionModel = require('../models/question');
const headerModel = require('../../../doraemon/models/header'); // 头部model

exports.list = (req, res, next) => {
    req.ctx(questionModel).getQuestionList().then(result => {
        res.render('question/list', {
            title: '调研中心',
            module: '3party',
            page: 'question-list',
            pageHeader: headerModel.setNav({
                navTitle: '调研中心'
            }),
            list: result,
            isApp: req.yoho.isApp,
            localCss: true
        });
    }).catch(next);
};

exports.check = (req, res, next) => {
    let params = req.body;

    params.uid = req.user.uid || params.uid;

    if (!params.uid) {

        return res.send({code: 206, message: '请先登录!'});
    }

    req.ctx(questionModel).getQuestionStatus(params).then(result => {
        res.send(result);
    }).catch(next);
};

exports.submit = (req, res, next) => {
    let params = req.body;

    params.uid = req.user.uid || params.uid;

    if (!params.uid) {
        return res.send({code: 400, message: '请先登录!'});
    }

    if (req.yoho.isApp) {
        params.sourceType = 'APP';
    } else if (req.yoho.mobile) {
        params.sourceType = 'H5';
    } else {
        params.sourceType = 'PC';
    }

    req.ctx(questionModel).submitQuestion(params).then(result => {
        res.send(result);
    }).catch(next);
};



exports.detail = (req, res, next) => {
    let id = parseInt(`0${req.params.id}`, 10);

    req.ctx(questionModel).getQuestionDetail(id, req.user.uid).then(result => {
        if (result && req.yoho.isApp) {
            result.uid = req.user.uid;
        }

        res.render('question/detail', {
            title: 'YOHOBUY!潮流大调查',
            module: '3party',
            page: 'question-detail',
            pageHeader: headerModel.setNav({
                navTitle: 'YOHOBUY!潮流大调查'
            }),
            detail: result,
            isApp: req.yoho.isApp,
            localCss: true
        });
    }).catch(next);
};