Authored by zhangxiaoru

认证

... ... @@ -11,85 +11,80 @@ const _ = require('lodash');
const productProcess = require(`${utils}/product-process`);
const getResource = code => {
return serviceApi.get('operations/api/v5/resource/get', {
content_code: code,
platform: 'iphone'
});
};
const vip = (limit) => {
return api.get('', {
method: 'app.student.vip',
limit: limit || 60
});
};
const verifiedStudentTotal = () => {
return api.get('', {
method: 'app.student.verifiedStudentTotal'
});
};
const getProvince = () => {
return api.get('', {
method: 'app.studentMarket.getAddressList'
}, {
cache: true
});
};
const getSchool = code => {
return api.get('', {
method: 'app.studentMarket.getSchoolInfoList',
areaCode: code
});
};
const getEducationLevelList = () => {
return api.get('', {
method: 'app.studentMarket.getEducationLevelList'
});
};
// const getResource = code => {
// return serviceApi.get('operations/api/v5/resource/get', {
// content_code: code,
// platform: 'iphone'
// });
// };
// const verifiedStudentTotal = () => {
// return api.get('', {
// method: 'app.student.verifiedStudentTotal'
// });
// };
// const getProvince = () => {
// return api.get('', {
// method: 'app.studentMarket.getAddressList'
// }, {
// cache: true
// });
// };
// const getSchool = code => {
// return api.get('', {
// method: 'app.studentMarket.getSchoolInfoList',
// areaCode: code
// });
// };
// const getEducationLevelList = () => {
// return api.get('', {
// method: 'app.studentMarket.getEducationLevelList'
// });
// };
const userAcquireStatus = (uid, couponIds) => {
return api.get('', {
method: 'app.coupons.userAcquireStatus',
uid: uid,
couponIds: couponIds
});
};
const verifyStudent = (uid, collegename, educationdegree, enrollmentyear) => {
return api.get('', {
method: 'app.student.verifyStudent',
uid: uid,
client_type: 'h5',
college_name: collegename,
enrollment_year: enrollmentyear,
education_degree: educationdegree
});
};
const verifyIdentity = (uid, certno, name, pageurl) => {
return api.get('', {
method: 'app.student.verifyIdentity',
uid: uid,
client_type: 'h5',
cert_no: certno,
name: name,
page_url: pageurl
});
};
const getUser = (uid) => {
if (!uid) {
return Promise.resolve({
code: 200,
data: {}
});
}
return api.get('', {
method: 'app.passport.profile',
uid: uid
}, {
cache: true
});
};
};//yao
// const verifyStudent = (uid, collegename, educationdegree, enrollmentyear) => {
// return api.get('', {
// method: 'app.student.verifyStudent',
// uid: uid,
// client_type: 'h5',
// college_name: collegename,
// enrollment_year: enrollmentyear,
// education_degree: educationdegree
// });
// };
// const verifyIdentity = (uid, certno, name, pageurl) => {
// return api.get('', {
// method: 'app.student.verifyIdentity',
// uid: uid,
// client_type: 'h5',
// cert_no: certno,
// name: name,
// page_url: pageurl
// });
// };
// const getUser = (uid) => {
// if (!uid) {
// return Promise.resolve({
// code: 200,
// data: {}
// });
// }
// return api.get('', {
// method: 'app.passport.profile',
// uid: uid
// }, {
// cache: true
// });
// };
/**
* 商品
* 查询商品
* @param id
* @returns {*}
*/
... ... @@ -102,7 +97,6 @@ const _getRelatedData = (idList) => {
let goods = [];
if (result && result.code === 200) {
console.log(result);
goods = productProcess.processProductList(result.data.product_list);
... ... @@ -112,67 +106,67 @@ const _getRelatedData = (idList) => {
return {};
}
});
};
/* 获取用户或者环境相关数据*/
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 isNewVersion = false;
const isProduction = process.env.NODE_ENV === 'production';
// console.log(req.get('User-Agent'));
// console.log(req.query.uid);
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);
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;
// }
// }
if (arrs[0] >= 5) {
isNewVersion = true;
} else if (+arrs[0] === 4 && +arrs[1] === 9 && +arrs[2] > 0) {
isNewVersion = true;
}
}
yoho.isSupportStudent = !yoho.isApp || isNewVersion;
yoho.http = 'http:';
if (isProduction) {
yoho.http = 'https:';
}
yoho.uid = uids && uids.length === 2 ? uids[1] : ''; // 8041246
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.data.vip_info && data.data.vip_info.is_student ? true : false;
// yoho.isStudent = false;
// console.log(yoho);
return yoho;
})();
};
};//yao
// /* 获取用户或者环境相关数据*/
// 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 isNewVersion = false;
// const isProduction = process.env.NODE_ENV === 'production';
// // console.log(req.get('User-Agent'));
// // console.log(req.query.uid);
// 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);
// 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;
// // }
// // }
// if (arrs[0] >= 5) {
// isNewVersion = true;
// } else if (+arrs[0] === 4 && +arrs[1] === 9 && +arrs[2] > 0) {
// isNewVersion = true;
// }
// }
// yoho.isSupportStudent = !yoho.isApp || isNewVersion;
// yoho.http = 'http:';
// if (isProduction) {
// yoho.http = 'https:';
// }
// yoho.uid = uids && uids.length === 2 ? uids[1] : ''; // 8041246
// 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.data.vip_info && data.data.vip_info.is_student ? true : false;
// // yoho.isStudent = false;
// // console.log(yoho);
// return yoho;
// })();
// };
exports.index = (req, res, next) => {
let code = '50b995e190ff8cfe52989972a4943b06';
... ... @@ -238,7 +232,10 @@ exports.index = (req, res, next) => {
return item;
});
coupons.data = coupons.data.slice(0, 2);
if (coupons.data.length > 2) {
coupons.data = coupons.data.slice(0, 2);
}
}
if (studentGoods && studentGoods.data) {
... ... @@ -277,7 +274,7 @@ exports.index = (req, res, next) => {
app_version: req.__USER__.app_version,
isAppNoLogin: req.__USER__.isApp && !req.__USER__.isLogin,
noLoginUrl: noLoginUrl,
page: 'student',
page: 'student-market',
showDownloadApp: true
};
if (!req.__USER__.isApp) {
... ... @@ -291,7 +288,7 @@ exports.index = (req, res, next) => {
if (options.isApp) {
if (options.isLogin) {
if (options.isStudent) {
options.loginUrl = false;
//options.loginUrl = false;
} else {
options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register"}}';
}
... ... @@ -302,7 +299,7 @@ exports.index = (req, res, next) => {
} else {
if (options.isLogin) {
if (options.isStudent) {
options.loginUrl = false;
//options.loginUrl = false;
}
}
}
... ... @@ -310,373 +307,168 @@ exports.index = (req, res, next) => {
// console.log(options);
res.render('student-market', options);
});
// return userAcquireStatus(uid, couponids.join(',')).then((cous) => {
// coupons.data = _.get(coupons, 'data', []).map((item)=>{
// item.status = 1;
// (cous.data || []).forEach((it) => {
// if (+it.couponId === +item.couponID) {
// item.hasNum = it.hasNum;
// item.status = it.status;
// }
// });
// item.couponID = crypto.encryption('yoho9646abcdefgh', item.couponID);
// return item;
// });
// // console.log(datas[1]);
// // 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}}}`;
// // return value;
// // });
// options = {
// isApp: req.__USER__.isApp,
// // goods: datas[1].data.product_list,
// banner: banner,
// icons: icons,
// coupons: coupons,
// activities: activities,
// isStudent: req.__USER__.isStudent,
// isSupportStudent: req.__USER__.isSupportStudent,
// isLogin: req.__USER__.isLogin,
// title: '有货学生专享权益',
// http: req.__USER__.http,
// uid: req.__USER__.uid,
// app_version: req.__USER__.app_version,
// isAppNoLogin: req.__USER__.isApp && !req.__USER__.isLogin,
// noLoginUrl: noLoginUrl,
// page: 'student',
// showDownloadApp: true
// };
// if (!req.__USER__.isApp) {
// options.pageHeader = headerModel.setNav({
// navTitle: options.title,
// navBtn: true
// });
// }
// options.loginUrl = '//m.yohobuy.com/activity/student/register';
// if (options.isApp) {
// if (options.isLogin) {
// if (options.isStudent) {
// options.loginUrl = false;
// } else {
// options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register"}}';
// }
// } else {
// // no login
// 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) {
// if (options.isStudent) {
// options.loginUrl = false;
// }
// }
// }
// // console.log(options);
// res.render('student-market', options);
// });
});
// Promise.all([getResource(code), vip()]).then(datas => {
// let coupons,
// activities,
// banner,
// icons,
// link,
// // url,
// // param,
// couponids = [];
// (datas[0].data || []).forEach((item) => {
// switch (item.template_name) {
// case 'getCoupon':
// coupons = item;
// break;
// case 'image_list':
// activities = item;
// break;
// case 'focus':
// banner = item;
// break;
// case 'recommend_content_five':
// icons = item;
// break;
// case 'link':
// link = item;
// break;
// default:
// // other = item;
// break;
// }
// });
// if (coupons && coupons.data) {
// 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) {
// // url = 'http://m.yohobuy.com/activity/student/register?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"http://m.yohobuy.com/activity/student"}}}';
// // }
// //
// // item.image.noLoginUrl=url;
// return item;
// });
// coupons.data = coupons.data.slice(0, 2);
// }
// return userAcquireStatus(uid, couponids.join(',')).then((cous) => {
// coupons.data = _.get(coupons, 'data', []).map((item)=>{
// item.status = 1;
// (cous.data || []).forEach((it) => {
// if (+it.couponId === +item.couponID) {
// item.hasNum = it.hasNum;
// item.status = it.status;
// }
// });
// item.couponID = crypto.encryption('yoho9646abcdefgh', item.couponID);
// return item;
// });
// // console.log(datas[1]);
// 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}}}`;
// return value;
// });
// options = {
// isApp: req.__USER__.isApp,
// goods: datas[1].data.product_list,
// banner: banner,
// icons: icons,
// coupons: coupons,
// activities: activities,
// isStudent: req.__USER__.isStudent,
// isSupportStudent: req.__USER__.isSupportStudent,
// isLogin: req.__USER__.isLogin,
// title: '有货学生专享权益',
// http: req.__USER__.http,
// uid: req.__USER__.uid,
// app_version: req.__USER__.app_version,
// isAppNoLogin: req.__USER__.isApp && !req.__USER__.isLogin,
// noLoginUrl: noLoginUrl,
// page: 'student',
// showDownloadApp: true
// };
// if (!req.__USER__.isApp) {
// options.pageHeader = headerModel.setNav({
// navTitle: options.title,
// navBtn: true
// });
// }
// options.loginUrl = '//m.yohobuy.com/activity/student/register';
// if (options.isApp) {
// if (options.isLogin) {
// if (options.isStudent) {
// options.loginUrl = false;
// } else {
// options.loginUrl = options.loginUrl + '?openby:yohobuy={"action":"go.h5","params":{"islogin":"N","url":"' + req.__USER__.http + '//m.yohobuy.com/activity/student/register"}}';
// }
// } else {
// // no login
// 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) {
// if (options.isStudent) {
// options.loginUrl = false;
// }
// }
// }
// // console.log(options);
// res.render('student-market', options);
// });
// }).catch(next);
};
exports.province = (req, res, next) => {
getProvince().then((result) => {
res.json(result);
}).catch(next);
};
exports.register = (req, res, next) => {
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) {
refer = '/activity/student?uid=' + req.__USER__.uid;// 所有认证过的,都跳转学生首页
res.redirect(helpers.urlFormat(refer));
} else {
res.render('register', {
title: '认证信息填写',
isApp: req.__USER__.isApp,
count: arr[0].data,
educations: arr[1].data,
educationsStr: JSON.stringify(arr[1].data),
years: years,
yearsStr: JSON.stringify(years),
module: 'activity',
page: 'register',
http: req.__USER__.http
});
}
}).catch(next);
};
exports.school = (req, res, next) => {
let code = req.query.code;
getSchool(code).then((result) => {
res.json(result);
}).catch(next);
};
exports.verifyidentity = (req, res, next) => {
// let uid=req.user.id;
let params = req.body;
let uid = req.__USER__.uid;
let url = 'http://m.yohobuy.com/activity/student/verify?' +
queryString.stringify({
college_name: params.college_name,
education_degree: params.education_degree,
enrollment_year: params.enrollment_year,
uid: req.__USER__.isApp ? uid : '',
}) + '&';
verifyIdentity(uid, params.cert_no, params.name, url).then((result) => {
res.json(result);
}).catch(next);
};
exports.verifystudent = (req, res, next) => {
let params = req.query;
let uid = req.__USER__.uid;
Promise.all([verifiedStudentTotal(), vip(), verifyStudent(uid, params.college_name, params.education_degree, params.enrollment_year, params.token)])
.then((datas) => {
let isverify = false,
prompt = '您的学校信息未通过审核';
if (datas[2].code === 200) {
if (datas[2].data.isStudent === 1) {
isverify = true;
prompt = datas[2].data.prompt;
}
} else {
if (datas[2].code === 500) {
prompt = '请重新认证!';
} else {
prompt = datas[2].message;
}
}
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}}}`;
return value;
});
return getUser(uid).then((user) => {
res.render('verify', {
isApp: req.__USER__.isApp,
count: datas[0].data,
goods: datas[1].data.product_list,
isverify: isverify,
prompt: prompt,
isLogin: user.data && user.data.vip_info && user.data.vip_info.is_student ? true : false,
title: '学生身份认证',
http: req.__USER__.http,
uid: req.__USER__.uid,
app_version: req.__USER__.app_version
});
}).catch(next);
}).catch(next);
});
};
exports.detail = (req, res) => {
let type = req.params.type,
options;
if (type === 'renzhen') {
options = {
title: '认证协议',
isRenZhen: true
};
} else {
options = {
title: '更多学生权益',
isQuanYi: true
};
}
options.isApp = req.__USER__.isApp;
res.render('detail', options);
};
exports.isLogin = (req, res, next) => {
// let refer = req.cookies.refer;
let url = req.get('referer') || '/activity/student/register';
getPlatForm(req).then((yoho)=>{
if (yoho.uid) {
req.__USER__ = yoho;
next();
return;
}
// refer = decodeURI(req.cookies.refer)||req.get("refer");
//
// if (refer) {
// refer = decodeURI(req.cookies.refer)||req.get("refer");
// } else {
// refer = '/activity/student/register';
// }
if (req.path === '/student/register' && !yoho.isStudent) {
url = '/activity/student/register';
}
res.redirect(helpers.urlFormat('/signin.html', {
refer: url
}));
}).catch(next);
};
exports.getUser = (req, res, next)=>{
getPlatForm(req).then((yoho)=>{
req.__USER__ = yoho;
next();
}).catch(next);
};
// exports.province = (req, res, next) => {
// getProvince().then((result) => {
// res.json(result);
// }).catch(next);
// };
// exports.register = (req, res, next) => {
// 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) {
// refer = '/activity/student-market?uid=' + req.__USER__.uid;// 所有认证过的,都跳转学生首页
// res.redirect(helpers.urlFormat(refer));
// } else {
// res.render('register', {
// title: '认证信息填写',
// isApp: req.__USER__.isApp,
// count: arr[0].data,
// educations: arr[1].data,
// educationsStr: JSON.stringify(arr[1].data),
// years: years,
// yearsStr: JSON.stringify(years),
// module: 'activity',
// page: 'register',
// http: req.__USER__.http
// });
// }
// }).catch(next);
// };
// exports.school = (req, res, next) => {
// let code = req.query.code;
// getSchool(code).then((result) => {
// res.json(result);
// }).catch(next);
// };
// exports.verifyidentity = (req, res, next) => {
// // let uid=req.user.id;
// let params = req.body;
// let uid = req.__USER__.uid;
// let url = 'http://m.yohobuy.com/activity/student/verify?' +
// queryString.stringify({
// college_name: params.college_name,
// education_degree: params.education_degree,
// enrollment_year: params.enrollment_year,
// uid: req.__USER__.isApp ? uid : '',
// }) + '&';
// verifyIdentity(uid, params.cert_no, params.name, url).then((result) => {
// res.json(result);
// }).catch(next);
// };
// exports.verifystudent = (req, res, next) => {
// let params = req.query;
// let uid = req.__USER__.uid;
// Promise.all([verifiedStudentTotal(), vip(), verifyStudent(uid, params.college_name, params.education_degree, params.enrollment_year, params.token)])
// .then((datas) => {
// let isverify = false,
// prompt = '您的学校信息未通过审核';
// if (datas[2].code === 200) {
// if (datas[2].data.isStudent === 1) {
// isverify = true;
// prompt = datas[2].data.prompt;
// }
// } else {
// if (datas[2].code === 500) {
// prompt = '请重新认证!';
// } else {
// prompt = datas[2].message;
// }
// }
// 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}}}`;
// return value;
// });
// return getUser(uid).then((user) => {
// res.render('verify', {
// isApp: req.__USER__.isApp,
// count: datas[0].data,
// goods: datas[1].data.product_list,
// isverify: isverify,
// prompt: prompt,
// isLogin: user.data && user.data.vip_info && user.data.vip_info.is_student ? true : false,
// title: '学生身份认证',
// http: req.__USER__.http,
// uid: req.__USER__.uid,
// app_version: req.__USER__.app_version
// });
// }).catch(next);
// }).catch(next);
// };
// exports.detail = (req, res) => {
// let type = req.params.type,
// options;
// if (type === 'renzhen') {
// options = {
// title: '认证协议',
// isRenZhen: true
// };
// } else {
// options = {
// title: '更多学生权益',
// isQuanYi: true
// };
// }
// options.isApp = req.__USER__.isApp;
// res.render('detail', options);
// };
// exports.isLogin = (req, res, next) => {
// // let refer = req.cookies.refer;
// let url = req.get('referer') || '/activity/student/register';
// getPlatForm(req).then((yoho)=>{
// if (yoho.uid) {
// req.__USER__ = yoho;
// next();
// return;
// }
// // refer = decodeURI(req.cookies.refer)||req.get("refer");
// //
// // if (refer) {
// // refer = decodeURI(req.cookies.refer)||req.get("refer");
// // } else {
// // refer = '/activity/student/register';
// // }
// if (req.path === '/student/register' && !yoho.isStudent) {
// url = '/activity/student/register';
// }
// res.redirect(helpers.urlFormat('/signin.html', {
// refer: url
// }));
// }).catch(next);
// };
// exports.getUser = (req, res, next)=>{
// getPlatForm(req).then((yoho)=>{
// req.__USER__ = yoho;
// next();
// }).catch(next);
// };
... ...
... ... @@ -20,19 +20,11 @@
</section>
{{/icons}}
{{#loginUrl}}
<div class='sm-layout'>
{{#if @root.isSupportStudent}}
快来认证吧,认证通过即可享受专属优惠!
{{else}}
请升级最新APP版本,完成认证
{{/if}}
{{#if @root.isSupportStudent}}
<a class='s-renzhen' href='{{.}}'>立即认证</a>
{{/if}}
<a class='s-renzhen' href='{{loginUrl}}'>立即认证</a>
</div>
{{/loginUrl}}
{{#coupons}}
<section class='s-section clearfix' data-template-id="{{template_id}}">
... ...
var $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
lazyLoad = require('yoho-jquery-lazyload'),
fastclick = require('yoho-fastclick'),
tip = require('../plugin/tip'),
dialog = require('../plugin/dialog'),
Hammer = require('yoho-hammer');
var _weChatInterface = '//m.yohobuy.com/life/getSignPackage',
wx = window.wx,
C_ID,
getChannel;
require('../common');
require('../common/footer');
// 根据ua判断页头
(function uaHeader() {
var UALIST = ['MicroMessenger', 'QQ/', 'Weibo'],
UA = navigator.userAgent,
i;
for (i = 0; i < UALIST.length; i++) {
if (UA.indexOf(UALIST[i]) > -1) {
$('#yoho-header').remove();
return;
}
}
}());
getChannel = function() {
var name = window.cookie('_Channel');
return {
boys: 1,
girls: 2,
kids: 3,
lifestyle: 4
}[name] || 1;
};
C_ID = getChannel();
function uuid() {
var s = [];
var hexDigits = '0123456789abcdef';
var id = '';
var i = 0;
for (i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = '4'; // bits 12-15 of the time_hi_and_version field to 0010
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
s[8] = s[13] = s[18] = s[23] = '-';
id = s.join('');
return id;
}
fastclick.attach(document.body);
lazyLoad($('img.lazy'));
// 头部banner轮播
if ($('.banner-swiper').find('li').size() > 1) {
new Swiper('.banner-swiper', {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
autoplayDisableOnInteraction: false,
paginationClickable: true,
slideElement: 'li',
pagination: '.banner-top .pagination-inner'
});
}
// 获取url中的参数
function getUrlParam(name) {
// 构造一个含有目标参数的正则表达式对象
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
// 匹配目标参数
var r = window.location.search.substr(1).match(reg);
// 返回参数值
if (r !== null) {
return r[2];
}
return null;
}
$('.on-lingqu', 'div.main-right-use').on('click', function() {
var $curDom = $(this),
req = '',
href = '',
a = '';
if (getUrlParam('app_version')) {
req += '&app_version=' + getUrlParam('app_version');
}
if (getUrlParam('uid')) {
req += '&uid=' + getUrlParam('uid');
}
if (!$curDom.hasClass('received')) {
$.ajax({
url: '//m.yohobuy.com/coupon/receiveCoupon?code=a83b7d55324fb65f96c1f85a3387ebd8' + req,
data: {
couponID: $curDom.parents('.coupon-floor').attr('coupon-id')
},
dataType: 'json',
success: function(data) {
var msg = data.msg,
status = data.status,
newUrl = '//m.yohobuy.com/signin.html?refer=' + location.href;
if (data.isApp === true) {
newUrl = data.url;
}
if (data.noLogin === true) {
location.href = newUrl;
} else {
if (status) {
href = $curDom.parent('.main-right-use').attr('href');
$curDom.parent('.main-right-use').wrap('<a class=\'main-right-use\' href=' + href + '></a>');
a = $curDom.parent('.main-right-use').parent('a');
a.html('<span class="received"></span>');
tip.show('领券成功');
} else {
tip.show(msg);
}
}
},
error: function() {
tip.show('网络异常!');
}
});
return false;
}
});
/**
* 微信分享
*/
if (typeof wx !== 'undefined') {
$.getJSON(_weChatInterface + '?pageurl=' +
encodeURIComponent(location.href.split('#')[0]) + '&callback=?',
function(json) {
var _appId,
_timestamp,
_nonceStr,
_signature;
if (json) {
_appId = json.appId.toString();
_timestamp = json.timestamp;
_nonceStr = json.nonceStr.toString();
_signature = json.signature.toString();
wx.config({
debug: false,
appId: _appId,
timestamp: _timestamp,
nonceStr: _nonceStr,
signature: _signature,
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'hideMenuItems',
'showMenuItems',
'hideAllNonBaseMenuItem',
'showAllNonBaseMenuItem',
'translateVoice',
'startRecord',
'stopRecord',
'onRecordEnd',
'playVoice',
'pauseVoice',
'stopVoice',
'uploadVoice',
'downloadVoice',
'chooseImage',
'previewImage',
'uploadImage',
'downloadImage',
'getNetworkType',
'openLocation',
'getLocation',
'hideOptionMenu',
'showOptionMenu',
'closeWindow',
'scanQRCode',
'chooseWXPay',
'openProductSpecificView',
'addCard',
'chooseCard',
'openCard'
]
});
}
});
wx.ready(function() {
var shareData = {
title: 'YOHO!BUY有货【学生】专享福利大派送!4大特权享不停!',
desc: '全球1000+潮流品牌每日上新!一起来YOHO!玩潮流!',
imgUrl: 'http://img12.static.yhbimg.com/brandCertificate/2016/08/10/14/0204d441c737c687fc418b2372d0aba8be.png',
link: 'https://m.yohobuy.com/activity/student'
};
// 分享给朋友
wx.onMenuShareAppMessage(shareData);
// 分享到朋友圈
wx.onMenuShareTimeline(shareData);
// 分享到QQ
wx.onMenuShareQQ(shareData);
// 分享到微博
wx.onMenuShareWeibo(shareData);
});
}
setTimeout(function() {
var len = $('.good-info', '.goods-list').length;
var ids = [];
var check = location.pathname.indexOf('quanyi') === -1;
$('.good-info', '.goods-list').each(function() {
var goodids = $(this).find('.good-thumb').attr('href').match(/"product_skn":([^}]+)/, 'g');
var goodid = goodids && goodids.length === 2 ? goodids[1] : '';
ids.push(goodid);
});
if (check && window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_STUDENT_VIP_GDS_LIST',
param: JSON.stringify({
C_ID: C_ID,
PRD_NUM: len,
PRD_ID: ids.join(','),
ACTION_ID: 0,
SORT_TYPE: 4,
REC_ID: uuid(40) + '0000'
})
}, true);
}
if ($('.s-verify-fail').size()) {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_STUDENT_ATTCT_RESULT',
param: JSON.stringify({
C_ID: C_ID,
SRC_ID: 5,
ATTCT_RES: 2,
FAILURE_CAUSE: $('.s-verify-fail').attr('prompt')
})
}, true);
}
} else if ($('.s-verify-success').size()) {
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo({
op: 'YB_STUDENT_ATTCT_RESULT',
param: JSON.stringify({
C_ID: C_ID,
SRC_ID: 5,
ATTCT_RES: 1,
FAILURE_CAUSE: '',
ATTCT_INFO: JSON.parse(localStorage.STUDENTCOOKIES)
})
}, true);
}
} else {
// 埋点 学生营销宣传首页
// if (window._yas && window._yas.sendCustomInfo) {
// window._yas.sendCustomInfo({
// op: 'YB_STUDENT_HOME',
// param: JSON.stringify({
// C_ID: C_ID
// }),
// }, true);
// }
}
}, 3000);
$('.swiper-slide', '.banner-top').click(function() {
var options;
var url = $(this).find('a').attr('href');
var index = $(this).index();
var tid = $(this).parents('.s-section').data('template-id');
options = {
op: 'YB_STUDENT_VIP_FLR',
param: JSON.stringify({
C_ID: C_ID,
F_ID: tid || 1,
F_NAME: '焦点图',
F_URL: encodeURIComponent(url),
F_INDEX: 1,
I_INDEX: index
})
};
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo(options, true);
}
// return false;
});
// 学生活动页楼层埋点
$('.s-activity, .main-left, .s-quan, .iconfont', '.s-section').click(function() {
var options;
var url = $(this).attr('href');
var index = $(this).index();
var tid = $(this).parents('.s-section').data('template-id');
var obj = {
's-activity': {
fname: '学生专属活动',
findex: 4,
iindex: index
},
'more iconfont': {
fname: '领券中心',
findex: 3,
iindex: 0
},
'main-left': {
fname: '领券中心',
findex: 3,
iindex: $(this).parent().parent().index()
},
'more s-quan': {
fname: '学生权益',
findex: 2,
iindex: 0
}
}[$(this).attr('class')];
options = {
op: 'YB_STUDENT_VIP_FLR',
param: JSON.stringify({
C_ID: C_ID,
F_ID: tid,
F_NAME: obj.fname,
F_URL: encodeURIComponent(url),
F_INDEX: obj.findex,
I_INDEX: obj.iindex
})
};
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo(options, true);
}
});
$('.good-info', '.goods-list').click(function() {
var options;
var index = $(this).index();
var goodids = $(this).find('.good-thumb').attr('href').match(/"product_skn":([^}]+)/, 'g');
var goodid = goodids && goodids.length === 2 ? goodids[1] : '';
options = {
op: 'YB_STUDENT_VIP_GDS_LIST',
param: JSON.stringify({
C_ID: C_ID,
PRD_NUM: Number(index) + 1,
PRD_ID: goodid,
ACTION_ID: 1,
REC_ID: uuid(40) + '0000'
})
};
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo(options, true);
}
});
$('.s-renzhen').click(function() {
var options = {
op: 'YB_STUDENT_ATTCT_INFO',
param: JSON.stringify({
C_ID: C_ID,
SRC_ID: 1
})
};
if (window._yas && window._yas.sendCustomInfo) {
window._yas.sendCustomInfo(options, true);
}
});
$('.dialog-wrapper').addClass('s-dialog-wrapper');
$('.s-dialog').on('click', function() {
var text = [{
dialogText: '<h2>权益1: 新品立享9折</h2><p>1、学生购买指定原价新品时,可立即享受9折优惠,与VIP折扣不可同时享受</p>'
}, {
dialogText: '<h2>权益2: 每1元返1个有货币</h2><p>1、学生购买指定商品时,以商品的实际成交金额计算,每1元返1个有货币;</p>' +
'<p>2、返有货币时间:确认收货7日后,系统将自动将对应数量的有货币返至购买账户;</p>' +
'<p>3、有货币有效期:获得当日至次年12月31日,逾期自动作废;</p>' +
'<p>4、查看有货币:登录后,点击“个人中心”在“我的有货币”中可以查看有货币余额及明细。</p>'
}, {
dialogText: '<h2>权益3: 免单抽奖</h2><p>1、每月将在累计购物金额最高的学校中,抽取3名幸运学生用户,获得免单资格;</p>' +
'<p>2、免单用户名单将在每月第1个工作日公布在有货微信公众号上,可关注【有货YOHOBUY】;</p>' +
'<p>3、免单用户将在中奖次日获得与实付金额等额的现金券,使用时间:中奖当月。</p>'
}, {
dialogText: '<h2>权益4: 学生专享活动</h2><p>1、每月不定期的开展学生专享活动,可打开有货APP推送,及时查收学生专享活动通知。</p>'
}];
var dialogBoxHammer, dialogRightBtn;
dialog.showDialog({
student: true,
dialogText: text[$(this).index()].dialogText,
hasFooter: {
rightBtnText: '我知道了'
}
}, function() {
$('body').css({
overflow: '',
position: ''
});
dialog.hideDialog();
}, undefined, true);
$('.dialog-content').css({
padding: '0 1.5rem 1rem 1.5rem'
});
$('.dialog-box').css({
'border-radius': '0.25rem',
background: '#fff'
});
$('.dialog-right-btn').css({
border: 'none',
color: '#d0021b'
});
$('body').css({
overflow: 'hidden',
position: 'fixed'
});
dialogBoxHammer = new Hammer(document.getElementsByClassName('dialog-box')[0]);
dialogRightBtn = new Hammer(document.getElementsByClassName('dialog-right-btn')[0]);
dialogBoxHammer.on('tap', function(event) {
event.srcEvent.stopPropagation();
});
dialogRightBtn.on('tap', function(event) {
$('body').css({
overflow: '',
position: ''
});
dialog.hideDialog();
event.preventDefault();
event.srcEvent.stopPropagation();
});
$('.dialog-content').addClass('s-dialog-content');
});
... ...
... ... @@ -11,10 +11,7 @@ var _weChatInterface = '//m.yohobuy.com/life/getSignPackage',
C_ID,
getChannel;
require('../common');
require('../common/footer');
// 根据ua判断页头
(function uaHeader() {
... ...
... ... @@ -32,4 +32,10 @@
padding: 3PX 0;
}
}
.s-dialog {
img {
height: 152px;
}
}
}
... ...