|
@@ -12,233 +12,6 @@ const _ = require('lodash'); |
|
@@ -12,233 +12,6 @@ const _ = require('lodash'); |
12
|
const helpers = global.yoho.helpers;
|
12
|
const helpers = global.yoho.helpers;
|
13
|
|
13
|
|
14
|
/**
|
14
|
/**
|
15
|
- * 组织店铺页面数据
|
|
|
16
|
- * @param {array} data 接口返回的店铺页所需数据
|
|
|
17
|
- * @param {int} shopId 店铺id
|
|
|
18
|
- * @param {int} isApp app版本
|
|
|
19
|
- * @return array
|
|
|
20
|
- */
|
|
|
21
|
-const _formShopData = (data, shopId, isApp) => {
|
|
|
22
|
- let formatData = {
|
|
|
23
|
- shopId: shopId,
|
|
|
24
|
- appVersion: isApp
|
|
|
25
|
- },
|
|
|
26
|
- single = false;
|
|
|
27
|
- let brandId;
|
|
|
28
|
-
|
|
|
29
|
- // 组织店铺装修
|
|
|
30
|
- if (data.decorator) {
|
|
|
31
|
- _.forEach(data.decorator.list, (floor) => {
|
|
|
32
|
- let resData = JSON.parse(floor.resourceData);
|
|
|
33
|
-
|
|
|
34
|
- floor[_.camelCase(floor.resourceName)] = true;
|
|
|
35
|
-
|
|
|
36
|
- // 店铺banner
|
|
|
37
|
- if (floor.shopTopBannerApp) {
|
|
|
38
|
- formatData.branerImg = resData[0].shopSrc;
|
|
|
39
|
- }
|
|
|
40
|
-
|
|
|
41
|
- // 资源位小图 接口返回两组,取每组第一张
|
|
|
42
|
- if (floor.oneRowTwoColImagesApp) {
|
|
|
43
|
- let spring = [];
|
|
|
44
|
-
|
|
|
45
|
- _.forEach(resData, (item) => {
|
|
|
46
|
- if (item.data) {
|
|
|
47
|
- spring.push({
|
|
|
48
|
- url: isApp ? listModel.modifyAppUrl(item.data[0], shopId) :
|
|
|
49
|
- listModel.modifyWapUrl(item.data[0], shopId),
|
|
|
50
|
- springType: helpers.image(item.data[0].src)
|
|
|
51
|
- });
|
|
|
52
|
- }
|
|
|
53
|
- });
|
|
|
54
|
-
|
|
|
55
|
- formatData.spring = spring;
|
|
|
56
|
- }
|
|
|
57
|
-
|
|
|
58
|
-
|
|
|
59
|
- // 店铺品牌一览
|
|
|
60
|
- if (floor.brandBrowse) {
|
|
|
61
|
- let brandNumber = resData.length;
|
|
|
62
|
- let brand = {
|
|
|
63
|
- list: []
|
|
|
64
|
- };
|
|
|
65
|
-
|
|
|
66
|
- brandId = '';
|
|
|
67
|
-
|
|
|
68
|
- // 少于2个不展示 单品店:单品店根据品牌id查询
|
|
|
69
|
- if (brandNumber < 2) {
|
|
|
70
|
- brandId = formatData.brand = resData[0].id;
|
|
|
71
|
- single = true;
|
|
|
72
|
- } else {
|
|
|
73
|
- _.forEach(resData, (item) => {
|
|
|
74
|
- if (item.brandDomain) {
|
|
|
75
|
- brand.list.push({
|
|
|
76
|
- url: helpers.urlFormat('', '', item.brandDomain) + (isApp ? `?openby:yohobuy={"action":"go.brand","params":{"shop_id":${shopId},"brand_id":${item.id}}}` : ''), //eslint-disable-line
|
|
|
77
|
- img: helpers.image(item.brandIco, 640, 400),
|
|
|
78
|
- brandName: item.brandName
|
|
|
79
|
- });
|
|
|
80
|
- brandId += item.id + ',';
|
|
|
81
|
- }
|
|
|
82
|
- });
|
|
|
83
|
-
|
|
|
84
|
- formatData.brandList = brand;
|
|
|
85
|
-
|
|
|
86
|
- // 大于5个返回更多品牌链接
|
|
|
87
|
- if (brandNumber > 5) {
|
|
|
88
|
- formatData.brandList.url = helpers.urlFormat('/product/index/allBrand', {
|
|
|
89
|
- shop_id: shopId
|
|
|
90
|
- });
|
|
|
91
|
- }
|
|
|
92
|
- }
|
|
|
93
|
- }
|
|
|
94
|
-
|
|
|
95
|
- // 资源位大图幻灯
|
|
|
96
|
- if (floor.largeSlideImgApp) {
|
|
|
97
|
- let bannerTop = {
|
|
|
98
|
- data: []
|
|
|
99
|
- };
|
|
|
100
|
-
|
|
|
101
|
- _.forEach(resData, (item) => {
|
|
|
102
|
- if (item.data[0]) {
|
|
|
103
|
- bannerTop.data.push({
|
|
|
104
|
- url: isApp ? listModel.modifyAppUrl(item.data[0], shopId) :
|
|
|
105
|
- listModel.modifyWapUrl(item.data[0], shopId),
|
|
|
106
|
- src: item.data[0].src
|
|
|
107
|
- });
|
|
|
108
|
- }
|
|
|
109
|
- });
|
|
|
110
|
-
|
|
|
111
|
- formatData.bannerTop = bannerTop;
|
|
|
112
|
- }
|
|
|
113
|
-
|
|
|
114
|
- // 热门品类
|
|
|
115
|
- if (floor.recommendApp) {
|
|
|
116
|
- let hotCategory = {
|
|
|
117
|
- data: {
|
|
|
118
|
- title: {
|
|
|
119
|
- title: '热门品类'
|
|
|
120
|
- },
|
|
|
121
|
- list: []
|
|
|
122
|
- }
|
|
|
123
|
- };
|
|
|
124
|
-
|
|
|
125
|
- _.forEach(resData, (cate) => {
|
|
|
126
|
- hotCategory.data.list.push({
|
|
|
127
|
- url: cate.url,
|
|
|
128
|
- src: helpers.image(cate.src)
|
|
|
129
|
- });
|
|
|
130
|
- });
|
|
|
131
|
-
|
|
|
132
|
- formatData.hotCategory = hotCategory;
|
|
|
133
|
- }
|
|
|
134
|
-
|
|
|
135
|
- // 人气单品
|
|
|
136
|
- if (floor.hotProductsApp) {
|
|
|
137
|
- let goods = [];
|
|
|
138
|
-
|
|
|
139
|
- _.forEach(resData, (item) => {
|
|
|
140
|
- let url = '//item.yohobuy.com/product/pro_';
|
|
|
141
|
-
|
|
|
142
|
- if (!item.cnAlphabet) {
|
|
|
143
|
- item.cnAlphabet = 'goods.html';
|
|
|
144
|
- }
|
|
|
145
|
- url += item.productId + '_' + item.goodsId + '/' + item.cnAlphabet + '.html';
|
|
|
146
|
- goods.push({
|
|
|
147
|
- url: url + (isApp ? `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":${item.productSkn}}}` : ''),//eslint-disable-line
|
|
|
148
|
- img: helpers.image(item.src, 235, 314),
|
|
|
149
|
- productName: item.productName,
|
|
|
150
|
- salesPrice: item.salesPrice,
|
|
|
151
|
- presentPrice: item.salesPrice
|
|
|
152
|
- });
|
|
|
153
|
- });
|
|
|
154
|
-
|
|
|
155
|
- formatData.hotList = goods;
|
|
|
156
|
- }
|
|
|
157
|
- });
|
|
|
158
|
- }
|
|
|
159
|
-
|
|
|
160
|
- // 店铺基本信息
|
|
|
161
|
- if (data.shopInfo) {
|
|
|
162
|
- let allGoodsParam = {
|
|
|
163
|
- title: '全部商品'
|
|
|
164
|
- };
|
|
|
165
|
-
|
|
|
166
|
- formatData = _.assign({
|
|
|
167
|
- logoImg: data.shopInfo.shopLogo,
|
|
|
168
|
- storeName: (data.shopInfo.isShowShopName === 'Y') ? data.shopInfo.shopName : '',
|
|
|
169
|
- collect: data.shopInfo.isFavorite === 'Y',
|
|
|
170
|
- url: helpers.urlFormat('', {
|
|
|
171
|
- shop_id: shopId
|
|
|
172
|
- }, 'search'), // 搜索链接
|
|
|
173
|
- more_url: helpers.urlFormat('', {
|
|
|
174
|
- shop_id: shopId,
|
|
|
175
|
- order: 's_n_d',
|
|
|
176
|
- title: '人气单品'
|
|
|
177
|
- }, 'search') // 人气单品的链接
|
|
|
178
|
- }, formatData);
|
|
|
179
|
-
|
|
|
180
|
- if (single) { // 单品点
|
|
|
181
|
- allGoodsParam.brand = brandId;
|
|
|
182
|
- } else { // 店铺id
|
|
|
183
|
- formatData.shopId = shopId;
|
|
|
184
|
- allGoodsParam.shopId = shopId;
|
|
|
185
|
- }
|
|
|
186
|
-
|
|
|
187
|
- if (!isApp) {
|
|
|
188
|
- formatData = _.assign({
|
|
|
189
|
- allGoods: helpers.urlFormat('', allGoodsParam, 'search'),
|
|
|
190
|
- shopIntroHref: helpers.urlFormat('/product/index/intro', {
|
|
|
191
|
- shop_id: shopId
|
|
|
192
|
- }) // 店铺简介页地址
|
|
|
193
|
- }, formatData);
|
|
|
194
|
- } else {
|
|
|
195
|
- formatData = _.assign({
|
|
|
196
|
- allGoods: `${helpers.urlFormat('', allGoodsParam, 'search')}&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":${shopId},"page":"1"}}`,//eslint-disable-line
|
|
|
197
|
- shopIntroHref: helpers.urlFormat('/product/index/intro', {
|
|
|
198
|
- shop_id: shopId,
|
|
|
199
|
- app_version: isApp
|
|
|
200
|
- }),
|
|
|
201
|
- more_url: formatData.more_url + `?openby:yohobuy={"action":"go.list","params":{"shop_id":${shopId},"title":"人气单品"}}`//eslint-disable-line
|
|
|
202
|
- }, formatData);
|
|
|
203
|
- }
|
|
|
204
|
- }
|
|
|
205
|
-
|
|
|
206
|
- // 店铺下面的所有分类
|
|
|
207
|
- if (data.shopCategory) {
|
|
|
208
|
- let total = data.shopCategory.length;
|
|
|
209
|
- let shopCategory = {
|
|
|
210
|
- list: []
|
|
|
211
|
- };
|
|
|
212
|
-
|
|
|
213
|
- if (total > 6) {
|
|
|
214
|
- shopCategory.url = helpers.urlFormat('/product/index/category', {
|
|
|
215
|
- shop_id: shopId
|
|
|
216
|
- });
|
|
|
217
|
- } else {
|
|
|
218
|
- _.forEach(data.shopCategory, (item) => {
|
|
|
219
|
- shopCategory.list.push({
|
|
|
220
|
- url: helpers.urlFormat('', {
|
|
|
221
|
- shop_id: shopId,
|
|
|
222
|
- sort: item.relationParameter.sort
|
|
|
223
|
- }, 'search'),
|
|
|
224
|
- categoryId: item.categoryId,
|
|
|
225
|
- name: item.categoryName
|
|
|
226
|
- });
|
|
|
227
|
- });
|
|
|
228
|
- }
|
|
|
229
|
-
|
|
|
230
|
- formatData.shopCategory = shopCategory;
|
|
|
231
|
- }
|
|
|
232
|
-
|
|
|
233
|
- if (single) {
|
|
|
234
|
- formatData.favId = shopId;
|
|
|
235
|
- formatData.shopId = '';
|
|
|
236
|
- }
|
|
|
237
|
-
|
|
|
238
|
- return formatData;
|
|
|
239
|
-};
|
|
|
240
|
-
|
|
|
241
|
-/**
|
|
|
242
|
* 新店铺首页
|
15
|
* 新店铺首页
|
243
|
* @param {object} req
|
16
|
* @param {object} req
|
244
|
* @param {int} shopId 店铺id
|
17
|
* @param {int} shopId 店铺id
|
|
@@ -246,29 +19,30 @@ const _formShopData = (data, shopId, isApp) => { |
|
@@ -246,29 +19,30 @@ const _formShopData = (data, shopId, isApp) => { |
246
|
* @param {string} isApp app版本
|
19
|
* @param {string} isApp app版本
|
247
|
*/
|
20
|
*/
|
248
|
const _getShopData = (req, shopId, uid, isApp) => {
|
21
|
const _getShopData = (req, shopId, uid, isApp) => {
|
249
|
- let data = {};
|
22
|
+ let shopData = {};
|
250
|
let channel = req.yoho.channel;
|
23
|
let channel = req.yoho.channel;
|
251
|
|
24
|
|
252
|
return Promise.all([listModel.getShopDecorator(shopId), listModel.getShopInfo(shopId, uid)]).then((result) => {
|
25
|
return Promise.all([listModel.getShopDecorator(shopId), listModel.getShopInfo(shopId, uid)]).then((result) => {
|
253
|
- data = {
|
26
|
+ shopData = {
|
254
|
decorator: result[0], // 店铺装修资源数据
|
27
|
decorator: result[0], // 店铺装修资源数据
|
255
|
shopInfo: result[1] // 店铺信息
|
28
|
shopInfo: result[1] // 店铺信息
|
256
|
};
|
29
|
};
|
257
|
|
30
|
|
258
|
// 店铺使用基础模板,返回品牌页面
|
31
|
// 店铺使用基础模板,返回品牌页面
|
259
|
- if (data.shopInfo.shopTemplateType && data.shopInfo.shopTemplateType === '1') {
|
32
|
+ if (shopData.shopInfo.shopTemplateType && shopData.shopInfo.shopTemplateType === '1') {
|
260
|
return {
|
33
|
return {
|
261
|
- goBrand: data.shopInfo
|
34
|
+ goBrand: shopData.shopInfo
|
262
|
};
|
35
|
};
|
263
|
}
|
36
|
}
|
264
|
|
37
|
|
265
|
// 店铺分类
|
38
|
// 店铺分类
|
266
|
return listModel.getShopCategory(shopId, channel).then((shopCategory) => {
|
39
|
return listModel.getShopCategory(shopId, channel).then((shopCategory) => {
|
267
|
- data = _.assign({
|
40
|
+ shopData = _.assign({
|
268
|
shopCategory: shopCategory
|
41
|
shopCategory: shopCategory
|
269
|
- }, data);
|
42
|
+ }, shopData);
|
270
|
|
43
|
|
271
|
- return _formShopData(data, shopId, isApp); // 组织楼层数据
|
44
|
+ //noinspection JSCheckFunctionSignatures
|
|
|
45
|
+ return listModel.formShopData(shopData, shopId, isApp); // 组织楼层数据
|
272
|
});
|
46
|
});
|
273
|
});
|
47
|
});
|
274
|
};
|
48
|
};
|