...
|
...
|
@@ -8,6 +8,7 @@ const Promise = require('bluebird'); |
|
|
const co = Promise.coroutine;
|
|
|
const headerModel = require('../../../doraemon/models/header'); // 头部model
|
|
|
const _ = require('lodash');
|
|
|
const productProcess = require(`${utils}/product-process`);
|
|
|
|
|
|
|
|
|
const getResource = code => {
|
...
|
...
|
@@ -87,6 +88,32 @@ const getUser = (uid) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 商品
|
|
|
* @param id
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
const _getRelatedData = (idList) => {
|
|
|
return api.get('', {
|
|
|
productSkn: idList,
|
|
|
method: 'h5.product.batch'
|
|
|
}).then((result) => {
|
|
|
|
|
|
let goods = [];
|
|
|
|
|
|
if (result && result.code === 200) {
|
|
|
console.log(result)
|
|
|
|
|
|
goods = productProcess.processProductList(result.data.product_list);
|
|
|
|
|
|
return goods;
|
|
|
} else {
|
|
|
logger.error('推荐商品 cood 不是 200');
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
/* 获取用户或者环境相关数据*/
|
|
|
const getPlatForm = (req) => {
|
|
|
let userAgent = req.get('User-Agent');
|
...
|
...
|
@@ -147,25 +174,30 @@ const getPlatForm = (req) => { |
|
|
})();
|
|
|
};
|
|
|
|
|
|
|
|
|
exports.index = (req, res, next) => {
|
|
|
let code = '989396a17443bf61e3e269702e51ef04';
|
|
|
let code = '50b995e190ff8cfe52989972a4943b06';
|
|
|
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"}}}';
|
|
|
|
|
|
Promise.all([getResource(code), vip()]).then(datas => {
|
|
|
return serviceApi.get('operations/api/v5/resource/get', {
|
|
|
content_code: code,
|
|
|
platform: 'iphone'
|
|
|
}).then((result) => {
|
|
|
|
|
|
let coupons,
|
|
|
activities,
|
|
|
banner,
|
|
|
icons,
|
|
|
link,
|
|
|
studentGoods,
|
|
|
idList = [],
|
|
|
|
|
|
// url,
|
|
|
// param,
|
|
|
couponids = [];
|
|
|
|
|
|
(datas[0].data || []).forEach((item) => {
|
|
|
(result.data || []).forEach((item) => {
|
|
|
switch (item.template_name) {
|
|
|
case 'getCoupon':
|
|
|
coupons = item;
|
...
|
...
|
@@ -182,6 +214,9 @@ exports.index = (req, res, next) => { |
|
|
case 'link':
|
|
|
link = item;
|
|
|
break;
|
|
|
case 'goods':
|
|
|
studentGoods = item;
|
|
|
break;
|
|
|
default:
|
|
|
// other = item;
|
|
|
break;
|
...
|
...
|
@@ -206,10 +241,16 @@ exports.index = (req, res, next) => { |
|
|
coupons.data = coupons.data.slice(0, 2);
|
|
|
}
|
|
|
|
|
|
return userAcquireStatus(uid, couponids.join(',')).then((cous) => {
|
|
|
if (studentGoods && studentGoods.data) {
|
|
|
_.forEach(studentGoods.data, function(obj) {
|
|
|
idList.push(obj.id);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
return Promise.all([userAcquireStatus(uid, couponids.join(',')), _getRelatedData(idList.join(','))]).then(datas => {
|
|
|
coupons.data = _.get(coupons, 'data', []).map((item)=>{
|
|
|
item.status = 1;
|
|
|
(cous.data || []).forEach((it) => {
|
|
|
(datas[0].data || []).forEach((it) => {
|
|
|
|
|
|
if (+it.couponId === +item.couponID) {
|
|
|
item.hasNum = it.hasNum;
|
...
|
...
|
@@ -220,18 +261,9 @@ exports.index = (req, res, next) => { |
|
|
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,
|
|
|
goods: datas[1],
|
|
|
banner: banner,
|
|
|
icons: icons,
|
|
|
coupons: coupons,
|
...
|
...
|
@@ -277,10 +309,210 @@ 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
|
|
|
// });
|
|
|
// }
|
|
|
|
|
|
}).catch(next);
|
|
|
// 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);
|
|
|
};
|
|
|
|
|
|
|
...
|
...
|
|