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 @@ -21,7 +21,8 @@ const studentsModel = require(`${mRoot}/students`); // students 页 model
21 exports.index = (req, res, next) => { 21 exports.index = (req, res, next) => {
22 let channel = req.query.channel || req.cookies._Channel || 'boys'; 22 let channel = req.query.channel || req.cookies._Channel || 'boys';
23 23
24 - studentsModel.getStudentsData(channel).then(result => { 24 + req.user.uid = 13311991;
  25 + studentsModel.getStudentsData(channel, req).then(result => {
25 26
26 let responseData = studentsModel.getTestData(channel); 27 let responseData = studentsModel.getTestData(channel);
27 28
@@ -94,5 +94,6 @@ exports.verifyStudent = (uid, collegeName, educationDegree, enrollmentYear) => { @@ -94,5 +94,6 @@ exports.verifyStudent = (uid, collegeName, educationDegree, enrollmentYear) => {
94 enrollment_year: enrollmentYear 94 enrollment_year: enrollmentYear
95 }; 95 };
96 96
  97 + console.log(finalParams);
97 return api.get('', finalParams); 98 return api.get('', finalParams);
98 }; 99 };
@@ -30,6 +30,20 @@ const getCoupon = (data) => { @@ -30,6 +30,20 @@ const getCoupon = (data) => {
30 return dest; 30 return dest;
31 }; 31 };
32 32
  33 +/**
  34 + * 补零
  35 + * @params data array
  36 + * @return Object
  37 + */
  38 +const pad = (num, n) =>{
  39 + let len = num.toString().length;
  40 +
  41 + while (len < n) {
  42 + num = '0' + num;
  43 + len++;
  44 + }
  45 + return num;
  46 +};
33 47
34 /** 48 /**
35 * 认证学生总数 49 * 认证学生总数
@@ -37,8 +51,13 @@ const getCoupon = (data) => { @@ -37,8 +51,13 @@ const getCoupon = (data) => {
37 * @return Object 51 * @return Object
38 */ 52 */
39 exports.studentsNum = (data) => { 53 exports.studentsNum = (data) => {
  54 + let dest = [];
40 55
41 - return data; 56 + data = pad(data, 7);
  57 + for (let i = 0; i < data.length; i++) {
  58 + dest.push(data.charAt(i));
  59 + }
  60 + return dest;
42 }; 61 };
43 62
44 /** 63 /**
@@ -11,6 +11,7 @@ @@ -11,6 +11,7 @@
11 // const logger = global.yoho.logger; 11 // const logger = global.yoho.logger;
12 // const camelCase = global.yoho.camelCase; 12 // const camelCase = global.yoho.camelCase;
13 const api = global.yoho.API; 13 const api = global.yoho.API;
  14 +const queryString = require('querystring');
14 15
15 const studentsApi = require('./students-api'); 16 const studentsApi = require('./students-api');
16 const stuHandler = require('./students-handler'); 17 const stuHandler = require('./students-handler');
@@ -29,8 +30,8 @@ const studentsCode = '989396a17443bf61e3e269702e51ef04'; // h5 a83b7d55324fb65f9 @@ -29,8 +30,8 @@ const studentsCode = '989396a17443bf61e3e269702e51ef04'; // h5 a83b7d55324fb65f9
29 * @params channel Object 频道 30 * @params channel Object 频道
30 * @return name returnType 返回值描述 31 * @return name returnType 返回值描述
31 */ 32 */
32 -exports.getStudentsData = (channel) => {  
33 - return api.all([ 33 +exports.getStudentsData = (channel, req) => {
  34 + let apiMethod = [
34 headerModel.requestHeaderData(channel), 35 headerModel.requestHeaderData(channel),
35 36
36 // 资源位数据 37 // 资源位数据
@@ -41,8 +42,17 @@ exports.getStudentsData = (channel) => { @@ -41,8 +42,17 @@ exports.getStudentsData = (channel) => {
41 42
42 // 商品数据 43 // 商品数据
43 studentsApi.getStuProducts() 44 studentsApi.getStuProducts()
  45 + ];
44 46
45 - ]).then(result => { 47 +
  48 + if (req.user.uid && req.query.collegeName && req.query.educationDegree &&
  49 + req.query.enrollmentYear && req.query.sign) {
  50 + apiMethod.push(
  51 + studentsApi.verifyStudent(req.user.uid, req.query.collegeName,
  52 + req.query.educationDegree, req.query.enrollmentYear)
  53 + );
  54 + }
  55 + return api.all(apiMethod).then(result => {
46 let responseData = { 56 let responseData = {
47 module: 'product', 57 module: 'product',
48 page: 'students', 58 page: 'students',
@@ -52,8 +62,11 @@ exports.getStudentsData = (channel) => { @@ -52,8 +62,11 @@ exports.getStudentsData = (channel) => {
52 62
53 realData: { 63 realData: {
54 sortItem: [{title: '学生权益介绍', href: 'stu-rights'}, {title: '我要验证身份', href: 'stu-identity'}, 64 sortItem: [{title: '学生权益介绍', href: 'stu-rights'}, {title: '我要验证身份', href: 'stu-identity'},
55 - {title: '学生热门单品', href: 'stu-good'}, {title: '更多活动推荐', href: 'stu-activity'}]  
56 - 65 + {title: '学生热门单品', href: 'stu-good'}, {title: '更多活动推荐', href: 'stu-activity'}],
  66 + identityItem: {
  67 + sendCoin: 100,
  68 + stuNum: []
  69 + }
57 }, 70 },
58 71
59 footerTop: true 72 footerTop: true
@@ -64,13 +77,19 @@ exports.getStudentsData = (channel) => { @@ -64,13 +77,19 @@ exports.getStudentsData = (channel) => {
64 Object.assign(responseData.realData, stuHandler.studentResource(result[1].data)); 77 Object.assign(responseData.realData, stuHandler.studentResource(result[1].data));
65 } 78 }
66 79
67 - // if (result[2].code === 200) {  
68 -  
69 - // } 80 + if (result[2].code === 200) {
  81 + responseData.realData.identityItem.stuNum = stuHandler.studentsNum(result[2].data);
  82 + }
70 83
71 if (result[3].code === 200) { 84 if (result[3].code === 200) {
72 Object.assign(responseData.realData, {proItem: stuHandler.stuProducts(result[3].data.product_list)}); 85 Object.assign(responseData.realData, {proItem: stuHandler.stuProducts(result[3].data.product_list)});
73 } 86 }
  87 +
  88 + // console.log(result[4]);
  89 + // if (result[4] && result[4].code === 200) {
  90 + // console.log(result[4]);
  91 + // }
  92 +
74 return responseData; 93 return responseData;
75 }); 94 });
76 }; 95 };
@@ -269,8 +288,12 @@ exports.getEduLevel = () => { @@ -269,8 +288,12 @@ exports.getEduLevel = () => {
269 * @params areaCode int 地区码 288 * @params areaCode int 地区码
270 * @return Object 接口数据 289 * @return Object 接口数据
271 */ 290 */
272 -exports.verifyIdentity = () => {  
273 - return studentsApi.verifyIdentity().then(result => { 291 +exports.verifyIdentity = (uid, params) => {
  292 + let pageUrl = 'http://localhost:6001/product/students?' +
  293 + queryString.stringify({collegeName: params.collegeName,
  294 + educationDegree: params.educationDegree, enrollmentYear: params.enrollmentYear});
  295 +
  296 + return studentsApi.verifyIdentity(uid, params.certNo, params.name, pageUrl).then(result => {
274 return result; 297 return result;
275 }); 298 });
276 }; 299 };
@@ -281,9 +304,10 @@ exports.verifyIdentity = () => { @@ -281,9 +304,10 @@ exports.verifyIdentity = () => {
281 * @return Object 接口数据 304 * @return Object 接口数据
282 */ 305 */
283 exports.verifyStudents = (uid, params) => { 306 exports.verifyStudents = (uid, params) => {
284 - let pageUrl = '/product/students?';  
285 307
286 - return studentsApi.verifyIdentity(uid, params.certNo, params.name, pageUrl).then(result => { 308 +
  309 + return studentsApi.verifyIdentity(uid, params.collegeName, params.educationDegree, params.enrollmentYear).
  310 + then(result => {
287 return result; 311 return result;
288 }); 312 });
289 }; 313 };