Authored by hongweigao

Merge branch 'feature/studentsTwo' into release/5.1

@@ -107,3 +107,19 @@ exports.userAcquireStatus = (req, res, next) => { @@ -107,3 +107,19 @@ exports.userAcquireStatus = (req, res, next) => {
107 }).catch(next); 107 }).catch(next);
108 108
109 }; 109 };
  110 +
  111 +
  112 +/**
  113 + * 学生返币专享页面
  114 + * @param {[type]} req [description]
  115 + * @param {[type]} res [description]
  116 + * @return {[type]} [description]
  117 + */
  118 +exports.list = (req, res, next) => {
  119 + let resData = {};
  120 +
  121 + studentsModel.getStudentsList(req.query, req.yoho.channel).then(result => {
  122 + Object.assign(resData, result);
  123 + res.render('list/index', resData);
  124 + }).catch(next);
  125 +};
@@ -521,5 +521,7 @@ module.exports = { @@ -521,5 +521,7 @@ module.exports = {
521 getShopDecorator, 521 getShopDecorator,
522 getArticleByBrand, 522 getArticleByBrand,
523 getShopList, 523 getShopList,
524 - getBrands4Filter 524 + getBrands4Filter,
  525 + getProductListOrig,
  526 + getSearchCackeKey
525 }; 527 };
@@ -6,6 +6,10 @@ @@ -6,6 +6,10 @@
6 'use strict'; 6 'use strict';
7 7
8 const api = global.yoho.API; 8 const api = global.yoho.API;
  9 +const config = require('../../../config/common');
  10 +const searchApi = require('./search-api');
  11 +const cache = global.yoho.cache;
  12 +const logger = global.yoho.logger;
9 13
10 /** 14 /**
11 * 获取完成认证学生总数 15 * 获取完成认证学生总数
@@ -115,3 +119,61 @@ exports.userAcquireStatus = (uid, couponIds) => { @@ -115,3 +119,61 @@ exports.userAcquireStatus = (uid, couponIds) => {
115 119
116 return api.get('', finalParams); 120 return api.get('', finalParams);
117 }; 121 };
  122 +
  123 +
  124 +/**
  125 + * 获取学生专享商品列表
  126 + * @return
  127 + */
  128 +exports.getStudentsProduct = (params) => {
  129 + let finalParams = {
  130 + method: 'app.student.rebate',
  131 + sales: 'Y',
  132 + outlets: 2,
  133 + stocknumber: 1,
  134 + order: 's_n_desc',
  135 + need_filter: 'yes',
  136 + limit: 60
  137 + };
  138 +
  139 + Object.assign(finalParams, params);
  140 +
  141 + if (!config.useCache) {
  142 + return searchApi.getProductListOrig(finalParams);
  143 + } else {
  144 + let cKey = searchApi.getSearchCackeKey(finalParams);
  145 +
  146 + return cache.get(cKey).catch().then(cdata => {
  147 + let hasCache = false;
  148 +
  149 + if (cdata) {
  150 +
  151 + try {
  152 + cdata = JSON.parse(cdata);
  153 + } catch (e) {
  154 + logger.debug('getProductList cache data parse fail.');
  155 + }
  156 +
  157 + if (cdata.filter && cdata.standard) {
  158 + hasCache = true;
  159 + finalParams.need_filter = 'no';
  160 + }
  161 + }
  162 +
  163 + return searchApi.getProductListOrig(finalParams).then(result => {
  164 + if (hasCache && result && result.data) {
  165 + Object.assign(result.data, cdata);
  166 + } else {
  167 + if (result && result.data && result.data.filter) {
  168 + cache.set(cKey, Object.assign({}, {
  169 + filter: result.data.filter,
  170 + standard: result.data.standard
  171 + }), 3600);
  172 + }
  173 + }
  174 +
  175 + return result;
  176 + });
  177 + });
  178 + }
  179 +};
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 */ 5 */
6 6
7 'use strict'; 7 'use strict';
8 - 8 +const utils = '../../../utils';
9 const api = global.yoho.API; 9 const api = global.yoho.API;
10 const queryString = require('querystring'); 10 const queryString = require('querystring');
11 const _ = require('lodash'); 11 const _ = require('lodash');
@@ -14,11 +14,13 @@ const studentsApi = require('./students-api'); @@ -14,11 +14,13 @@ const studentsApi = require('./students-api');
14 const stuHandler = require('./students-handler'); 14 const stuHandler = require('./students-handler');
15 const helpers = global.yoho.helpers; 15 const helpers = global.yoho.helpers;
16 const crypto = global.yoho.crypto; 16 const crypto = global.yoho.crypto;
17 -  
18 -// const productProcess = require(`${utils}/product-process`);  
19 -// const _ = require('lodash');  
20 const headerModel = require('../../../doraemon/models/header'); 17 const headerModel = require('../../../doraemon/models/header');
21 const serviceApi = global.yoho.ServiceAPI; 18 const serviceApi = global.yoho.ServiceAPI;
  19 +const searchApi = require('./search-api');
  20 +
  21 +const productProcess = require(`${utils}/product-process`);
  22 +const searchHandler = require('./search-handler');
  23 +const needParams = ['query', 'msort', 'misort', 'gender', 'shelveTime'];
