...
|
...
|
@@ -6,11 +6,13 @@ const crypto = global.yoho.crypto; |
|
|
const queryString = require('querystring');
|
|
|
const Promise = require('bluebird');
|
|
|
const co = Promise.coroutine;
|
|
|
const headerModel = require('../../../doraemon/models/header'); // 头部model
|
|
|
|
|
|
|
|
|
const getResource = code => {
|
|
|
return serviceApi.get('operations/api/v5/resource/get', {
|
|
|
content_code: code
|
|
|
content_code: code,
|
|
|
platform: 'iphone'
|
|
|
});
|
|
|
};
|
|
|
const vip = (limit) => {
|
...
|
...
|
@@ -27,6 +29,8 @@ const verifiedStudentTotal = () => { |
|
|
const getProvince = () => {
|
|
|
return api.get('', {
|
|
|
method: 'app.studentMarket.getAddressList'
|
|
|
}, {
|
|
|
cache: true
|
|
|
});
|
|
|
};
|
|
|
const getSchool = code => {
|
...
|
...
|
@@ -91,26 +95,45 @@ const getPlatForm = (req) => { |
|
|
|
|
|
yoho.isiOS = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(userAgent);
|
|
|
yoho.isAndroid = /Android/i.test(userAgent);
|
|
|
yoho.isApp = /YohoBuy/i.test(req.get('User-Agent'));
|
|
|
yoho.isApp = /YohoBuy/i.test(req.get('User-Agent')) || (req.query.app_version && req.query.client_type);
|
|
|
yoho.isSupportStudent = !yoho.isApp || (/^4.9/i.test(req.query.app_version) && !/^4.9.0/i.test(req.query.app_version));
|
|
|
yoho.http = 'http:';
|
|
|
if (isProduction) {
|
|
|
yoho.http = 'https:';
|
|
|
}
|
|
|
yoho.uid = uids && uids.length === 2 ? uids[1] : ''; // 8041246
|
|
|
yoho.uid = req.user.uid || yoho.uid;
|
|
|
yoho.uid = req.user.uid || yoho.uid || req.query.uid || '';
|
|
|
yoho.isLogin = yoho.uid ? true : false;
|
|
|
return co(function*() {
|
|
|
let data = yield getUser(yoho.uid);
|
|
|
|
|
|
yoho.isStudent = data.data && data.data.vip_info && data.data.vip_info.is_student ? true : false;
|
|
|
console.log(yoho);
|
|
|
|
|
|
// console.log(yoho);
|
|
|
return yoho;
|
|
|
})();
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
// const getRequest = (url)=>{
|
|
|
//
|
|
|
// let regurl = /^[^\?]+\?([\w\W]+)$/;
|
|
|
// let regpara = /([^&=]+)=([\w\W]*?)(&|$|#)/g;
|
|
|
// let ret = {};
|
|
|
// let strpara,
|
|
|
// result;
|
|
|
//
|
|
|
// let arrurl = regurl.exec(url);
|
|
|
//
|
|
|
// if (arrurl && arrurl[1]) {
|
|
|
// strpara = arrurl[1];
|
|
|
// while ((result = regpara.exec(strpara)) !== null) {
|
|
|
// ret[result[1]] = result[2];
|
|
|
// }
|
|
|
// }
|
|
|
// return ret;
|
|
|
// };
|
|
|
|
|
|
|
|
|
exports.index = (req, res, next) => {
|
...
|
...
|
@@ -118,12 +141,16 @@ exports.index = (req, res, next) => { |
|
|
let uid = req.__USER__.uid;
|
|
|
let options;
|
|
|
|
|
|
|
|
|
|
|
|
Promise.all([getResource(code), vip()]).then(datas => {
|
|
|
let coupons,
|
|
|
activities,
|
|
|
banner,
|
|
|
icons,
|
|
|
link,
|
|
|
// url,
|
|
|
// param,
|
|
|
couponids = [];
|
|
|
|
|
|
(datas[0].data || []).forEach((item) => {
|
...
|
...
|
@@ -148,11 +175,22 @@ exports.index = (req, res, next) => { |
|
|
break;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
if (coupons && coupons.data) {
|
|
|
coupons.link = link && link.data ? link.data[0].url + '&app_version=1' : '';
|
|
|
coupons.link = link && link.data ? link.data[0].url + (req.__USER__.isApp ? '&app_version=1' : '') : '';
|
|
|
coupons.data = (coupons.data || []).map((item) => {
|
|
|
couponids.push(item.couponID);
|
|
|
|
|
|
// if (item.image.url.indexOf('?') === -1) {
|
|
|
// item.image.url += '?';
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// url = item.image.url.substring(0, item.image.url.indexOf('?'));
|
|
|
//
|
|
|
// param = JSON.stringify(getRequest(item.image.url));
|
|
|
// item.image.url = item.image.url + '&app_version=1&openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + url + '","param":' + param + '}}';
|
|
|
|
|
|
// console.log(item);
|
|
|
return item;
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -161,6 +199,7 @@ exports.index = (req, res, next) => { |
|
|
coupons.data = (coupons.data || []).map((item)=>{
|
|
|
item.status = 1;
|
|
|
(cous.data || []).forEach((it) => {
|
|
|
|
|
|
if (+it.couponId === +item.couponID) {
|
|
|
item.hasNum = it.hasNum;
|
|
|
item.status = it.status;
|
...
|
...
|
@@ -171,7 +210,7 @@ exports.index = (req, res, next) => { |
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
datas[1].data = datas[1].data || {};
|
|
|
datas[1].data.product_list = (datas[1].data.product_list || []).map(function(value) {
|
|
|
value.goodsId = value.goods_list[0].goods_id;
|
|
|
value.url = helpers.urlFormat(`/product/pro_${value.product_id}_${value.goodsId}/${value.cn_alphabet}.html`) + `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${value.product_skn}}}`;
|
...
|
...
|
@@ -186,10 +225,18 @@ exports.index = (req, res, next) => { |
|
|
coupons: coupons,
|
|
|
activities: activities,
|
|
|
isStudent: req.__USER__.isStudent,
|
|
|
isSupportStudent: req.__USER__.isSupportStudent,
|
|
|
isLogin: req.__USER__.isLogin,
|
|
|
title: '有货学生专享优惠',
|
|
|
http: req.__USER__.http
|
|
|
http: req.__USER__.http,
|
|
|
uid: req.__USER__.uid
|
|
|
};
|
|
|
if (!req.__USER__.isApp) {
|
|
|
options.pageHeader = headerModel.setNav({
|
|
|
navTitle: options.title,
|
|
|
navBtn: true
|
|
|
});
|
|
|
}
|
|
|
|
|
|
options.loginUrl = '//m.yohobuy.com/activity/student/register';
|
|
|
if (options.isApp) {
|
...
|
...
|
@@ -200,7 +247,7 @@ exports.index = (req, res, next) => { |
|
|
options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register"}}';
|
|
|
}
|
|
|
} else {
|
|
|
options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register"}}}';
|
|
|
options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student"}}}';
|
|
|
}
|
|
|
} else {
|
|
|
if (options.isLogin) {
|
...
|
...
|
@@ -227,14 +274,23 @@ exports.province = (req, res, next) => { |
|
|
};
|
|
|
|
|
|
exports.register = (req, res, next) => {
|
|
|
let years = [];
|
|
|
let years = [],
|
|
|
refer;
|
|
|
|
|
|
for (let i = 0; i < 8; i++) {
|
|
|
years.push((new Date()).getFullYear() - i);
|
|
|
}
|
|
|
Promise.all([verifiedStudentTotal(), getEducationLevelList()]).then((arr) => {
|
|
|
if (req.__USER__.isStudent) {
|
|
|
res.redirect(helpers.urlFormat('/activity/student'));
|
|
|
refer = req.get('referer') || '/home?openby:yohobuy={"action":"go.mine"}';// TODO
|
|
|
|
|
|
// if (refer) {
|
|
|
// refer = decodeURI(req.cookies.refer);
|
|
|
// } else {
|
|
|
// refer = '/activity/student';
|
|
|
// }
|
|
|
// refer = refer;
|
|
|
res.redirect(helpers.urlFormat(refer));
|
|
|
} else {
|
|
|
res.render('register', {
|
|
|
title: '认证信息填写',
|
...
|
...
|
@@ -308,7 +364,9 @@ exports.verifystudent = (req, res, next) => { |
|
|
isverify: isverify,
|
|
|
prompt: prompt,
|
|
|
isLogin: user.data && user.data.vip_info && user.data.vip_info.is_student ? true : false,
|
|
|
title: '学生身份认证'
|
|
|
title: '学生身份认证',
|
|
|
http: req.__USER__.http,
|
|
|
uid: req.__USER__.uid
|
|
|
});
|
|
|
}).catch(next);
|
|
|
|
...
|
...
|
@@ -335,7 +393,7 @@ exports.detail = (req, res) => { |
|
|
};
|
|
|
|
|
|
exports.isLogin = (req, res, next) => {
|
|
|
let refer = req.cookies.refer;
|
|
|
// let refer = req.cookies.refer;
|
|
|
|
|
|
|
|
|
getPlatForm(req).then((yoho)=>{
|
...
|
...
|
@@ -345,21 +403,22 @@ exports.isLogin = (req, res, next) => { |
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (refer) {
|
|
|
refer = decodeURI(req.cookies.refer);
|
|
|
} else {
|
|
|
refer = '/activity/student/register';
|
|
|
}
|
|
|
// refer = decodeURI(req.cookies.refer)||req.get("refer");
|
|
|
//
|
|
|
// if (refer) {
|
|
|
// refer = decodeURI(req.cookies.refer)||req.get("refer");
|
|
|
// } else {
|
|
|
// refer = '/activity/student/register';
|
|
|
// }
|
|
|
|
|
|
res.redirect(helpers.urlFormat('/signin.html', {
|
|
|
refer: refer
|
|
|
refer: req.get('referer') || '/activity/student/register'
|
|
|
}));
|
|
|
});
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
exports.getUser = (req, res, next)=>{
|
|
|
getPlatForm(req).then((yoho)=>{
|
|
|
req.__USER__ = yoho;
|
...
|
...
|
|