|
@@ -20,6 +20,8 @@ const DEFAULT_IMG = '01091c21f2317a64f123f1649fbbccf7ba'; |
|
@@ -20,6 +20,8 @@ const DEFAULT_IMG = '01091c21f2317a64f123f1649fbbccf7ba'; |
20
|
// 经典店铺list url
|
20
|
// 经典店铺list url
|
21
|
const shopListUrl = '/product/shoplist';
|
21
|
const shopListUrl = '/product/shoplist';
|
22
|
|
22
|
|
|
|
23
|
+const needParams = ['query', 'msort', 'misort', 'category_id', 'gender', 'shelveTime'];
|
|
|
24
|
+
|
23
|
/**
|
25
|
/**
|
24
|
* channel=>gender
|
26
|
* channel=>gender
|
25
|
*/
|
27
|
*/
|
|
@@ -266,42 +268,158 @@ const _getShopData = (channel, params, shopInfo) => { |
|
@@ -266,42 +268,158 @@ const _getShopData = (channel, params, shopInfo) => { |
266
|
})();
|
268
|
})();
|
267
|
};
|
269
|
};
|
268
|
|
270
|
|
|
|
271
|
+
|
|
|
272
|
+/**
|
|
|
273
|
+ * 获取基础模板店铺数据
|
|
|
274
|
+ */
|
|
|
275
|
+const _getBaseShopData = (channel, params, shopInfo) => {
|
|
|
276
|
+ params = params || {};
|
|
|
277
|
+
|
|
|
278
|
+ let searchParams = searchHandler.getSearchParams(params);
|
|
|
279
|
+ let shopId = params.shopId;
|
|
|
280
|
+
|
|
|
281
|
+ return co(function * () {
|
|
|
282
|
+ let result = yield Promise.props({
|
|
|
283
|
+ header: headerModel.requestHeaderData(channel), // 头部数据
|
|
|
284
|
+ sort: searchApi.getSortList({shop_id: shopId}),
|
|
|
285
|
+ decorator: searchApi.getShopDecorator(shopId), // 店铺装修数据
|
|
|
286
|
+ product: searchApi.getProductList(Object.assign(searchParams,
|
|
|
287
|
+ {shop_id: shopId}), 'shop'), // 搜索店铺商品
|
|
|
288
|
+ coupons: api.shopCouponListAsync(shopId), // 店铺优惠券数据
|
|
|
289
|
+ shopInfo: shopInfo ? Promise.resolve(shopInfo) : api.getShopInfo(shopId)
|
|
|
290
|
+ });
|
|
|
291
|
+
|
|
|
292
|
+ if (result.shopInfo && result.shopInfo.code === 200) {
|
|
|
293
|
+ shopInfo = result.shopInfo.data;
|
|
|
294
|
+ }
|
|
|
295
|
+
|
|
|
296
|
+ const shopName = shopInfo.shop_name;
|
|
|
297
|
+
|
|
|
298
|
+ let resData = {
|
|
|
299
|
+ shopId: shopId,
|
|
|
300
|
+ brand: Object.assign({brandShopAd: true},
|
|
|
301
|
+ searchHandler.handlePathNavData({brandName: shopName}, params, 'shop', channel))
|
|
|
302
|
+ };
|
|
|
303
|
+
|
|
|
304
|
+ Object.assign(resData,
|
|
|
305
|
+ result.header, // 头部数据
|
|
|
306
|
+ searchHandler.getBrandShopSeo(channel, {shopName: shopName}, params));
|
|
|
307
|
+
|
|
|
308
|
+ _.set(resData, 'headerData.header', true);
|
|
|
309
|
+ _.set(resData, 'brand.shopBanner', {
|
|
|
310
|
+ shopId: shopId,
|
|
|
311
|
+ shopName: shopName,
|
|
|
312
|
+ shopHome: `/?shopId=${shopId}`,
|
|
|
313
|
+ shopIntro: `/shop${shopId}-about`
|
|
|
314
|
+ });
|
|
|
315
|
+
|
|
|
316
|
+ // 店铺装修
|
|
|
317
|
+ if (result.decorator.code === 200) {
|
|
|
318
|
+ let data = result.decorator.data || {},
|
|
|
319
|
+ decorator = shopHandler.getShopDecorator(data, {}, shopId, true);
|
|
|
320
|
+
|
|
|
321
|
+ Object.assign(resData.brand.shopBanner, decorator.shopTopBannerBase || {});
|
|
|
322
|
+
|
|
|
323
|
+ // 设置店招高度
|
|
|
324
|
+ _.set(resData, 'brand.shopBanner.bannerHeight', 150);
|
|
|
325
|
+
|
|
|
326
|
+ if (decorator.signboard) {
|
|
|
327
|
+ _.set(resData, 'brand.signboard', decorator.signboard);
|
|
|
328
|
+ }
|
|
|
329
|
+ }
|
|
|
330
|
+
|
|
|
331
|
+ // 获取左侧类目数据
|
|
|
332
|
+ if (result.sort.code === 200) {
|
|
|
333
|
+ let dps = {shopId: shopId};
|
|
|
334
|
+
|
|
|
335
|
+ _.forEach(needParams, value => {
|
|
|
336
|
+ if (params[value]) {
|
|
|
337
|
+ dps[value] = params[value];
|
|
|
338
|
+ }
|
|
|
339
|
+ });
|
|
|
340
|
+
|
|
|
341
|
+ Object.assign(resData.brand, {
|
|
|
342
|
+ leftContent: searchHandler.handleSortData(result.sort.data, dps, params)
|
|
|
343
|
+ });
|
|
|
344
|
+ }
|
|
|
345
|
+
|
|
|
346
|
+ // 获取商品数据和顶部筛选条件
|
|
|
347
|
+ if (result.product.code === 200) {
|
|
|
348
|
+ let data = result.product.data;
|
|
|
349
|
+ let filters = Object.assign(searchHandler.handleFilterDataAll(data, params),
|
|
|
350
|
+ resData.brand.leftContent.sort);
|
|
|
351
|
+
|
|
|
352
|
+ filters.checkedConditions.conditions = _.concat(filters.checkedConditions.conditions,
|
|
|
353
|
+ resData.brand.leftContent.checked);
|
|
|
354
|
+
|
|
|
355
|
+ Object.assign(resData.brand, {
|
|
|
356
|
+ filters: filters,
|
|
|
357
|
+ opts: searchHandler.handleOptsData(params, data.total, data.filter),
|
|
|
358
|
+ totalCount: data.total,
|
|
|
359
|
+ footPager: searchHandler.handlePagerData(data.total, params),
|
|
|
360
|
+ goods: productProcess.processProductList(data.product_list,
|
|
|
361
|
+ Object.assign({showDiscount: false, from: {type: 'shop', params: params}}, params)),
|
|
|
362
|
+ hasNextPage: searchHandler.handleNextPage(params, data.total),
|
|
|
363
|
+
|
|
|
364
|
+ // 最近浏览记录
|
|
|
365
|
+ latestWalk: 7
|
|
|
366
|
+ });
|
|
|
367
|
+
|
|
|
368
|
+ // 店铺页不显示品牌筛选项
|
|
|
369
|
+ _.unset(resData, 'brand.filters.brand');
|
|
|
370
|
+ }
|
|
|
371
|
+
|
|
|
372
|
+ // 店铺优惠券
|
|
|
373
|
+ if (result.coupons && !_.isEmpty(result.coupons.data)) {
|
|
|
374
|
+ _.set(resData, 'brand.coupon',
|
|
|
375
|
+ searchHandler.handleBrandShopCoupons(result.coupons.data, {shopId: shopId}));
|
|
|
376
|
+ }
|
|
|
377
|
+
|
|
|
378
|
+ return resData;
|
|
|
379
|
+ })();
|
|
|
380
|
+};
|
|
|
381
|
+
|
269
|
exports.getShopInfoAsync = (domain, channel, params) => {
|
382
|
exports.getShopInfoAsync = (domain, channel, params) => {
|
|
|
383
|
+ let resData;
|
270
|
let shopId = _.get(params, 'shopId');
|
384
|
let shopId = _.get(params, 'shopId');
|
271
|
|
385
|
|
272
|
return co(function * () {
|
386
|
return co(function * () {
|
|
|
387
|
+ let data, shopInfo;
|
|
|
388
|
+
|
273
|
_.unset(params, 'domain');
|
389
|
_.unset(params, 'domain');
|
|
|
390
|
+ domain = _.toLower(domain);
|
274
|
|
391
|
|
275
|
- if (shopId) {
|
392
|
+ if (shopId) { // 带id访问
|
276
|
let result = yield api.getShopInfo(shopId);
|
393
|
let result = yield api.getShopInfo(shopId);
|
277
|
- let data = result.data;
|
394
|
+
|
|
|
395
|
+ data = result.data;
|
278
|
|
396
|
|
279
|
// 根据店铺ID,未取到店铺信息,跳转至首页
|
397
|
// 根据店铺ID,未取到店铺信息,跳转至首页
|
280
|
if (result.code !== 200 || _.isEmpty(data)) {
|
398
|
if (result.code !== 200 || _.isEmpty(data)) {
|
281
|
return {redirect: helpers.urlFormat('')};
|
399
|
return {redirect: helpers.urlFormat('')};
|
282
|
}
|
400
|
}
|
283
|
|
401
|
|
|
|
402
|
+ let lowResDomain = _.toLower(data.shop_domain);
|
|
|
403
|
+
|
284
|
// 根据店铺ID取到的店铺domain与链接中domain不一致,跳转至店铺域名下(解决店铺域名与品牌域名混用的问题)
|
404
|
// 根据店铺ID取到的店铺domain与链接中domain不一致,跳转至店铺域名下(解决店铺域名与品牌域名混用的问题)
|
285
|
- if (data.shop_domain !== domain) {
|
|
|
286
|
- return {redirect: helpers.urlFormat('', params, data.shop_domain)};
|
405
|
+ if (lowResDomain !== domain) {
|
|
|
406
|
+ return {redirect: helpers.urlFormat('', params, lowResDomain)};
|
287
|
}
|
407
|
}
|
288
|
|
408
|
|
289
|
- if (+data.shop_template_type === 2) {
|
|
|
290
|
- let resData = yield _getShopData(channel, params, data);
|
|
|
291
|
-
|
|
|
292
|
- return Object.assign(resData, {templateType: +data.shop_template_type});
|
|
|
293
|
- }
|
|
|
294
|
- } else {
|
409
|
+ shopInfo = data;
|
|
|
410
|
+ } else { // 以店铺域名方式直接访问
|
295
|
let result = yield searchApi.getBrandData({domain: domain});
|
411
|
let result = yield searchApi.getBrandData({domain: domain});
|
296
|
- let data = result.data;
|
|
|
297
|
|
412
|
|
|
|
413
|
+ data = result.data;
|
|
|
414
|
+
|
|
|
415
|
+ // 未取到domain信息,跳转至首页
|
298
|
if (result.code !== 200) {
|
416
|
if (result.code !== 200) {
|
299
|
return {redirect: helpers.urlFormat('')};
|
417
|
return {redirect: helpers.urlFormat('')};
|
300
|
}
|
418
|
}
|
301
|
|
419
|
|
302
|
// domain类型不为店铺,跳转至搜索
|
420
|
// domain类型不为店铺,跳转至搜索
|
303
|
if (data.type * 1 !== 2) {
|
421
|
if (data.type * 1 !== 2) {
|
304
|
- let d = {query: _.toLower(domain)};
|
422
|
+ let d = {query: domain};
|
305
|
|
423
|
|
306
|
if (data.id) {
|
424
|
if (data.id) {
|
307
|
d.brand = data.id;
|
425
|
d.brand = data.id;
|
|
@@ -311,13 +429,15 @@ exports.getShopInfoAsync = (domain, channel, params) => { |
|
@@ -311,13 +429,15 @@ exports.getShopInfoAsync = (domain, channel, params) => { |
311
|
}
|
429
|
}
|
312
|
|
430
|
|
313
|
params.shopId = data.shop_id;
|
431
|
params.shopId = data.shop_id;
|
|
|
432
|
+ }
|
314
|
|
433
|
|
315
|
- if (+data.shop_template_type === 2) {
|
|
|
316
|
- let resData = yield _getShopData(channel, params);
|
|
|
317
|
-
|
|
|
318
|
- return Object.assign(resData, {templateType: +data.shop_template_type});
|
|
|
319
|
- }
|
434
|
+ if (+data.shop_template_type === 2) { // 经典店铺
|
|
|
435
|
+ resData = yield _getShopData(channel, params, shopInfo);
|
|
|
436
|
+ } else {
|
|
|
437
|
+ resData = yield _getBaseShopData(channel, params, shopInfo);
|
320
|
}
|
438
|
}
|
|
|
439
|
+
|
|
|
440
|
+ return Object.assign(resData, {templateType: +data.shop_template_type});
|
321
|
})();
|
441
|
})();
|
322
|
};
|
442
|
};
|
323
|
|
443
|
|