Authored by ccbikai(👎🏻🍜)

Merge branch 'release/newSearch' of git.yoho.cn:fe/yohobuywap-node into release/newSearch

@@ -14,7 +14,7 @@ const helpers = global.yoho.helpers; @@ -14,7 +14,7 @@ const helpers = global.yoho.helpers;
14 /** 14 /**
15 * 店铺 - 基础模板 15 * 店铺 - 基础模板
16 */ 16 */
17 -const _baseShop = (req, res, shopInfo) => { 17 +const _baseShop = (req, res, shopInfo, shopId) => {
18 18
19 listModel.getBaseShopData(req.query, shopInfo).then(result => { 19 listModel.getBaseShopData(req.query, shopInfo).then(result => {
20 20
@@ -27,13 +27,31 @@ const _baseShop = (req, res, shopInfo) => { @@ -27,13 +27,31 @@ const _baseShop = (req, res, shopInfo) => {
27 title: result.shopName, 27 title: result.shopName,
28 goodList: result, 28 goodList: result,
29 showDownloadApp: true, 29 showDownloadApp: true,
30 - pageFooter: true 30 + pageFooter: true,
  31 + shopId: shopId,
31 }); 32 });
32 }); 33 });
33 34
34 }; 35 };
35 36
36 /** 37 /**
  38 + * 基础模板收藏
  39 + */
  40 +const baseShopFav = (req, res) => {
  41 + let isApp = req.query.app_version || req.query.appVersion || false;
  42 + let uid = isApp ? req.query.uid : req.user.uid;
  43 + let shopId = req.query.shopId;
  44 +
  45 + listModel.getShopData(req, shopId, uid, isApp).then(result => {
  46 + res.json({
  47 + code: 200,
  48 + collect: result.goBrand && result.goBrand.isFavorite === 'Y' ? true : false,
  49 + });
  50 + });
  51 +};
  52 +
  53 +
  54 +/**
37 * 店铺首页 55 * 店铺首页
38 * @return int 56 * @return int
39 */ 57 */
@@ -42,6 +60,7 @@ const _shop = (req, res, shopId) => { @@ -42,6 +60,7 @@ const _shop = (req, res, shopId) => {
42 let pageHeader = {}; 60 let pageHeader = {};
43 let uid = 0; 61 let uid = 0;
44 62
  63 + // pagecache前端判断
45 if (!isApp) { 64 if (!isApp) {
46 pageHeader = { 65 pageHeader = {
47 pageHeader: _.assign({ 66 pageHeader: _.assign({
@@ -55,21 +74,23 @@ const _shop = (req, res, shopId) => { @@ -55,21 +74,23 @@ const _shop = (req, res, shopId) => {
55 navTitle: false 74 navTitle: false
56 })) 75 }))
57 }; 76 };
58 - uid = req.user.uid;  
59 - } else {  
60 - uid = req.query.uid;  
61 - req.session.appUid = uid;  
62 - res.cookie('appUid', uid, {  
63 - domain: 'yohobuy.com',  
64 - expires: new Date(Date.now() + 2592000000) // 有效期一年  
65 - });  
66 } 77 }
67 78
  79 + // uid = req.user.uid;
  80 + // } else {
  81 + // uid = req.query.uid;
  82 + // req.session.appUid = uid;
  83 + // res.cookie('appUid', uid, {
  84 + // domain: 'yohobuy.com',
  85 + // expires: new Date(Date.now() + 2592000000) // 有效期一年
  86 + // });
  87 + // }
  88 +
68 listModel.getShopData(req, shopId, uid, isApp).then(result => { 89 listModel.getShopData(req, shopId, uid, isApp).then(result => {
69 if (result.goBrand) { 90 if (result.goBrand) {
70 91
71 /* 若店铺使用基础模板跳转基础模板 */ 92 /* 若店铺使用基础模板跳转基础模板 */
72 - _baseShop(req, res, result.goBrand); 93 + _baseShop(req, res, result.goBrand, shopId);
73 } else { 94 } else {
74 result = _.assign(result, pageHeader); 95 result = _.assign(result, pageHeader);
75 96
@@ -79,12 +100,46 @@ const _shop = (req, res, shopId) => { @@ -79,12 +100,46 @@ const _shop = (req, res, shopId) => {
79 shopIndex: result, 100 shopIndex: result,
80 shopHeadHide: true, 101 shopHeadHide: true,
81 gender: req.query.gender, 102 gender: req.query.gender,
82 - channel: req.query.channel 103 + channel: req.query.channel,
  104 + shopId: shopId,
83 }); 105 });
84 } 106 }
85 }); 107 });
86 }; 108 };
87 109
  110 +/**
  111 + * app设置cookie
  112 + */
  113 +const shopAppCookie = (req, res) => {
  114 + let uid = req.query.uid;
  115 +
  116 + req.session.appUid = uid;
  117 + res.cookie('appUid', uid, {
  118 + domain: 'yohobuy.com',
  119 + expires: new Date(Date.now() + 2592000000) // 有效期一年
  120 + });
  121 + res.json({
  122 + code: 200,
  123 + msg: 'app cookie set',
  124 + });
  125 +};
  126 +
  127 +/**
  128 + * 前端请求判断shop是否收藏
  129 + */
  130 +const shopFav = (req, res) => {
  131 + let isApp = req.query.app_version || req.query.appVersion || false;
  132 + let uid = isApp ? req.query.uid : req.user.uid;
  133 + let shopId = req.query.shopId;
  134 +
  135 + listModel.getShopData(req, shopId, uid, isApp).then(result => {
  136 + res.json({
  137 + code: 200,
  138 + collect: result.collect,
  139 + });
  140 + });
  141 +};
  142 +
