plustar.js
3.65 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
'use strict';
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const _ = require('lodash');
const productProcess = require('../../../utils/product-process');
const logger = global.yoho.logger;
const camelCase = global.yoho.camelCase;
const formaData = (data, gender) => {
let build = [];
// console.log(data)
_.forEach(data, function(val) {
// 多张图
if (val.data[1]) {
let imgs = [];
_.forEach(val.data, function(list) {
let obj = {};
obj = _.assign(obj, {
url: '/plustar/brandinfo?id=' + val.id + '&gender=' + gender,
img: list.src,
deps: val.brand_title
});
imgs.push(obj);
});
build.push({
imgs: imgs
});
}
// 单张图
if (val.data[0]) {
_.forEach(val.data, function(list) {
build.push({
url: '/plustar/brandinfo?id=' + val.id + '&gender=' + gender,
img: list.src,
deps: val.brand_title
});
});
}
});
return build;
};
const getContentData = (gender, type) => {
return serviceAPI.get('guang/api/v3/plustar/getlist', {
gender: gender,
brand_type: type
}).then((result) => {
if (result && result.code === 200) {
// console.log(result)
return formaData(result.data.data.list[0].data, gender);
} else {
logger.error('列表 list data return code is not 200');
return {};
}
});
};
const getListData = (gender, recom, all) => {
return Promise.all([getContentData(gender, recom), getContentData(gender, all)]).then((result) => {
return {
star: result[0],
plus: result[1]
};
});
};
// 相关资讯
const getRelatedEditorial = () => {
};
// 是否收藏
const isCollection = (uid, brandId, clientType) => {
return serviceAPI.get('shops/service/v1/favorite/getUidBrandFav', {
uid: uid,
brandId: brandId,
client_type: clientType
}).then((result) => {
// console.log(result)
if (result && result.code === 200) {
// console.log(result.data)
let isLike = true;
return isLike;
} else {
let isLike = false;
return isLike;
}
});
};
// 品牌详情
const getBrandData = (id, clientType, uid) => {
return serviceAPI.get('guang/api/v1/plustar/getbrandinfo', {
id: id,
client_type: clientType
}).then((result) => {
if (result && result.code === 200) {
// console.log(result.data)
let list = result.data || [];
list = camelCase(list);
let brandId = result.data.brand_id;
return isCollection(uid, brandId, clientType).then((result) => {
// console.log(result)
list = _.assign(list, {
isLike: result
});
return list;
});
} else {
logger.error('detail data return code is not 200');
return {};
}
});
};
const getDetailData = (id, uid, udid, gender, isApp, clientType) => {
return Promise.all([getBrandData(id, clientType, uid), getRelatedEditorial(gender)]).then((result) => {
// console.log(result[0].brandDomain)
return {
brandInfo: result[0],
newArrival: result[1]
};
});
};
module.exports = {
getListData,
getContentData,
getDetailData
};