favorite.js
3.42 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
'use strict';
const api = global.yoho.API;
const helpers = global.yoho.helpers;
/**
* 处理用户收藏的商品数据
*
* @param int uid 用户ID
* @param int page 第几页
* @param int limit 限制读取的数目,默认10
* @return array 处理之后的收藏的商品数据
*/
exports.getFavProductData = (uid, page, limit) => {
return api.get('', {
method: 'app.favorite.product',
uid: uid,
page: page,
limit: limit
}, {
code: 200
}).then(result => {
var isend = true,
list = [],
data = result.data;
if (data && page <= data.page_total) {
data.product_list.forEach(function(d) {
if (!d.product_skn) {
return;
}
let link = '';
let discountPrice = false;
if (d.goodsId && d.cnAlphabet) {
link = helpers.urlFormat(`/product/pro_${d.product_id}_${d.goodsId}/${d.cnAlphabet}.html`);
}
if (Number(d.market_price) - Number(d.sales_price) > 0) {
discountPrice = '¥' + Number(Math.max(d.sales_price, 0)).toFixed(2);
}
list.push({
fav_id: d.product_id,
link: link,
imgUrl: d.image ? helpers.image(d.image) : '',
title: d.product_name,
price: '¥' + Number(Math.max(d.market_price, 0)).toFixed(2),
discountPrice: discountPrice,
sellOut: d.storage <= 0,
invalidGoods: d.status === 0
});
});
if (page < data.page_total) {
isend = false;
}
}
return {
isend: isend,
list: list
};
});
};
/**
* 处理用户收藏的品牌数据
*
* @param int uid 用户ID
* @param string gender 性别 1,3表示男,2,3表示女,1,2,3表示全部
* @param int page 第几页
* @param int limit 限制读取的数目
* @return array 处理之后的收藏的品牌数据
*/
exports.getFavBrandData = (uid, gender, page, limit) => {
return api.get('', {
method: 'app.favorite.brand',
uid: uid,
gender: gender,
page: page,
limit: limit
}, {
code: 200
}).then(result => {
var isend = true,
list = [],
data = result.data;
if (data && page <= data.page_total) {
data.brand_list.forEach(function(d) {
list.push({
fav_id: d.brand_id,
link: '', // todo
imgUrl: d.brand_ico ? helpers.image(d.brand_ico, 160, 125) : '',
brandName: d.brand_name,
down: d.status === 0
});
});
if (page < data.page_total) {
isend = false;
}
}
return {
isend: isend,
list: list
};
});
};
/**
* 取消收藏的商品/品牌数据
*
* @param int uid 用户ID
* @param int favId 要取消的收藏id
* @param string type 取消类型(brand:品牌,product:商品)
* @return array 接口返回的数据
*/
exports.favoriteDelete = (uid, favId, type) => {
return api.get('', {
method: 'app.favorite.cancel',
uid: uid,
type: type,
fav_id: favId
});
};