...
|
...
|
@@ -7,6 +7,7 @@ const queryString = require('querystring'); |
|
|
const Promise = require('bluebird');
|
|
|
const co = Promise.coroutine;
|
|
|
const headerModel = require('../../../doraemon/models/header'); // 头部model
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
|
|
|
const getResource = code => {
|
...
|
...
|
@@ -91,20 +92,34 @@ const getPlatForm = (req) => { |
|
|
let userAgent = req.get('User-Agent');
|
|
|
let yoho = {};
|
|
|
let uids = req.get('User-Agent').match(/uid=([^;]+)/i);
|
|
|
let versions = req.get('User-Agent').match(/app_version=([^;]+)/i);
|
|
|
let arrs = [];
|
|
|
let version = false;
|
|
|
let isNewVersion = false;
|
|
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
|
|
|
|
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')) || (req.query.app_version && req.query.client_type);
|
|
|
if (req.query.app_version) {
|
|
|
arrs = req.query.app_version.split('.');
|
|
|
version = arrs.length > 2 && Number(arrs.slice(0, 2).join('') + arrs[2].slice(0, 1)) > 490;
|
|
|
}
|
|
|
|
|
|
yoho.app_version = versions && versions.length === 2 ? versions[1] : '';
|
|
|
yoho.app_version = yoho.app_version || req.query.app_version || '';
|
|
|
if (yoho.app_version) {
|
|
|
yoho.app_version = _.toString(yoho.app_version);
|
|
|
arrs = yoho.app_version.split('.');
|
|
|
if (arrs.length > 2) {
|
|
|
if (arrs[0] && +arrs[0] < 4) {
|
|
|
isNewVersion = false;
|
|
|
} else if (arrs[1] && +arrs[1] < 9) {
|
|
|
isNewVersion = false;
|
|
|
} else if (arrs[2] && +arrs[2] <= 0) {
|
|
|
isNewVersion = false;
|
|
|
} else {
|
|
|
isNewVersion = true;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
yoho.isSupportStudent = !yoho.isApp || version;
|
|
|
yoho.isSupportStudent = !yoho.isApp || isNewVersion;
|
|
|
yoho.http = 'http:';
|
|
|
if (isProduction) {
|
|
|
yoho.http = 'https:';
|
...
|
...
|
@@ -117,37 +132,19 @@ const getPlatForm = (req) => { |
|
|
|
|
|
yoho.isStudent = data.data && data.data.vip_info && data.data.vip_info.is_student ? true : false;
|
|
|
|
|
|
// console.log(yoho);
|
|
|
// yoho.isStudent = false;
|
|
|
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) => {
|
|
|
let code = 'a83b7d55324fb65f96c1f85a3387ebd8';
|
|
|
let uid = req.__USER__.uid;
|
|
|
let options;
|
|
|
let noLoginUrl = helpers.urlFormat('/activity/student/register') + '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student"}}}';
|
|
|
|
|
|
|
|
|
|
...
|
...
|
@@ -185,25 +182,16 @@ exports.index = (req, res, next) => { |
|
|
}
|
|
|
});
|
|
|
if (coupons && coupons.data) {
|
|
|
coupons.link = link && link.data ? link.data[0].url + (req.__USER__.isApp ? '&app_version=1' : '') : '';
|
|
|
coupons.link = link && link.data ? link.data[0].url + (req.__USER__.isApp ? '&app_version=' + req.__USER__.app_version : '') : '';
|
|
|
coupons.data = (coupons.data || []).map((item) => {
|
|
|
// let url = item.image.url;
|
|
|
couponids.push(item.couponID);
|
|
|
|
|
|
if (!req.__USER__.isLogin) {
|
|
|
item.image.url = 'http://m.yohobuy.com/activity/student/register?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http://m.yohobuy.com/activity/student"}}}';
|
|
|
}
|
|
|
|
|
|
// if (item.image.url.indexOf('?') === -1) {
|
|
|
// item.image.url += '?';
|
|
|
// if (!req.__USER__.isLogin) {
|
|
|
// url = 'http://m.yohobuy.com/activity/student/register?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http://m.yohobuy.com/activity/student"}}}';
|
|
|
// }
|
|
|
//
|
|
|
//
|
|
|
// 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);
|
|
|
// item.image.noLoginUrl=url;
|
|
|
return item;
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -242,7 +230,10 @@ exports.index = (req, res, next) => { |
|
|
isLogin: req.__USER__.isLogin,
|
|
|
title: '有货学生专享优惠',
|
|
|
http: req.__USER__.http,
|
|
|
uid: req.__USER__.uid
|
|
|
uid: req.__USER__.uid,
|
|
|
app_version: req.__USER__.app_version,
|
|
|
isAppNoLogin: req.__USER__.isApp && !req.__USER__.isLogin,
|
|
|
noLoginUrl: noLoginUrl
|
|
|
};
|
|
|
if (!req.__USER__.isApp) {
|
|
|
options.pageHeader = headerModel.setNav({
|
...
|
...
|
@@ -261,7 +252,7 @@ exports.index = (req, res, next) => { |
|
|
}
|
|
|
} else {
|
|
|
// no login
|
|
|
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/register","antarget":"1"}}}';
|
|
|
}
|
|
|
} else {
|
|
|
if (options.isLogin) {
|
...
|
...
|
@@ -350,15 +341,20 @@ exports.verifystudent = (req, res, next) => { |
|
|
Promise.all([verifiedStudentTotal(), vip(), verifyStudent(uid, params.college_name, params.education_degree, params.enrollment_year, params.token)])
|
|
|
.then((datas) => {
|
|
|
let isverify = false,
|
|
|
prompt = '你的学校信息未通审核';
|
|
|
prompt = '您的学校信息未通过审核';
|
|
|
|
|
|
if (datas[2].code === 200) {
|
|
|
if (datas[2].data.isStudent === 1) {
|
|
|
isverify = true;
|
|
|
prompt = datas[2].data.prompt;
|
|
|
if (datas[2].code === 200) {
|
|
|
if (datas[2].data.isStudent === 1) {
|
|
|
isverify = true;
|
|
|
prompt = datas[2].data.prompt;
|
|
|
}
|
|
|
} else {
|
|
|
prompt = datas[2].message;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
prompt = datas[2].message;
|
|
|
prompt = '认证失败';
|
|
|
}
|
|
|
datas[1].data.product_list = datas[1].data.product_list.map(function(value) {
|
|
|
value.goodsId = value.goods_list[0].goods_id;
|
...
|
...
|
@@ -375,7 +371,8 @@ exports.verifystudent = (req, res, next) => { |
|
|
isLogin: user.data && user.data.vip_info && user.data.vip_info.is_student ? true : false,
|
|
|
title: '学生身份认证',
|
|
|
http: req.__USER__.http,
|
|
|
uid: req.__USER__.uid
|
|
|
uid: req.__USER__.uid,
|
|
|
app_version: req.__USER__.app_version
|
|
|
});
|
|
|
}).catch(next);
|
|
|
|
...
|
...
|
|