students.js 1.89 KB
/**
 * 学生优惠controller
 * @author: ghw<hongwei.gao@yoho.cn>
 * @date: 2016/8/5
 */

'use strict';

const mRoot = '../models';

const studentsModel = require(`${mRoot}/students`); // students  model

/**
 * students 首页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */

exports.index = (req, res, next) => {
    let channel = req.query.channel || req.cookies._Channel || 'boys';

    studentsModel.getStudentsData(channel).then(result => {

        let responseData = studentsModel.getTestData(channel);

        // let responseData = {};
        Object.assign(responseData, result);

        res.render('students/index', responseData);

    }).catch(next);
};

/**
 * 学校地区
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.schoolArea = (req, res, next) => {
    studentsModel.getSchoolArea().then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 学校列表
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.schoolList = (req, res, next) => {
    let areaCode = req.query.areaCode || 32;

    studentsModel.getSchoolList(areaCode).then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 学历层次
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.eduLevel = (req, res, next) => {
    studentsModel.getEduLevel().then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 学生验证
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.verify = (req, res, next) => {

    studentsModel.verify(req.user.uid, req.query).then(result => {
        res.json(result);
    }).catch(next);

};