brand.js
6.89 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
/**
* Created by PhpStorm.
* User: Targaryen
* Date: 2016/7/19
* Time: 13:51
*/
'use strict';
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const brandApi = require('./brand-api');
const logger = global.yoho.logger;
const _ = require('lodash');
/**
* 处理品牌一览品牌列表数据
* @param origin
* @returns {Array}
*/
const handleBrandList = origin => {
let dest = {
brandList: [],
indexList: []
};
_.forEach(origin, (value, key) => {
let brands = [];
_.forEach(value, (subValue) => {
brands.push({
name: subValue.brand_name,
link: helpers.urlFormat('', null, subValue.brand_domain),
logo: subValue.brand_ico
});
});
dest.brandList.push({
index: key,
brands: brands
});
dest.indexList.push({
index: key,
name: key === '0~9' ? '0' : key
});
});
return dest;
};
/**
* 获取品牌店铺数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getBrandData = params => {
let finalResult = {};
return api.all([
brandApi.getBrandInfoByDomain({domain: params.domain})
]).then(result => {
if (result[0].code === 200) {
/* 品牌有店铺 */
if (result[0].data.shop_id) {
return api.all([
brandApi.getShopInfoData({
shopId: result[0].data.shop_id,
uid: params.uid
})
]).then(subResult => {
if (subResult[0].code === 200) {
/* TODO 判断是否是使用 BLK 模板,不使用 BLK 模板的就直接返回 */
if (subResult[0].data.shop_template_type === 2) {
Object.assign(finalResult, {
brandBg: 'http://7xwj52.com1.z0.glb.clouddn.com/brandbg.jpg',
showBrandLogo: false,
brandLogo: 'https://img11.static.yhbimg.com/brandLogo/2016/04/13/15/010eb8606c1072fd2e769c62567d3bbe93.png?imageView2/2/w/140/h/140',
brandName: 'A.Dorad',
brandIntro: 'Dora毕业于中国美术学院的珠宝设计专业。毕业之后,Dora便开始游走于各国,吸收各地首饰设计的精髓,之后又在首尔修学了3年,A.Dorad饰品系列诞生于首尔, 设计师Dora将首尔设为起点并逐步推向国际。2013年,A.Dorad将旗下主力设计师带领进军广州,并以此为基地,以国际化的标准,设计出全新概念饰品。A.Dorad给人们提供高品质的服务,并且拥有独有的工艺。多样的珠宝首饰产品造型更衬托出其前卫、高雅的设计理念。珍贵的矿石搭配流行的创意理念,启迪了人类艺术。A.Dorad饰品符合现代年轻人对珠宝的追求与热爱,充满个性与时尚.它可以满足不同人的需求独家定制专属于自己的水晶饰品。A.Dorad将继续发挥无与伦比的创造力并开启通往浪漫梦幻的大门。',
showMore: false
});
} else {
logger.info('no BLK template');
}
} else {
logger.error('getShopInfoData api code no 200');
}
});
} else {
logger.info('brand has no shop');
}
} else {
logger.error('getBrandOriginData api code no 200');
}
return finalResult;
});
};
/**
* 获取品牌店铺商品数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getBrandShopGoodsData = params => {
let finalResult = {};
return api.all([brandApi.getBrandShopGoodsOriginData(params)]).then(result => {
});
};
/**
* 获取品牌列表页数据
* @param params
*/
const getBrandListData = params => {
let finalResult = {};
return api.all([brandApi.getBrandListOriginData(params)]).then(result => {
if (result[0].code === 200 && result[0].data.all_list) {
Object.assign(finalResult, handleBrandList(result[0].data.all_list));
} else {
logger.error('getBrandListOriginData api code no 200 or allList is null');
}
return finalResult;
});
};
/**
* 获取全部分类数据
* @param params
* @returns {*|Promise.<TResult>}
*/
const getCateListData = params => {
let finalResult = [];
let item = {};
let oneClass = [];
let subitem = {};
let genderArr = {boy: '1,3', girl: '2,3', kids: '1,2,3', lifestyle: '1,2,3'};
return brandApi.getCateListData(params).then(result => {
if (result.code !== 200) {
return [];
}
_.forEach(result.data, (category, categorykey) => {
oneClass = {name: categorykey, ca: []};
_.forEach(category, (cate) => {
item = {
id: cate.category_id,
name: cate.category_name,
sort: cate.relation_parameter.sort,
sub: []
};
if (_.isEmpty(cate.sub)) {
item.url = helpers.urlFormat('/', {
sort: item.sort,
sort_name: item.name,
gender: genderArr[categorykey]
}, 'list');
oneClass.ca.push(item);
return true;// equal continue;
}
// 有子分类的,首先添加一级分类
item.sub.push({
id: item.id,
name: '全部' + item.name,
sort: item.sort,
url: helpers.urlFormat('/', {
sort: item.sort,
sort_name: item.name,
gender: genderArr[categorykey]
}, 'list'),
sub: []
});
_.forEach(cate.sub, (sub) => {
subitem = {
id: sub.category_id,
name: sub.category_name,
sort: sub.relation_parameter.sort,
url: ''
};
subitem.url = helpers.urlFormat('/', {
sort: subitem.sort,
sort_name: subitem.name,
gender: genderArr[categorykey]
}, 'list');
item.sub.push(subitem);
});
oneClass.ca.push(item);
});
finalResult.push(oneClass);
});
return finalResult;
});
};
module.exports = {
getBrandData,
getBrandShopGoodsData,
getBrandListData,
getCateListData
};