shopCollect.js
3.55 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
/**
* 店铺收藏
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/10/17
*/
'use strict';
const _ = require('lodash');
const logger = global.yoho.logger;
const serviceAPI = global.yoho.ServiceAPI;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
shopList(uid, tabName, channelId) {
let params = {
method: 'app.shops.promote'
};
if (uid) {
params.uid = uid;
}
if (tabName) {
params.tab_name = tabName;
}
if (channelId) {
params.channel_id = channelId;
}
return this.get({
data: params,
param: {
code: 200
}
}).then((result) => {
if (result && result.code === 200) {
_.forEach(result.data, function(data) {
let href = '//m.yohobuy.com/product/shop?shop_id=' +
data.shopsId + '&openby:yohobuy={"action":"go.shop","params":{"shop_id":"' +
data.shopsId + '","shop_template_type":"' +
data.shopTemplateType + '","shop_name":"' + data.shopName + '"}}';
data.isFavorite = data.isFavorite === 'Y';
if (parseInt(data.collectionNum, 10) > 10000) {
data.collectionNum = (data.collectionNum / 10000).toFixed(1) + ' w';
}
data.href = href;
});
return result.data;
} else {
logger.error('shop list data return code is not 200');
return {};
}
});
}
shopNav(channelId) {
let params = {
method: 'app.shops.promoteTabNameList'
};
if (channelId) {
params.channel_id = channelId;
}
return this.get({
data: params,
param: {
cache: true,
code: 200
}
}).then((result) => {
if (result.data) {
if (result.data.length === 0 || (result.data.length === 1 && result.data[0] === 'NULL')) {
return false;
} else {
return result.data;
}
}
});
}
banner(contentCode) {
return this.get({
api: serviceAPI,
url: 'operations/api/v5/resource/get',
data: {
content_code: contentCode,
platform: 'iphone'
},
param: {
cache: true,
code: 200
}
}).then((result) => {
if (result && result.data) {
return result.data[0];
}
});
}
shopFav(uid, shopIds) {
return this.get({
data: {
method: 'app.shops.promoteFavorite',
shop_ids: shopIds,
uid: uid
},
param: {
code: 200
}
}).then((result) => {
if (result.data) {
return result.data;
}
});
}
/**
* 根据店铺ID调获取店铺数据
* 图片字段:pic_popular
order 传 pools_id_asc 或者 pools_id_desc
* @param {*} params
*/
batchGetShops(params) {
return this.get({
data: {
method: 'app.shops.batchGetShops',
shop_ids: params.shop_ids,
order: params.order
}
});
}
};