88 // 品类落地页 143 // 品类落地页
89 const category = (req, res) => { 144 const category = (req, res) => {
90 let params = Object.assign({}, req.query); 145 let params = Object.assign({}, req.query);
@@ -126,6 +181,7 @@ const brand = (req, res, next) => { @@ -126,6 +181,7 @@ const brand = (req, res, next) => {
126 } 181 }
127 182
128 listModel.getBrandLogoByDomain(domain).then((result) => { 183 listModel.getBrandLogoByDomain(domain).then((result) => {
  184 +
129 brandLogo = result; 185 brandLogo = result;
130 186
131 title = brandLogo.name; 187 title = brandLogo.name;
@@ -177,13 +233,27 @@ const brand = (req, res, next) => { @@ -177,13 +233,27 @@ const brand = (req, res, next) => {
177 }), 233 }),
178 goodList: params, 234 goodList: params,
179 showDownloadApp: true, 235 showDownloadApp: true,
180 - pageFooter: true 236 + pageFooter: true,
  237 + domain: req.query.domain,
181 }); 238 });
182 }); 239 });
183 } 240 }
184 }).catch(next); 241 }).catch(next);
185 }; 242 };
186 243
  244 +const brandFav = (req, res) => {
  245 + let domain = req.query.domain;
  246 + let uid = req.user.uid;
  247 + let brandId = 0;
  248 +
  249 + listModel.getBrandLogoByDomain(domain).then((result) => {
  250 + brandId = result.id;
  251 + listModel.getBrandIntro(brandId, uid).then(result2 => {
  252 + res.json(result2);
  253 + });
  254 + });
  255 +};
  256 +
