ResourceParser.js
5.97 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
'use strict';
// import {image, urlFormat} from './Helper';
const helpers = require('./Helper');
const _ = require('lodash');
/**
* 销售类目链接拼接 APP
* @param origin
* @param shopId
* @private
*/
function _modifyAppUrl(origin, shopId) {
if (parseInt(_.get(origin, 'linkType', 0), 10) === 1) {
return `http://m.yohobuy.com?openby:yohobuy={"action":"go.poollist","params":{"shop_id":"${shopId}","title":"${origin.categoryName}","productPool":"${origin.categoryId}"}}`; //eslint-disable-line
} else {
if (_.has(origin, 'url')) {
return origin.url;
} else {
return '';
}
}
};
// 店铺banner
function shopTopBanner_APPParser(resData) {
return resData[0].shopSrc;
}
// 资源位小图 接口返回两组,取每组第一张
function oneRowTwoColImages_APPParser(resData, shopId, resourceId) {
let spring = [];
_.forEach(resData, (item) => {
if (item.data) {
spring.push({
url: _modifyAppUrl(item.data[0], shopId),
src: item.data[0].src,
resourceId,
});
}
});
return spring;
}
// 店铺品牌一览
function brandBrowseParser(resData, shopId, resourceId) {
let brandNumber = resData.length;
let brands = [];
let brandId = '';
let single = false;
// 少于2个不展示 单品店:单品店根据品牌id查询
if (brandNumber < 2) {
brandId = resData[0].id;
single = true;
} else {
_.forEach(resData, (item) => {
if (item.brandDomain) {
brands.push({
url: `http://m.yohobuy.com?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}`, //eslint-disable-line
src: helpers.image(item.brandIco, 640, 400),
name: item.brandName
});
brandId += item.id + ',';
}
});
}
return {
single,
brandId,
brands,
resourceId,
};
}
// 资源位大图幻灯
function largeSlideImg_APPParser(resData, shopId, resourceId) {
let bannerTop = [];
_.forEach(resData, (item) => {
if (item.data[0]) {
bannerTop.push({
url: _modifyAppUrl(item.data[0], shopId),
src: item.data[0].src,
resourceId,
});
}
});
return bannerTop;
}
// 热门品类
function recommend_APPParser(resData, shopId, resourceId) {
let hotCategory = {
list: [],
resourceId,
};
_.forEach(resData, cate => {
hotCategory.list.push({
url: _modifyAppUrl(cate, shopId),
src: helpers.image(cate.src),
name: cate.name
});
});
return hotCategory;
}
// 人气单品
function hotProducts_APPParser(resData, shopId, resourceId) {
let hotProduct = {
productSkn: '',
moreUrl: `http://m.yohobuy.com?openby:yohobuy={"action":"go.list","params":{"shop_id":"${shopId}","title":"人气单品"}}`,
resourceId,
};
let productSkn = '';
_.forEach(resData, value => {
productSkn += value.productSkn + ',';
});
hotProduct.productSkn = productSkn;
return hotProduct;
}
export function parseShopResources(json, shopId) {
let shopTopBanner_APP = '';
let oneRowTwoColImages_APP = [];
let brandBrowse = {};
let largeSlideImg_APP = [];
let recommend_APP = {};
let hotProducts_APP = {};
let logData = [];
_.forEach(json.list, floor => {
let resData = JSON.parse(floor.resource_data);
let resource_name = floor.resource_name;
let resourceId = floor.resource_id;
let logList = [];
switch(resource_name) {
case 'shopTopBanner_APP':
shopTopBanner_APP = shopTopBanner_APPParser(resData);
logList.push({
I_INDEX : '1',
ACTION_URL : '',
});
break;
case 'oneRowTwoColImages_APP':
oneRowTwoColImages_APP = oneRowTwoColImages_APPParser(resData, shopId,resourceId);
oneRowTwoColImages_APP.map((item, i) => {
logList.push({
I_INDEX : i + 1,
ACTION_URL : item.url,
});
});
break;
case 'brandBrowse':
brandBrowse = brandBrowseParser(resData, shopId, resourceId);
logList.push({
I_INDEX : '1',
BRAND_ID: brandBrowse.brandId,
});
break;
case 'largeSlideImg_APP':
largeSlideImg_APP = largeSlideImg_APPParser(resData, shopId, resourceId);
largeSlideImg_APP.map((item, i) => {
logList.push({
I_INDEX : i + 1,
ACTION_URL : item.url,
});
});
break;
case 'recommend_APP':
recommend_APP = recommend_APPParser(resData, shopId, resourceId);
recommend_APP.list.map((item, i) => {
logList.push({
I_INDEX : i + 1,
ACTION_URL : item.url,
});
});
break;
case 'hotProducts_APP':
hotProducts_APP = hotProducts_APPParser(resData, shopId, resourceId);
logList.push({
I_INDEX : '0',
PRODUCT_SKN: hotProducts_APP.productSkn,
MORE_URL : hotProducts_APP.moreUrl,
});
break;
}
if (logList.length > 0) {
logData.push({
F_NAME : resource_name,
F_ID : resourceId,
LIST: logList,
});
}
});
let data = {
shopTopBanner_APP,
oneRowTwoColImages_APP,
brandBrowse,
largeSlideImg_APP,
recommend_APP,
hotProducts_APP,
};
return {
data,
logData,
};
}