shop-handler.js
10.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
/*
* @Author: sefon
* @Date: 2016-07-31 22:13:24
*/
'use strict';
const _ = require('lodash');
const Fn = require('lodash/fp');
const qs = require('queryString');
const helpers = global.yoho.helpers;
// const queryString = require('querystring');
const newProductsName = '新品上架 NEW';
const hotProductsName = '人气单品 HOT';
const shopListUrl = '/product/shoplist';
exports.setShopSeo = (shopName) => {
return {
title: `${shopName} | ${shopName} 潮流服装服饰-Yoho!Buy有货`,
keywords: `${shopName},${shopName} 服装服饰,${shopName} 潮流服装服饰`,
description: `${shopName} | Yoho!Buy有货 ${shopName} 潮流服饰官方授权店!100%品牌正品保证,支持货到付款。`
};
};
/**
* 新品上架
*/
const newProducts = (data) => {
let dest = {};
if (!_.isEmpty(data)) {
Object.assign(dest, {
name: newProductsName,
list: []
});
_.forEach(data, (value) => {
dest.list.push({
productId: value.productId,
title: value.productName,
productSkn: value.productSkn,
price: `¥${value.salesPrice}`,
img: value.src,
url: helpers.getUrlBySkc(value.productId, value.goodsId, value.cnAlphabet)
});
});
}
return dest;
};
/**
* 人气单品
*/
const hotProducts = (data) => {
let dest = {
name: hotProductsName,
list: []
};
_.forEach(data, (value, key) => {
dest.list.push({
productId: value.productId,
title: value.productName,
productSkn: value.productSkn,
price: `¥${value.salesPrice}`,
img: value.src,
url: helpers.getUrlBySkc(value.productId, value.goodsId, value.cnAlphabet),
index: key + 1
});
});
return dest;
};
/**
* tabBar
*/
const goodsTabBar = (data, shopId) => {
let dest = {
hot: [],
new: []
};
_.forEach(_.sortBy(data.hot, o => {
return -o.position;
}), (value) => {
if (value.url && value.position) {
dest.hot.push({
name: value.name,
url: value.url
});
}
});
_.forEach(_.sortBy(data.new, o => {
return -o.position;
}), (value) => {
if (value.url && value.position) {
dest.new.push({
name: value.name,
url: value.url
});
}
});
dest.hot.push({name: 'MORE', url: `${shopListUrl}?navBar=2&order=s_n_desc&shopId=${shopId}`});
dest.new.push({name: 'MORE', url: `${shopListUrl}?navBar=3&order=s_t_desc&shopId=${shopId}`});
return dest;
};
/**
* 店铺经典模板banner
* @param data 装修数据
* @returns {{}}
*/
const shopTopBanner = (data) => {
let src = data[0].shopSrc;
let str = _.split(src, '?').length ? '?' : '&';
return {
shopTopBanner: {
bannerHeight: 200,
banner: `${src}${str}imageView2/1/w/{width}/h/{height}`,
detailSrc: data[0].detailSrc || '',
isShowShopName: data[0].isShowShopName === 'Y'
}
};
};
const shopTopBannerBase = (data) => {
return {
shopTopBannerBase: {
bannerHeight: 200,
banner: helpers.getForceSourceUrl(data[0].shopSrc),
showShopName: data[0].isShowShopName === 'Y'
}
};
};
/**
* 导航
* @param data 装修数据
* @returns {{}}
*/
const navigationBar = (data, shopId) => {
let shopNav = [
{
name: '店铺首页',
url: `/?navBar=0&shopId=${shopId}`
},
{
name: '全部商品',
url: `${shopListUrl}/?navBar=1&shopId=${shopId}`
},
{
name: '人气单品',
url: `${shopListUrl}/?navBar=2&order=s_n_desc&shopId=${shopId}`
},
{
name: '新品上架',
url: `${shopListUrl}/?navBar=3&order=s_t_desc&shopId=${shopId}`
}
];
_.forEach(data, (value) => {
if (value.url) {
shopNav.push({
name: value.name,
url: `${value.url}&navBar=${shopNav.length}`
});
}
});
return {navigationBar: shopNav};
};
/**
* 资源位大图
* @param type $data
* @return type []
*/
const largeSlideImg = (data) => {
let dest = [];
_.forEach(data, (value) => {
value = _.get(value, 'data[0]', {});
dest.push({
img: value.src,
url: value.url
});
});
return {largeSlideImg: dest};
};
/**
* 资源位小图
* @param data 装修数据
* @returns {{}}
*/
const oneRowTwoColImages = (data) => {
let dest = [];
_.forEach(data, (value) => {
value = _.get(value, 'data[0]', {});
dest.push({
img: value.src,
url: value.url
});
});
return {oneRowTwoColImages: dest};
};
/**
* 经典推荐
* @param type $data
* @return type []
*/
const recommend = (data) => {
let dest = [];
_.forEach(data, (value) => {
dest.push({
enName: value.enName,
name: value.name,
img: value.src,
title: value.title,
url: value.url
});
});
return {
recommend: {
title: dest[0].title,
list: dest
}
};
};
/**
* 品牌集合
* @param type $data
* @return type []
*/
const brandBrowse = (data, params) => {
let brand = _.get(params, 'brand', '');
let resData = {};
if (!_.isEmpty(data) && data.length > 1) {
let list = [];
_.forEach(data, value => {
list.push({
url: `${shopListUrl}?shopId=${params.shopId || ''}&brand=${value.id}&title=${value.title}$navBar=1`,
brandName: value.brandName,
title: value.title,
cur: (brand === +value.id)
});
});
resData.brandBrowse = {
title: list[0].title,
list: list
};
}
return resData;
};
/**
* 热门推荐
* @param type $data
* @return type []
*/
const hotRecommend = (data) => {
let resData = {};
if (!_.isEmpty(data)) {
let list = [];
_.forEach(data, value => {
list.push({
title: value.title,
img: value.src,
url: value.url
});
});
resData.hotRecommend = {
title: list[0].title,
list: list
};
}
return resData;
};
/**
* 水牌
*/
const signboard = (data) => {
let list = [];
_.forEach(data, value => {
if (value.data) {
_.forEach(value.data, val => {
list.push({
img: helpers.image(val.src, 160, 240),
url: val.url
});
});
}
});
return {
title: _.get(list, '[0].title', ''),
list: list
};
};
// 销售类目
const _handleSaleCategory = (shopId, resourceObj) => {
const thisShop = (categoryId) => shopListUrl + '?' + qs.stringify({
productPool: categoryId,
shopId: shopId,
navBar: -1
});
let hasSaleCategory = Fn.pipe(Fn.prop('linkType'), Fn.eq('1'));
if (hasSaleCategory(resourceObj)) {
return Object.assign(resourceObj, {url: thisShop(resourceObj.categoryId)});
}
_(resourceObj).forEach((value) => {
if (_.has(value, 'data')) {
_.forEach(value.data, (it) => {
if (hasSaleCategory(it)) {
Object.assign(it, {url: thisShop(it.categoryId)});
}
});
}
if (hasSaleCategory(value)) {
Object.assign(value, {url: thisShop(value.categoryId)});
}
});
return resourceObj;
};
/**
* 店铺装修楼层数据
* @param data 装修数据
* @returns {{}}
*/
exports.getShopDecorator = (data, params, shopId, base) => {
let dest = {};
if (base) {
_.forEach(data.list, (value) => {
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
switch (value.resource_name) {
case 'signboard':
dest.signboard = signboard(info);
break;
case 'shopTopBanner_base':
Object.assign(dest, shopTopBannerBase(info));
break;
default:
break;
}
});
} else {
Object.assign(dest, {
newArrivel: {},
hotSingle: {}
});
_.forEach(data.list, (value) => {
let info = Fn.pipe(JSON.parse, _.partial(_handleSaleCategory, shopId))(value.resource_data);
let tabBar;
switch (value.resource_name) {
case 'newProducts':
Object.assign(dest.newArrivel, newProducts(info));
break;
case 'hotProducts':
Object.assign(dest.hotSingle, hotProducts(info));
break;
case 'goodsTabBar':
tabBar = goodsTabBar(info, shopId);
Object.assign(dest.newArrivel, {navs: tabBar.new});
Object.assign(dest.hotSingle, {navs: tabBar.hot});
break;
case 'shopTopBanner':
Object.assign(dest, shopTopBanner(info));
break;
case 'navigationBar':
Object.assign(dest, navigationBar(info, shopId));
break;
case 'largeSlideImg':
Object.assign(dest, largeSlideImg(info, shopId));
break;
case 'oneRowTwoColImages':
Object.assign(dest, oneRowTwoColImages(info, shopId));
break;
case 'recommend':
Object.assign(dest, recommend(info, shopId));
break;
case 'brandBrowse':
Object.assign(dest, brandBrowse(info, params));
break;
case 'hotRecommend':
Object.assign(dest, hotRecommend(info));
break;
default:
break;
}
});
}
return dest;
};