Authored by 周少峰

Merge branch 'release/5.0.0' of git.yoho.cn:fe/yohobuy-node into release/5.0.0

@@ -5,6 +5,8 @@ @@ -5,6 +5,8 @@
5 5
6 'use strict'; 6 'use strict';
7 const _ = require('lodash'); 7 const _ = require('lodash');
  8 +const Fn = require('lodash/fp');
  9 +const qs = require('queryString');
8 10
9 const helpers = global.yoho.helpers; 11 const helpers = global.yoho.helpers;
10 12
@@ -72,21 +74,25 @@ const goodsTabBar = (data, shopId) => { @@ -72,21 +74,25 @@ const goodsTabBar = (data, shopId) => {
72 new: [] 74 new: []
73 }; 75 };
74 76
75 - _.forEach(data.hot, (value) => {  
76 - if (value.url) { 77 + _.forEach(_.sortBy(data.hot, o => {
  78 + return -o.position;
  79 + }), (value) => {
  80 + if (value.url && value.position) {
77 dest.hot.push({ 81 dest.hot.push({
78 name: value.name, 82 name: value.name,
79 - href: value.url 83 + url: value.url
80 }); 84 });
81 } 85 }
82 86
83 }); 87 });
84 88
85 - _.forEach(data.new, (value) => {  
86 - if (value.url) { 89 + _.forEach(_.sortBy(data.new, o => {
  90 + return -o.position;
  91 + }), (value) => {
  92 + if (value.url && value.position) {
87 dest.new.push({ 93 dest.new.push({
88 name: value.name, 94 name: value.name,
89 - href: value.url 95 + url: value.url
90 }); 96 });
91 } 97 }
92 }); 98 });
@@ -150,9 +156,16 @@ const navigationBar = (data, shopId) => { @@ -150,9 +156,16 @@ const navigationBar = (data, shopId) => {
150 } 156 }
151 ]; 157 ];
152 158
153 - return {navigationBar: _.union(shopNav, _.filter(data, (value) => {  
154 - return value.url;  
155 - }))}; 159 + _.forEach(data, (value) => {
  160 + if (value.url) {
  161 + shopNav.push({
  162 + name: value.name,
  163 + url: `${value.url}&navBar=${shopNav.length}`
  164 + });
  165 + }
  166 + });
  167 +
  168 + return {navigationBar: shopNav};
