students-api.js
3.91 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* 学生营销接口
* @date: 2016-08-06 14:24:04
* @author: name<emial@yoho.cn>
*/
'use strict';
const api = global.yoho.API;
const config = global.yoho.config;
const searchApi = require('./search-api');
const cache = global.yoho.cache;
const logger = global.yoho.logger;
/**
* 获取完成认证学生总数
* @return
*/
exports.getVerifiedTotal = () => {
return api.get('', {method: 'app.student.verifiedStudentTotal'}, config.apiCache);
};
/**
* 获取学历层次列表
* @return
*/
exports.getEduLevelList = () => {
return api.get('', {method: 'app.studentMarket.getEducationLevelList'}, config.apiCache);
};
/**
* 获取学校地区
* @return
*/
exports.getArea = () => {
let finalParams = {
method: 'app.studentMarket.getAddressList'
};
return api.get('', finalParams, config.apiCache);
};
/**
* 获取学校列表
* @return
*/
exports.getSchool = (areaCode) => {
let finalParams = {
method: 'app.studentMarket.getSchoolInfoList',
areaCode: areaCode
};
return api.get('', finalParams, config.apiCache);
};
/**
* 学生专项商品
* @return
*/
exports.getStuProducts = (params) => {
let finalParams = {
method: 'app.student.vip',
order: 's_t_desc',
limit: 15
};
Object.assign(finalParams, params);
return api.get('', finalParams, config.apiCache);
};
/**
* 身份验证
* @return
*/
exports.verifyIdentity = (uid, certNo, name, pageUrl) => {
let finalParams = {
method: 'app.student.verifyIdentity',
uid: uid,
cert_no: certNo,
name: name,
page_url: pageUrl
};
return api.get('', finalParams, config.apiCache);
};
/**
* 学籍验证
* @return
*/
exports.verifyStudent = (uid, collegeName, educationDegree, enrollmentYear) => {
let finalParams = {
method: 'app.student.verifyStudent',
uid: uid,
client_type: 'web',
college_name: collegeName,
education_degree: educationDegree,
enrollment_year: enrollmentYear
};
return api.get('', finalParams, config.apiCache);
};
/**
* 获取优惠券领取状态
* @return
*/
exports.userAcquireStatus = (uid, couponIds) => {
let finalParams = {
method: 'app.coupons.userAcquireStatus',
couponIds: couponIds
};
if (uid !== '') {
finalParams.uid = uid;
}
return api.get('', finalParams, config.apiCache);
};
/**
* 获取学生专享商品列表
* @return
*/
exports.getStudentsProduct = (params) => {
let finalParams = {
method: 'app.student.rebate',
sales: 'Y',
stocknumber: 1,
need_filter: 'yes',
limit: 60
};
Object.assign(finalParams, params);
if (!config.useCache) {
return searchApi.getProductListOrig(finalParams);
} else {
let cKey = searchApi.getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let hasCache = false;
if (cdata) {
try {
cdata = JSON.parse(cdata);
} catch (e) {
logger.debug('getProductList cache data parse fail.');
}
if (cdata.filter && cdata.standard) {
hasCache = true;
finalParams.need_filter = 'no';
}
}
return searchApi.getProductListOrig(finalParams).then(result => {
if (hasCache && result && result.data) {
Object.assign(result.data, cdata);
} else {
if (result && result.data && result.data.filter) {
cache.set(cKey, Object.assign({}, {
filter: result.data.filter,
standard: result.data.standard
}), 3600);
}
}
return result;
});
});
}
};