Blame view

apps/product/controllers/students.js 2.95 KB
wenjiekong authored
1 2 3 4 5 6 7
/**
 * 学生优惠controller
 * @author: ghw<hongwei.gao@yoho.cn>
 * @date: 2016/8/5
 */

'use strict';
htoooth authored
8
htoooth authored
9
// TODO: ctxk
周少峰 authored
10
const mRoot = '../models';
周少峰 authored
11
const helpers = global.yoho.helpers;
wenjiekong authored
12
周少峰 authored
13
const studentsModel = require(`${mRoot}/students`); // students  model
wenjiekong authored
14 15 16 17 18 19 20 21

/**
 * students 首页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
周少峰 authored
22 23
exports.index = (req, res, next) => {
    let channel = req.query.channel || req.cookies._Channel || 'boys';
wenjiekong authored
24
htoooth authored
25
    req.ctx(studentsModel).getStudentsData(channel, req).then(result => {
周少峰 authored
26
周少峰 authored
27
        if ('isStudent' in req.user && parseInt(req.user.isStudent, 10) === 1) {
hongweigao authored
28
            result.realData.identityObj.verifyRusult = {isStudent: true};
29
        }
30
周少峰 authored
31
        res.render('students/index', result);
周少峰 authored
32 33

    }).catch(next);
wenjiekong authored
34
};
周少峰 authored
35 36

/**
周少峰 authored
37 38 39 40 41 42
 * 学校地区
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.schoolArea = (req, res, next) => {
htoooth authored
43
    req.ctx(studentsModel).getSchoolArea().then(result => {
周少峰 authored
44 45 46 47 48 49
        res.json(result);
    }).catch(next);
};

/**
 * 学校列表
周少峰 authored
50 51 52 53
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
周少峰 authored
54 55
exports.schoolList = (req, res, next) => {
    let areaCode = req.query.areaCode || 32;
周少峰 authored
56
htoooth authored
57
    req.ctx(studentsModel).getSchoolList(areaCode).then(result => {
周少峰 authored
58 59
        res.json(result);
    }).catch(next);
wenjiekong authored
60
};
周少峰 authored
61 62 63 64 65 66 67 68

/**
 * 学历层次
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.eduLevel = (req, res, next) => {
htoooth authored
69
    req.ctx(studentsModel).getEduLevel().then(result => {
周少峰 authored
70 71 72
        res.json(result);
    }).catch(next);
};
周少峰 authored
73 74

/**
wenjiekong authored
75
 * 身份验证
周少峰 authored
76 77 78 79 80
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.verify = (req, res, next) => {
周少峰 authored
81 82 83
    if (!req.user.uid) {
        res.send({code: 200, data: helpers.urlFormat('/signin.html')});
    }
周少峰 authored
84
htoooth authored
85
    req.ctx(studentsModel).verifyIdentity(req.user.uid, req.query).then(result => {
周少峰 authored
86 87 88
        res.json(result);
    }).catch(next);
周少峰 authored
89
};
90 91 92 93 94 95 96 97 98 99 100 101

/**
 * 获取优惠券领取状态
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.userAcquireStatus = (req, res, next) => {
    let uid;

    if (!req.user.uid) {
        uid = '';
102
    } else {
103 104 105
        uid = req.user.uid;
    }
htoooth authored
106
    req.ctx(studentsModel).userAcquireStatus(uid, req.query.couponIds).then(result => {
107 108 109 110
        res.json(result);
    }).catch(next);

};
周少峰 authored
111 112 113 114 115 116 117 118 119 120 121


/**
 * 学生返币专享页面
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.list = (req, res, next) => {
    let resData = {};
htoooth authored
122
    req.ctx(studentsModel).getStudentsList(req.query, req.yoho.channel).then(result => {
周少峰 authored
123 124 125 126
        Object.assign(resData, result);
        res.render('list/index', resData);
    }).catch(next);
};