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