Authored by wenjiekong

Merge branch 'feature/students' of http://git.yoho.cn/fe/yohobuy-node into feature/students

... ... @@ -21,7 +21,8 @@ const studentsModel = require(`${mRoot}/students`); // students 页 model
exports.index = (req, res, next) => {
let channel = req.query.channel || req.cookies._Channel || 'boys';
studentsModel.getStudentsData(channel).then(result => {
req.user.uid = 13311991;
studentsModel.getStudentsData(channel, req).then(result => {
let responseData = studentsModel.getTestData(channel);
... ...
... ... @@ -94,5 +94,6 @@ exports.verifyStudent = (uid, collegeName, educationDegree, enrollmentYear) => {
enrollment_year: enrollmentYear
};
console.log(finalParams);
return api.get('', finalParams);
};
... ...
... ... @@ -30,6 +30,20 @@ const getCoupon = (data) => {
return dest;
};
/**
* 补零
* @params data array
* @return Object
*/
const pad = (num, n) =>{
let len = num.toString().length;
while (len < n) {
num = '0' + num;
len++;
}
return num;
};
/**
* 认证学生总数
... ... @@ -37,8 +51,13 @@ const getCoupon = (data) => {
* @return Object
*/
exports.studentsNum = (data) => {
let dest = [];
return data;
data = pad(data, 7);
for (let i = 0; i < data.length; i++) {
dest.push(data.charAt(i));
}
return dest;
};
/**
... ...
... ... @@ -11,6 +11,7 @@
// const logger = global.yoho.logger;
// const camelCase = global.yoho.camelCase;
const api = global.yoho.API;
const queryString = require('querystring');
const studentsApi = require('./students-api');
const stuHandler = require('./students-handler');
... ... @@ -29,8 +30,8 @@ const studentsCode = '989396a17443bf61e3e269702e51ef04'; // h5 a83b7d55324fb65f9
* @params channel Object 频道
* @return name returnType 返回值描述
*/
exports.getStudentsData = (channel) => {
return api.all([
exports.getStudentsData = (channel, req) => {
let apiMethod = [
headerModel.requestHeaderData(channel),
// 资源位数据
... ... @@ -41,8 +42,17 @@ exports.getStudentsData = (channel) => {
// 商品数据
studentsApi.getStuProducts()
];
]).then(result => {
if (req.user.uid && req.query.collegeName && req.query.educationDegree &&
req.query.enrollmentYear && req.query.sign) {
apiMethod.push(
studentsApi.verifyStudent(req.user.uid, req.query.collegeName,
req.query.educationDegree, req.query.enrollmentYear)
);
}
return api.all(apiMethod).then(result => {
let responseData = {
module: 'product',
page: 'students',
... ... @@ -52,8 +62,11 @@ exports.getStudentsData = (channel) => {
realData: {
sortItem: [{title: '学生权益介绍', href: 'stu-rights'}, {title: '我要验证身份', href: 'stu-identity'},
{title: '学生热门单品', href: 'stu-good'}, {title: '更多活动推荐', href: 'stu-activity'}]
{title: '学生热门单品', href: 'stu-good'}, {title: '更多活动推荐', href: 'stu-activity'}],
identityItem: {
sendCoin: 100,
stuNum: []
}
},
footerTop: true
... ... @@ -64,13 +77,19 @@ exports.getStudentsData = (channel) => {
Object.assign(responseData.realData, stuHandler.studentResource(result[1].data));
}
// if (result[2].code === 200) {
// }
if (result[2].code === 200) {
responseData.realData.identityItem.stuNum = stuHandler.studentsNum(result[2].data);
}
if (result[3].code === 200) {
Object.assign(responseData.realData, {proItem: stuHandler.stuProducts(result[3].data.product_list)});
}
// console.log(result[4]);
// if (result[4] && result[4].code === 200) {
// console.log(result[4]);
// }
return responseData;
});
};
... ... @@ -269,8 +288,12 @@ exports.getEduLevel = () => {
* @params areaCode int 地区码
* @return Object 接口数据
*/
exports.verifyIdentity = () => {
return studentsApi.verifyIdentity().then(result => {
exports.verifyIdentity = (uid, params) => {
let pageUrl = 'http://localhost:6001/product/students?' +
queryString.stringify({collegeName: params.collegeName,
educationDegree: params.educationDegree, enrollmentYear: params.enrollmentYear});
return studentsApi.verifyIdentity(uid, params.certNo, params.name, pageUrl).then(result => {
return result;
});
};
... ... @@ -281,9 +304,10 @@ exports.verifyIdentity = () => {
* @return Object 接口数据
*/
exports.verifyStudents = (uid, params) => {
let pageUrl = '/product/students?';
return studentsApi.verifyIdentity(uid, params.certNo, params.name, pageUrl).then(result => {
return studentsApi.verifyIdentity(uid, params.collegeName, params.educationDegree, params.enrollmentYear).
then(result => {
return result;
});
};
... ...