Authored by 周少峰

Merge branch 'feature/studentsTwo'

... ... @@ -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);
};
... ...
... ... @@ -525,5 +525,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,58 @@ exports.userAcquireStatus = (uid, couponIds) => {
return api.get('', finalParams);
};
/**
* 获取学生专享商品列表
* @return
*/
exports.getStudentsProduct = (params) => {
let finalParams = {
method: 'app.student.rebate',
sales: 'Y',
stocknumber: 1,
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;
});
});
}
};
... ...
... ... @@ -115,7 +115,7 @@ exports.stuProducts = (data) => {
data[key].market_price = data[key].sales_price;
delete data[key].sales_price;
if (value.student_price) {
Object.assign(data[key], {forStu: true});
Object.assign(data[key], {for_stu: true});
}
});
return products;
... ...
... ... @@ -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);
});
};
... ...
... ... @@ -103,5 +103,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;
... ...
... ... @@ -448,7 +448,7 @@ $couponDia.on('click', function() {
$rightDia.on('click', function() {
var cont = '<h3 class="dia-title">特权详细说明</h3>' +
'<p>权益1:新品立享9折</p>' +
'<p>学生购买原价新品时,可立即享受9折优惠,与VIP折扣不可同时享受。</p><br>' +
'<p>学生购买指定原价新品时,可立即享受9折优惠,与VIP折扣不可同时享受。</p><br>' +
'<p>权益2:每1元返1个有货币</p>' +
'<p>学生购买指定商品时,以商品的实际成交金额计算,每1元返1个有货币;</p>' +
'<p>返有货币时间:确认收货7日后,系统将自动将对应数量的有货币返至购买账户;</p>' +
... ... @@ -662,7 +662,7 @@ $(function() {
var rightsFirst = '<div class="item-content hide">' +
'<p class="item-title">新品立享9折</p>' +
'<p>学生购买原价新品时,可立即享受9折优惠,与VIP折扣不可同时享受。</p></div>';
'<p>学生购买指定原价新品时,可立即享受9折优惠,与VIP折扣不可同时享受。</p></div>';
var rightsSecond = '<div class="item-content hide">' +
'<p class="item-title">每1元返1个有货币</p>' +
... ... @@ -824,10 +824,12 @@ $(function() {
$('#stuRights .stu-rights-item:eq(0), #stuRights .stu-rights-item:eq(1),' +
'#stuRights .stu-rights-item:eq(2), #stuRights .stu-rights-item:eq(3)').hover(function() {
var content = $(this).find('.item-content');
var gapHeight;
content.removeClass('hide');
let gapHeight = parseInt(content.height(), 10) + 40 - parseInt($(this).height(), 10);
gapHeight = parseInt(content.height(), 10) + 40 - parseInt($(this).height(), 10);
if (gapHeight > 0) {
content.css('margin-top', -(gapHeight) + 'px');
... ...
... ... @@ -116,9 +116,10 @@
.stu-rights-item .item-content {
position: absolute;
top: 0;
min-height: 160px;
padding: 20px;
margin-top: 0;
transition: margin-top 2s linear;
transition: margin-top 2.5s linear;
background: rgba(255,255,255,.95);
}
... ...