Authored by 郝肖肖

搜索 默认筛选添加 uid

@@ -26,6 +26,7 @@ const list = (req, res, next) => { @@ -26,6 +26,7 @@ const list = (req, res, next) => {
26 let isQueryFirstClass = false; // 标识用户搜的是不是一级品类 26 let isQueryFirstClass = false; // 标识用户搜的是不是一级品类
27 let isQuerySecondClass = false; // 标识用户搜的是不是二级品类 27 let isQuerySecondClass = false; // 标识用户搜的是不是二级品类
28 let domain = null; 28 let domain = null;
  29 + let uid = req.user.uid || 0;
29 30
30 if (params.shop_id) { 31 if (params.shop_id) {
31 params.shopId = params.shop_id; 32 params.shopId = params.shop_id;
@@ -52,6 +53,10 @@ const list = (req, res, next) => { @@ -52,6 +53,10 @@ const list = (req, res, next) => {
52 query = query.toLowerCase(); 53 query = query.toLowerCase();
53 } 54 }
54 55
  56 + if (uid) {
  57 + initialData.uid = uid;
  58 + }
  59 +
55 /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */ 60 /* 判断是不是品牌, 是品牌跳到品牌列表页(显示搜索框),判断是不是品类, 是品类加导航标题(不显示搜索框) */
56 return Promise.all([ 61 return Promise.all([
57 searchModel.getBrandDomain(query), 62 searchModel.getBrandDomain(query),
@@ -183,16 +188,26 @@ let fuzzyDatas = (req, res, next) => { @@ -183,16 +188,26 @@ let fuzzyDatas = (req, res, next) => {
183 * ajax 商品数据请求 188 * ajax 商品数据请求
184 */ 189 */
185 const search = (req, res, next) => { 190 const search = (req, res, next) => {
186 - res.header('Access-Control-Allow-Origin', '*'); 191 + let allowOrigin = _.get(req, 'headers.origin', null) ?
  192 + req.headers.origin : req.protocol + '://' + req.headers.host;
  193 +
  194 + res.setHeader('Access-Control-Allow-Origin', allowOrigin);
  195 + res.setHeader('Access-Control-Allow-Credentials', 'true');
187 196
188 let params = Object.assign({}, req.query); 197 let params = Object.assign({}, req.query);
  198 + let uid = req.user.uid || 0;
  199 +
  200 + if (uid) {
  201 + params.uid = uid;
  202 + }
189 203
190 params.isApp = req.yoho.isApp; 204 params.isApp = req.yoho.isApp;
191 params.limit = 24; 205 params.limit = 24;
  206 +
192 searchModel.getSearchData(params).then((result) => { 207 searchModel.getSearchData(params).then((result) => {
193 208
194 if (result && result.list && 209 if (result && result.list &&
195 - parseInt(params.page) === 1 && parseInt(params.start) > 0) { 210 + parseInt(params.page, 10) === 1 && parseInt(params.start, 10) > 0) {
196 // 首屏渲染时,使用 'start' 参数裁减已渲染数据 211 // 首屏渲染时,使用 'start' 参数裁减已渲染数据
197 result.list = result.list.slice(params.start || 0); 212 result.list = result.list.slice(params.start || 0);
198 } 213 }
@@ -15,7 +15,7 @@ const cachePage = { @@ -15,7 +15,7 @@ const cachePage = {
15 // 自定义频道 15 // 自定义频道
16 '/channel/:id.html': 1 * MINUTE, 16 '/channel/:id.html': 1 * MINUTE,
17 17
18 - //ajax获取频道页楼层 18 + // ajax获取频道页楼层
19 '/channel/getResourceContent': 30 * MINUTE, 19 '/channel/getResourceContent': 30 * MINUTE,
20 20
21 // 商品分类 21 // 商品分类
@@ -30,10 +30,12 @@ const cachePage = { @@ -30,10 +30,12 @@ const cachePage = {
30 // 店铺推荐 30 // 店铺推荐
31 '/product/detail/preference': 5 * MINUTE, 31 '/product/detail/preference': 5 * MINUTE,
32 '/product/detail/intro/:productskn': 15 * MINUTE, 32 '/product/detail/intro/:productskn': 15 * MINUTE,
  33 +
33 // 店铺人气单品 34 // 店铺人气单品
34 '/product/new/shop/hotlist': 5 * MINUTE, 35 '/product/new/shop/hotlist': 5 * MINUTE,
  36 +
35 // 店铺简介 37 // 店铺简介
36 - '/product/index/intro' : 15 * MINUTE, 38 + '/product/index/intro': 15 * MINUTE,
37 39
38 // 逛 40 // 逛
39 '/guang/': 1 * MINUTE, 41 '/guang/': 1 * MINUTE,
@@ -57,9 +59,10 @@ const cachePage = { @@ -57,9 +59,10 @@ const cachePage = {
57 '/product/list/index': 1 * MINUTE, 59 '/product/list/index': 1 * MINUTE,
58 '/product/index/index': 1 * MINUTE, 60 '/product/index/index': 1 * MINUTE,
59 '/product/index/brand': 1 * MINUTE, 61 '/product/index/brand': 1 * MINUTE,
60 -  
61 '/product/search/filter': 1 * MINUTE, 62 '/product/search/filter': 1 * MINUTE,
62 - '/product/search/search': 1 * MINUTE, 63 +
  64 + // 筛选默认须要添加uid参数
  65 + // '/product/search/search': 1 * MINUTE,
63 66
64 '/product/new': 1 * MINUTE, 67 '/product/new': 1 * MINUTE,
65 68
@@ -532,6 +532,9 @@ function search(opt) { @@ -532,6 +532,9 @@ function search(opt) {
532 type: 'GET', 532 type: 'GET',
533 url: location.protocol + '//m.yohobuy.com/product/search/search', 533 url: location.protocol + '//m.yohobuy.com/product/search/search',
534 data: setting, 534 data: setting,
  535 + xhrFields: {
  536 + withCredentials: true
  537 + },
535 success: function(data) { 538 success: function(data) {
536 var num, 539 var num,
537 $container, 540 $container,