156 }; 169 };
157 170
158 /** 171 /**
@@ -160,24 +173,14 @@ const navigationBar = (data, shopId) => { @@ -160,24 +173,14 @@ const navigationBar = (data, shopId) => {
160 * @param type $data 173 * @param type $data
161 * @return type [] 174 * @return type []
162 */ 175 */
163 -const largeSlideImg = (data, shopId) => { 176 +const largeSlideImg = (data) => {
164 let dest = []; 177 let dest = [];
165 178
166 _.forEach(data, (value) => { 179 _.forEach(data, (value) => {
167 - let url;  
168 -  
169 value = _.get(value, 'data[0]', {}); 180 value = _.get(value, 'data[0]', {});
170 - url = value.url;  
171 -  
172 - if (+value.categoryId > 0) {  
173 - if (!url) {  
174 - url = `${shopListUrl}?shopId=${shopId}`;  
175 - }  
176 - url += `&productPool=${value.categoryId}`;  
177 - }  
178 dest.push({ 181 dest.push({
179 img: value.src, 182 img: value.src,
180 - url: url 183 + url: value.url
181 }); 184 });
182 }); 185 });
183 186
@@ -189,24 +192,14 @@ const largeSlideImg = (data, shopId) => { @@ -189,24 +192,14 @@ const largeSlideImg = (data, shopId) => {
189 * @param data 装修数据 192 * @param data 装修数据
190 * @returns {{}} 193 * @returns {{}}
191 */ 194 */
192 -const oneRowTwoColImages = (data, shopId) => { 195 +const oneRowTwoColImages = (data) => {
193 let dest = []; 196 let dest = [];
194 197
195 _.forEach(data, (value) => { 198 _.forEach(data, (value) => {
196 - let url;  
197 -  
198 value = _.get(value, 'data[0]', {}); 199 value = _.get(value, 'data[0]', {});
199 - url = value.url;  
200 -  
201 - if (+value.categoryId > 0) {  
202 - if (!url) {  
203 - url = `${shopListUrl}?shopId=${shopId}`;  
204 - }  
205 - url += `&productPool=${value.categoryId}`;  
206 - }  
207 dest.push({ 200 dest.push({
208 img: value.src, 201 img: value.src,
209 - url: url 202 + url: value.url
210 }); 203 });
211 }); 204 });
212 return {oneRowTwoColImages: dest}; 205 return {oneRowTwoColImages: dest};
@@ -217,21 +210,16 @@ const oneRowTwoColImages = (data, shopId) => { @@ -217,21 +210,16 @@ const oneRowTwoColImages = (data, shopId) => {
217 * @param type $data 210 * @param type $data
218 * @return type [] 211 * @return type []
219 */ 212 */
220 -const recommend = (data, shopId) => { 213 +const recommend = (data) => {
221 let dest = []; 214 let dest = [];
222 215
223 _.forEach(data, (value) => { 216 _.forEach(data, (value) => {
224 - let url = value.url || `${shopListUrl}?shopId=${shopId}`;  
225 -  
226 - if (+value.categoryId > 0) {  
227 - url += `&productPool=${value.categoryId}`;  
228 - }  
229 dest.push({ 217 dest.push({
230 enName: value.enName, 218 enName: value.enName,
231 name: value.name, 219 name: value.name,
232 img: value.src, 220 img: value.src,
233 title: value.title, 221 title: value.title,
234 - url: url 222 + url: value.url
235 }); 223 });
236 }); 224 });
237 225
@@ -323,6 +311,38 @@ const signboard = (data) => { @@ -323,6 +311,38 @@ const signboard = (data) => {
323 }; 311 };
324 }; 312 };
325 313
  314 +
  315 +// 销售类目
  316 +const _handleSaleCategory = (shopId, resourceObj) => {
  317 + const thisShop = (categoryId) => shopListUrl + '?' + qs.stringify({
  318 + productPool: categoryId,
  319 + shopId: shopId,
  320 + navBar: -1
  321 + });
  322 +
  323 + let hasSaleCategory = Fn.pipe(Fn.prop('linkType'), Fn.eq('1'));
  324 +
  325 + if (hasSaleCategory(resourceObj)) {
  326 + return Object.assign(resourceObj, {url: thisShop(resourceObj.categoryId)});
  327 + }
  328 +
  329 + _(resourceObj).forEach((value) => {
  330 + if (_.has(value, 'data')) {
  331 + _.forEach(value.data, (it) => {
  332 + if (hasSaleCategory(it)) {
  333 + Object.assign(it, {url: thisShop(it.categoryId)});
  334 + }
  335 + });
  336 + }
  337 +
  338 + if (hasSaleCategory(value)) {
  339 + Object.assign(value, {url: thisShop(value.categoryId)});
  340 + }
  341 + });
  342 +
  343 + return resourceObj;
  344 +};
  345 +
326 /** 346 /**
327 * 店铺装修楼层数据 347 * 店铺装修楼层数据
328 * @param data 装修数据 348 * @param data 装修数据
@@ -333,7 +353,7 @@ exports.getShopDecorator = (data, params, shopId, base) => { @@ -333,7 +353,7 @@ exports.getShopDecorator = (data, params, shopId, base) => {
333 353
334 if (base) { 354 if (base) {
335 _.forEach(data.list, (value) => { 355 _.forEach(data.list, (value) => {
336 - let info = JSON.parse(value.resource_data); 356 + let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
337 357
338 switch (value.resource_name) { 358 switch (value.resource_name) {
339 case 'signboard': 359 case 'signboard':
@@ -351,9 +371,9 @@ exports.getShopDecorator = (data, params, shopId, base) => { @@ -351,9 +371,9 @@ exports.getShopDecorator = (data, params, shopId, base) => {
351 newArrivel: {}, 371 newArrivel: {},
352 hotSingle: {} 372 hotSingle: {}
353 }); 373 });
354 - 374 +
355 _.forEach(data.list, (value) => { 375 _.forEach(data.list, (value) => {
356 - let info = JSON.parse(value.resource_data); 376 + let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
357 let tabBar; 377 let tabBar;
358 378
359 switch (value.resource_name) { 379 switch (value.resource_name) {