students.js
2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* 学生优惠controller
* @author: ghw<hongwei.gao@yoho.cn>
* @date: 2016/8/5
*/
'use strict';
const mRoot = '../models';
const helpers = global.yoho.helpers;
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, req).then(result => {
if ('isStudent' in req.user && parseInt(req.user.isStudent, 10) === 1) {
result.realData.verifyRusult = {isStudent: true};
}
res.render('students/index', result);
}).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) => {
if (!req.user.uid) {
res.send({code: 200, data: helpers.urlFormat('/signin.html')});
}
studentsModel.verifyIdentity(req.user.uid, req.query).then(result => {
res.json(result);
}).catch(next);
};
/**
* 获取优惠券领取状态
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.userAcquireStatus = (req, res, next) => {
let uid;
if (!req.user.uid) {
uid = '';
} else {
uid = req.user.uid;
}
studentsModel.userAcquireStatus(uid, req.query.couponIds).then(result => {
res.json(result);
}).catch(next);
};
/**
* 学生返币专享页面
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.list = (req, res, next) => {
let resData = {};
studentsModel.getStudentsList(req.query, req.yoho.channel).then(result => {
Object.assign(resData, result);
res.render('list/index', resData);
}).catch(next);
};