favorite.js
1.87 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
/**
* 收藏相关接口
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/7/17
*/
'use strict';
const FavAPI = require('./favorite-api');
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.favAPI = new FavAPI(ctx);
}
/**
* 收藏商品
* @function toggleFavProduct
* @param { number } productId 商品id
* @param { number } uid 用户uid
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
toggleFavProduct(productId, uid, isadd) {
if (isadd) {
return this.favAPI.addFavAsync(uid, productId, 'product');
} else {
return this.favAPI.cancelFavAsync(uid, productId, 'product');
}
}
/**
* 收藏品牌
* @function toggleFavBrand
* @param { number } brandId 品牌id
* @param { number } uid 用户uid
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
toggleFavBrand(brandId, uid, isadd) {
if (isadd) {
return this.favAPI.addFavAsync(uid, brandId, 'brand');
} else {
return this.favAPI.cancelFavAsync(uid, brandId, 'brand');
}
}
/**
* 收藏店铺
* @function toggleFavShop
* @param { number } shopId 店铺id
* @param { number } uid 用户uid
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
* @return { Object } 收藏结果
*/
toggleFavShop(shopId, uid, isadd) {
if (isadd) {
return this.favAPI.addFavAsync(uid, shopId, 'shop');
} else {
return this.favAPI.cancelFavAsync(uid, shopId, 'shop');
}
}
getFavStatus(uid, id, type) {
return this.favAPI.isFavAsync(uid, id, type);
}
};