tide.js
5.72 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
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
const ROOTPATH = '../../../';
const contentCodeConfig = require(`${ROOTPATH}config/content-code`);
const productProcess = require(`${ROOTPATH}utils/product-process`);
class TideModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
tideCategory(params) {
return Promise.all([
this.getResource(Object.assign({
content_code: contentCodeConfig.tide.category
}, params)),
this.crmRecommendSort(params)
]).then(res => {
let tide = {
resource: _.get(res[0], 'data', []),
contents: []
};
let sindex = _.findIndex(tide.resource, {template_name: 'image_list'});
if (sindex > -1) {
tide.resource[sindex].title = '# 精彩活动 #';
}
_.each(_.get(res[1], 'data', []), (item, index) => {
item.sortInfo = item.sortInfo || {};
let goods = productProcess.processProductList(item.productList || [], {
isApp: params.isApp,
showSimilar: false
});
let tdata = {
sortInfo: Object.assign({}, item.sortInfo, {
url: helpers.urlFormat(`/list/mi${item.sortInfo.itemId}`, {
'openby:yohobuy': `{"action":"go.list","params":{"misort":"${item.sortInfo.itemId}"}}`
})
}),
goods: goods
};
if (index === 0) {
tdata.title = '# 潮品推介 #';
} else {
tdata.borderTop = true;
}
tide.contents.push(tdata);
});
return tide;
});
}
// 促购个性化3个品类商品推荐
crmRecommendSort(params) {
return this.get({
data: Object.assign({
method: 'app.product.crmRecommend.sort'
}, params)
});
}
// 促购个性化店铺商品推荐(1个店铺+店铺下6个商品)
crmRecommendShopSix(params) {
return this.get({
data: Object.assign({
method: 'app.product.crmRecommend.shopSix'
}, params)
});
}
// 促购个性化店铺推荐(9个店铺)
crmRecommendShop(params) {
return this.get({
data: Object.assign({
method: 'app.product.crmRecommend.shop',
imageType: 2,
imageSize: '314*352',
}, params)
});
}
// 促购个性化店铺推荐(30个商品)
crmRecommendProduct(params) {
return this.get({
data: Object.assign({
method: 'app.product.crmRecommend.product'
}, params)
});
}
tideShop(params) {
return Promise.all([
this.getResource(Object.assign({
content_code: contentCodeConfig.tide.brand
}, params)),
this.crmRecommendShopSix(params),
this.crmRecommendShop(params),
this.crmRecommendProduct(params)
]).then(res => {
let tide = {
resource: _.get(res[0], 'data', []),
brands: [],
shopInfo: [],
contents: []
};
let sindex = _.findIndex(tide.resource, {template_name: 'image_list'});
if (sindex > -1) {
tide.resource[sindex].title = '# 精彩活动 #';
}
let shopInfo = _.get(res[1], 'data.shopInfo', {});
if (shopInfo.shopId) {
shopInfo.url = helpers.urlFormat(`/shop/${shopInfo.shopDomain}-${shopInfo.shopId}.html`, {
'openby:yohobuy': `{"action":"go.shop","params":{"shop_id":"${shopInfo.shopId}","shop_template_type":"${shopInfo.shopTemplateType}","shop_name":"${shopInfo.shopName}"}}` //eslint-disable-line
});
}
if (shopInfo.imageUrl || _.get(res[1], 'data.productList', []).length) {
tide.shopInfo.push({
title: '# 为你精选 #',
shopInfo: shopInfo,
goods: productProcess.processProductList(_.get(res[1], 'data.productList', []), {
isApp: params.isApp,
showSimilar: false
})
});
}
_.each(_.get(res[2], 'data', []), (item) => {
tide.brands.push(Object.assign({}, item, {
url: helpers.urlFormat(`/shop/${item.shopDomain}-${item.shopId}.html`, {
'openby:yohobuy': `{"action":"go.shop","params":{"shop_id":"${item.shopId}","shop_template_type":"${item.shopTemplateType}","shop_name":"${item.shopName}"}}` //eslint-disable-line
})
}));
});
if (_.get(res[3], 'data', []).length) {
tide.contents.push({
title: '# 潮品推介 #',
goods: productProcess.processProductList(_.get(res[3], 'data', []), {
isApp: params.isApp,
showSimilar: false
})
});
}
return tide;
});
}
getResource(params) {
return this.get({
url: 'operations/api/v5/resource/get',
data: Object.assign({
platform: 'iphone'
}, params),
api: global.yoho.ServiceAPI,
param: {cache: true}
}).then(result => {
return result;
});
}
}
module.exports = TideModel;