187 /** 257 /**
188 * 店铺简介 258 * 店铺简介
189 * @param req 259 * @param req
@@ -270,5 +340,11 @@ module.exports = { @@ -270,5 +340,11 @@ module.exports = {
270 category, 340 category,
271 brand, 341 brand,
272 favoriteBrand, 342 favoriteBrand,
273 - shopIntro 343 + shopIntro,
  344 +
  345 + // pagecache新增
  346 + brandFav,
  347 + shopAppCookie,
  348 + shopFav,
  349 + baseShopFav,
274 }; 350 };
@@ -381,7 +381,6 @@ const _formShopData = (data, shopId, isApp) => { @@ -381,7 +381,6 @@ const _formShopData = (data, shopId, isApp) => {
381 formatData.favId = shopId; 381 formatData.favId = shopId;
382 formatData.shopId = ''; 382 formatData.shopId = '';
383 } 383 }
384 -  
385 return formatData; 384 return formatData;
386 }; 385 };
387 386
@@ -492,11 +491,9 @@ const getShopData = (req, shopId, uid, isApp) => { @@ -492,11 +491,9 @@ const getShopData = (req, shopId, uid, isApp) => {
492 const getBrandIntro = (brandId, uid) => { 491 const getBrandIntro = (brandId, uid) => {
493 let param = {}; 492 let param = {};
494 493
495 - if (uid) {  
496 - param = {  
497 - uid: uid  
498 - };  
499 - } 494 + param = {
  495 + uid: uid,
  496 + };
500 497
501 return api.get('', _.assign({ 498 return api.get('', _.assign({
502 method: 'app.brand.getBrandIntro', 499 method: 'app.brand.getBrandIntro',
@@ -96,6 +96,10 @@ router.get('/index/index', list.category); @@ -96,6 +96,10 @@ router.get('/index/index', list.category);
96 96
97 // 品牌 | 店铺 97 // 品牌 | 店铺
98 router.get('/index/brand', list.brand); 98 router.get('/index/brand', list.brand);
  99 +router.get('/index/brandFav', list.brandFav);
  100 +router.get('/index/shopAppCookie', list.shopAppCookie);
  101 +router.get('/index/shopFav', list.shopFav);
  102 +router.get('/index/baseShopFav', list.baseShopFav);
99 103
100 // 店铺介绍 104 // 店铺介绍
101 router.get('/index/intro', list.shopIntro); 105 router.get('/index/intro', list.shopIntro);
@@ -32,11 +32,7 @@ @@ -32,11 +32,7 @@
32 <img class="logo" src="{{image logoImg 500 500}}"> 32 <img class="logo" src="{{image logoImg 500 500}}">
33 <p class="store-name">{{storeName}}</p> 33 <p class="store-name">{{storeName}}</p>
34 <div class="collect"> 34 <div class="collect">
35 - {{#if collect}}  
36 - <div class="already-collect" id="collect"></div>  
37 - {{else}}  
38 - <div class="not-collect buriedpoint" id="collect" data-bp-id="shop_branner_collect_1"></div>  
39 - {{/if}} 35 + <div class="not-collect buriedpoint" id="collect" data-bp-id="shop_branner_collect_1"></div>
40 </div> 36 </div>
41 </div> 37 </div>
42 </div> 38 </div>
@@ -220,3 +216,5 @@ @@ -220,3 +216,5 @@
220 {{> common/filter}} 216 {{> common/filter}}
221 {{/ shopIndex}} 217 {{/ shopIndex}}
222 {{> common/query-param}} 218 {{> common/query-param}}
  219 +
  220 +<input type="text" class="shopid" style="display:none" value={{shopId}} />
@@ -37,7 +37,7 @@ @@ -37,7 +37,7 @@
37 <a class="btn-intro" href="javascript:void(0);"> 37 <a class="btn-intro" href="javascript:void(0);">
38 品牌介绍 38 品牌介绍
39 </a> 39 </a>
40 - <a class="btn-col{{#if collected}} coled{{/if}}" href="javascript:void(0);"> 40 + <a class="btn-col" href="javascript:void(0);">
41 <span class="iconfont">&#xe622;</span> 41 <span class="iconfont">&#xe622;</span>
42 <span class="txt"></span> 42 <span class="txt"></span>
43 </a> 43 </a>
@@ -65,7 +65,7 @@ @@ -65,7 +65,7 @@
65 <a class="btn-intro" href="javascript:void(0);"> 65 <a class="btn-intro" href="javascript:void(0);">
66 店铺介绍 66 店铺介绍
67 </a> 67 </a>
68 - <a class="btn-col{{#if collected}} coled{{/if}}" href="javascript:void(0);"> 68 + <a class="btn-col" href="javascript:void(0);">
69 <span class="iconfont">&#xe622;</span> 69 <span class="iconfont">&#xe622;</span>
70 <span class="txt"></span> 70 <span class="txt"></span>
71 </a> 71 </a>
@@ -140,3 +140,6 @@ @@ -140,3 +140,6 @@
140 140
141 {{> common/suspend-cart}} 141 {{> common/suspend-cart}}
142 {{/ goodList}} 142 {{/ goodList}}
  143 +
  144 +<input type="text" class="domain" style="display:none" value={{domain}}>
  145 +<input type="text" class="shopId" style="display:none" value={{shopId}}>
@@ -71,6 +71,43 @@ require('../../common'); @@ -71,6 +71,43 @@ require('../../common');
71 71
72 ellipsis.init(); 72 ellipsis.init();
73 73
  74 +// pageCache 获取是否收藏
  75 +(function() {
  76 + if ($('.domain').val()) {
  77 + $.ajax({
  78 + url: '/product/index/brandFav',
  79 + data: {
  80 + domain: $('.domain').val()
  81 + },
  82 + dataType: 'json',
  83 + success: function(data) {
  84 + if (data.collected) {
  85 + $('.brand-header .btn-col').addClass('coled');
  86 + }
  87 + },
  88 + error: function() {
  89 + tip.show('网络断开连接了~');
  90 + }
  91 + });
  92 + } else {
  93 + $.ajax({
  94 + url: '/product/index/baseShopFav',
  95 + data: {
  96 + shopId: $('.shopId').val()
  97 + },
  98 + dataType: 'json',
  99 + success: function(data) {
  100 + if (data.collect) {
  101 + $('.brand-header .btn-col').addClass('coled');
  102 + }
  103 + },
  104 + error: function() {
  105 + tip.show('网络断开连接了~');
  106 + }
  107 + });
  108 + }
  109 +}());
  110 +
74 // 搜索输入联动 111 // 搜索输入联动
75 function inputAction() { 112 function inputAction() {
76 var $searchAssociate = $('.search-associate'); 113 var $searchAssociate = $('.search-associate');
@@ -42,6 +42,38 @@ var winH = $(window).height(), @@ -42,6 +42,38 @@ var winH = $(window).height(),
42 42
43 require('../../common'); 43 require('../../common');
44 44
  45 +// pagecache判断app设置cookie,判断是否收藏
  46 +(function() {
  47 + var param = location.search;
  48 + var isApp = param.indexOf('app_version') > -1 || param.indexOf('appVersion') > -1;
  49 +
  50 + if (isApp) {
  51 + $.ajax({
  52 + type: 'GET',
  53 + url: '/product/index/shopAppCookie',
  54 + error: function() {
  55 + tip.show('网络断开连接了~');
  56 + }
  57 + });
  58 + }
  59 +
  60 + $.ajax({
  61 + type: 'GET',
  62 + url: '/product/index/shopFav',
  63 + data: {
  64 + shopId: $('.shopid').val(),
  65 + },
  66 + success: function(data) {
  67 + if (data.collect) {
  68 + $collect.attr('class', 'already-collect');
  69 + }
  70 + },
  71 + error: function() {
  72 + tip.show('网络断开连接了~');
  73 + }
  74 + });
  75 +}());
  76 +
45 // 默认筛选条件 77 // 默认筛选条件
46 var defaultOpt = require('../../common/query-param'); 78 var defaultOpt = require('../../common/query-param');
47 79