Authored by hongweigao

Merge branch 'feature/studentsTwo' into release/5.1

... ... @@ -107,3 +107,19 @@ exports.userAcquireStatus = (req, res, next) => {
}).catch(next);
};
/**
* 学生返币专享页面
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.list = (req, res, next) => {
let resData = {};
studentsModel.getStudentsList(req.query, req.yoho.channel).then(result => {
Object.assign(resData, result);
res.render('list/index', resData);
}).catch(next);
};
... ...
... ... @@ -521,5 +521,7 @@ module.exports = {
getShopDecorator,
getArticleByBrand,
getShopList,
getBrands4Filter
getBrands4Filter,
getProductListOrig,
getSearchCackeKey
};
... ...
... ... @@ -6,6 +6,10 @@
'use strict';
const api = global.yoho.API;
const config = require('../../../config/common');
const searchApi = require('./search-api');
const cache = global.yoho.cache;
const logger = global.yoho.logger;
/**
* 获取完成认证学生总数
... ... @@ -115,3 +119,61 @@ exports.userAcquireStatus = (uid, couponIds) => {
return api.get('', finalParams);
};
/**
* 获取学生专享商品列表
* @return
*/
exports.getStudentsProduct = (params) => {
let finalParams = {
method: 'app.student.rebate',
sales: 'Y',
outlets: 2,
stocknumber: 1,
order: 's_n_desc',
need_filter: 'yes',
limit: 60
};
Object.assign(finalParams, params);
if (!config.useCache) {
return searchApi.getProductListOrig(finalParams);
} else {
let cKey = searchApi.getSearchCackeKey(finalParams);
return cache.get(cKey).catch().then(cdata => {
let hasCache = false;
if (cdata) {
try {
cdata = JSON.parse(cdata);
} catch (e) {
logger.debug('getProductList cache data parse fail.');
}
if (cdata.filter && cdata.standard) {
hasCache = true;
finalParams.need_filter = 'no';
}
}
return searchApi.getProductListOrig(finalParams).then(result => {
if (hasCache && result && result.data) {
Object.assign(result.data, cdata);
} else {
if (result && result.data && result.data.filter) {
cache.set(cKey, Object.assign({}, {
filter: result.data.filter,
standard: result.data.standard
}), 3600);
}
}
return result;
});
});
}
};
... ...
... ... @@ -5,7 +5,7 @@
*/
'use strict';
const utils = '../../../utils';
const api = global.yoho.API;
const queryString = require('querystring');
const _ = require('lodash');
... ... @@ -14,11 +14,13 @@ const studentsApi = require('./students-api');
const stuHandler = require('./students-handler');
const helpers = global.yoho.helpers;
const crypto = global.yoho.crypto;
// const productProcess = require(`${utils}/product-process`);
// const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header');
const serviceApi = global.yoho.ServiceAPI;
const searchApi = require('./search-api');
const productProcess = require(`${utils}/product-process`);
const searchHandler = require('./search-handler');
const needParams = ['query', 'msort', 'misort', 'gender', 'shelveTime'];
// 学生营销资源码
const studentsCode = '989396a17443bf61e3e269702e51ef04'; // h5 a83b7d55324fb65f96c1f85a3387ebd8
... ... @@ -177,3 +179,86 @@ exports.userAcquireStatus = (uid, couponIds) => {
return result;
});
};
/**
* 获取学生返币专享商品列表数据
*/
exports.getStudentsList = (params, channel) => {
let standard = [];
_.forEach(params, (value, key) => {
let s = _.split(key, 'parameter_', 2);
if (s.length > 1) {
standard.push(`${s[1]}_${value}`);
_.unset(params, `${key}`);
}
});
if (standard.length) {
params.standard = standard.join(',');
}
let searchParams = searchHandler.getSearchParams(params);
// 调用接口
let apiMethod = [
headerModel.requestHeaderData(channel),
searchApi.getSortList(Object.assign({}, {msort: '', misort: ''})),
studentsApi.getStudentsProduct(searchParams)
];
return Promise.all(apiMethod).then(result => {
let finalResult = {
module: 'product',
page: 'list',
headerData: Object.assign(result[0].headerData, {
header: true
}),
list: {
leftContent: {}
}
};
// 获取左侧类目数据
if (result[1].code === 200) {
let dps = {};
_.forEach(needParams, (value) => {
if (params[value]) {
dps[value] = params[value];
}
});
finalResult.list = Object.assign(
searchHandler.handlePathNavData(result[1].data.sort, params, 'sort', channel), {
leftContent: searchHandler.handleSortData(result[1].data.sort, dps)
});
}
// 获取商品数据和顶部筛选条件
if (result[2].code === 200) {
//删掉student_price,不让页面显示
_.forEach(result[2].data.product_list, goods => {
delete goods.student_price;
});
Object.assign(finalResult.list, {
filters: searchHandler.handleFilterDataAll(result[2].data, params),
opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
totalCount: result[2].data.total,
footPager: searchHandler.handlePagerData(result[2].data.total, params),
goods: productProcess.processProductList(result[2].data.product_list,
Object.assign({showDiscount: false}, params, {
from: {type: 'list', params: params}
})),
hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
// 最近浏览记录
latestWalk: 6
});
}
finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.list, 'goods'))};
return Object.assign({}, finalResult);
});
};
... ...
... ... @@ -101,5 +101,6 @@ router.get('/students/schoolList', students.schoolList); // 学校地区
router.get('/students/eduLevel', students.eduLevel); // 学校地区
router.get('/students/verify', students.verify); // 身份验证
router.get('/students/userAcquireStatus', students.userAcquireStatus); // 获取优惠券领取状态
router.get('/students/list', students.list); // 获取优惠券领取状态
module.exports = router;
... ...
... ... @@ -16,8 +16,8 @@ module.exports = {
siteUrl: 'http://www.yohobuy.com',
domains: {
favApi: 'http://192.168.102.31:8092/brower',
api: 'http://api-test1.yohops.com:9999/',
service: 'http://service-test1.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
search: 'http://192.168.102.216:8080/yohosearch/'
},
subDomains: {
... ...