shop.js
4.26 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
/**
* Created by PhpStorm.
* User: Targaryen
* Date: 2016/7/26
* Time: 10:34
*/
'use strict';
const logger = global.yoho.logger;
const shopApi = require('./shop-api');
const processProductList = require(`${global.utils}/beautify/product`);
const camelCase = global.yoho.camelCase;
const _ = require('lodash');
const prettyFilter = require(`${global.utils}/beautify/filters`);
/**
* 获取品牌店铺数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getShopData = params => {
let finalResult = {};
return shopApi.getBrandInfoByDomain({
domain: params.domain
}).then(result => {
if (result.data) {
/* 品牌名称 */
Object.assign(finalResult, {
brandName: result.data.brand_name
});
/* 品牌是否有店铺 */
if (result.data.shop_id) {
/* 是 BLK 的店铺 */
Object.assign(finalResult, {
isBlkShop: true,
shopId: result.data.shop_id
});
return shopApi.getShopInfoData({
shopId: result.data.shop_id,
uid: params.uid
}).then(subResult => {
if (subResult.data) {
/* 取店铺的基本信息 */
Object.assign(finalResult, {
shopLogo: subResult.data.shop_logo,
shopName: subResult.data.shop_name,
shopIntro: subResult.data.shop_intro,
isFav: subResult.data.is_favorite === 'Y'
});
/* 取资源位店铺背景图 */
return shopApi.getShopsDecoratorList({
shopId: result.data.shop_id
}).then(thResult => {
if (thResult.data) {
_.forEach(thResult.data.list, value => {
if (value.resource_name === 'shopTopBanner_app') {
Object.assign(finalResult, {
shopBg: JSON.parse(value.resource_data).shopSrc
});
}
});
}
return finalResult;
});
}
return finalResult;
});
} else {
/* 不是 BLK 的店铺 */
Object.assign(finalResult, {
isBlkShop: false
});
logger.info('brand has no shop');
}
return finalResult;
}
return finalResult;
});
};
/**
* 获取品牌店铺商品数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getBrandShopGoodsData = params => {
let finalResult = {};
return shopApi.getBrandInfoByDomain({
domain: params.domain
}).then(result => {
if (result.data) {
return shopApi.getBrandShopGoodsOriginData(Object.assign(params, {
brand: result.data.id,
shopId: result.data.shop_id
})).then(subResult => {
if (subResult.data) {
prettyFilter(subResult.data.filter);
finalResult = {
data: {
productList: processProductList(subResult.data.product_list, {gender: params.gender}),
filter: subResult.data.filter,
page: subResult.data.page,
pageTotal: subResult.data.page_total
},
code: 200
};
}
return camelCase(finalResult);
});
}
return camelCase(finalResult);
});
};
/**
* 收藏店铺
* @param params
* @returns {*|Promise.<TResult>}
*/
const collectShopData = params => {
return shopApi.collectShopOriginData(params).then(result => {
return result;
});
};
module.exports = {
getShopData,
getBrandShopGoodsData,
collectShopData
};