22 24
23 // 学生营销资源码 25 // 学生营销资源码
24 const studentsCode = '989396a17443bf61e3e269702e51ef04'; // h5 a83b7d55324fb65f96c1f85a3387ebd8 26 const studentsCode = '989396a17443bf61e3e269702e51ef04'; // h5 a83b7d55324fb65f96c1f85a3387ebd8
@@ -177,3 +179,86 @@ exports.userAcquireStatus = (uid, couponIds) => { @@ -177,3 +179,86 @@ exports.userAcquireStatus = (uid, couponIds) => {
177 return result; 179 return result;
178 }); 180 });
179 }; 181 };
  182 +
  183 +/**
  184 + * 获取学生返币专享商品列表数据
  185 + */
  186 +exports.getStudentsList = (params, channel) => {
  187 + let standard = [];
  188 +
  189 + _.forEach(params, (value, key) => {
  190 + let s = _.split(key, 'parameter_', 2);
  191 +
  192 + if (s.length > 1) {
  193 + standard.push(`${s[1]}_${value}`);
  194 + _.unset(params, `${key}`);
  195 + }
  196 + });
  197 +
  198 + if (standard.length) {
  199 + params.standard = standard.join(',');
  200 + }
  201 +
  202 + let searchParams = searchHandler.getSearchParams(params);
  203 +
  204 + // 调用接口
  205 + let apiMethod = [
  206 + headerModel.requestHeaderData(channel),
  207 + searchApi.getSortList(Object.assign({}, {msort: '', misort: ''})),
  208 + studentsApi.getStudentsProduct(searchParams)
  209 + ];
  210 +
  211 + return Promise.all(apiMethod).then(result => {
  212 + let finalResult = {
  213 + module: 'product',
  214 + page: 'list',
  215 + headerData: Object.assign(result[0].headerData, {
  216 + header: true
  217 + }),
  218 + list: {
  219 + leftContent: {}
  220 + }
  221 + };
  222 +
  223 + // 获取左侧类目数据
  224 + if (result[1].code === 200) {
  225 + let dps = {};
  226 +
  227 + _.forEach(needParams, (value) => {
  228 + if (params[value]) {
  229 + dps[value] = params[value];
  230 + }
  231 + });
  232 +
  233 + finalResult.list = Object.assign(
  234 + searchHandler.handlePathNavData(result[1].data.sort, params, 'sort', channel), {
  235 + leftContent: searchHandler.handleSortData(result[1].data.sort, dps)
  236 + });
  237 + }
  238 +
  239 + // 获取商品数据和顶部筛选条件
  240 + if (result[2].code === 200) {
  241 + //删掉student_price,不让页面显示
  242 + _.forEach(result[2].data.product_list, goods => {
  243 + delete goods.student_price;
  244 + });
  245 + Object.assign(finalResult.list, {
  246 + filters: searchHandler.handleFilterDataAll(result[2].data, params),
  247 + opts: searchHandler.handleOptsData(params, result[2].data.total, result[2].data.filter),
  248 + totalCount: result[2].data.total,
  249 + footPager: searchHandler.handlePagerData(result[2].data.total, params),
  250 + goods: productProcess.processProductList(result[2].data.product_list,
  251 + Object.assign({showDiscount: false}, params, {
  252 + from: {type: 'list', params: params}
  253 + })),
  254 + hasNextPage: searchHandler.handleNextPage(params, result[2].data.total),
  255 +
  256 + // 最近浏览记录
  257 + latestWalk: 6
  258 + });
  259 + }
  260 +
  261 + finalResult.criteo = {skn: searchHandler.getCriteo(_.get(finalResult.list, 'goods'))};
  262 + return Object.assign({}, finalResult);
  263 + });
  264 +};
@@ -101,5 +101,6 @@ router.get('/students/schoolList', students.schoolList); // 学校地区 @@ -101,5 +101,6 @@ router.get('/students/schoolList', students.schoolList); // 学校地区
101 router.get('/students/eduLevel', students.eduLevel); // 学校地区 101 router.get('/students/eduLevel', students.eduLevel); // 学校地区
102 router.get('/students/verify', students.verify); // 身份验证 102 router.get('/students/verify', students.verify); // 身份验证
103 router.get('/students/userAcquireStatus', students.userAcquireStatus); // 获取优惠券领取状态 103 router.get('/students/userAcquireStatus', students.userAcquireStatus); // 获取优惠券领取状态
  104 +router.get('/students/list', students.list); // 获取优惠券领取状态
104 105
105 module.exports = router; 106 module.exports = router;
@@ -16,8 +16,8 @@ module.exports = { @@ -16,8 +16,8 @@ module.exports = {
16 siteUrl: 'http://www.yohobuy.com', 16 siteUrl: 'http://www.yohobuy.com',
17 domains: { 17 domains: {
18 favApi: 'http://192.168.102.31:8092/brower', 18 favApi: 'http://192.168.102.31:8092/brower',
19 - api: 'http://api-test1.yohops.com:9999/',  
20 - service: 'http://service-test1.yohops.com:9999/', 19 + api: 'http://api-test3.yohops.com:9999/',
  20 + service: 'http://service-test3.yohops.com:9999/',
21 search: 'http://192.168.102.216:8080/yohosearch/' 21 search: 'http://192.168.102.216:8080/yohosearch/'
22 }, 22 },
23 subDomains: { 23 subDomains: {