...
|
...
|
@@ -6,9 +6,16 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const favAPI = require('./favorite-api');
|
|
|
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
|
...
|
...
|
@@ -16,15 +23,15 @@ const favAPI = require('./favorite-api'); |
|
|
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
|
|
|
* @return { Object } 收藏结果
|
|
|
*/
|
|
|
const toggleFavProduct = (productId, uid, isadd) => {
|
|
|
toggleFavProduct(productId, uid, isadd) {
|
|
|
if (isadd) {
|
|
|
return favAPI.addFavAsync(uid, productId, 'product');
|
|
|
return this.favAPI.addFavAsync(uid, productId, 'product');
|
|
|
} else {
|
|
|
return favAPI.cancelFavAsync(uid, productId, 'product');
|
|
|
return this.favAPI.cancelFavAsync(uid, productId, 'product');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 收藏品牌
|
|
|
* @function toggleFavBrand
|
|
|
* @param { number } brandId 品牌id
|
...
|
...
|
@@ -32,15 +39,15 @@ const toggleFavProduct = (productId, uid, isadd) => { |
|
|
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
|
|
|
* @return { Object } 收藏结果
|
|
|
*/
|
|
|
const toggleFavBrand = (brandId, uid, isadd) => {
|
|
|
toggleFavBrand(brandId, uid, isadd) {
|
|
|
if (isadd) {
|
|
|
return favAPI.addFavAsync(uid, brandId, 'brand');
|
|
|
return this.favAPI.addFavAsync(uid, brandId, 'brand');
|
|
|
} else {
|
|
|
return favAPI.cancelFavAsync(uid, brandId, 'brand');
|
|
|
return this.favAPI.cancelFavAsync(uid, brandId, 'brand');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 收藏店铺
|
|
|
* @function toggleFavShop
|
|
|
* @param { number } shopId 店铺id
|
...
|
...
|
@@ -48,21 +55,16 @@ const toggleFavBrand = (brandId, uid, isadd) => { |
|
|
* @param { string } isadd 是否收藏 true--添加收藏 false--取消收藏
|
|
|
* @return { Object } 收藏结果
|
|
|
*/
|
|
|
const toggleFavShop = (shopId, uid, isadd) => {
|
|
|
toggleFavShop(shopId, uid, isadd) {
|
|
|
if (isadd) {
|
|
|
return favAPI.addFavAsync(uid, shopId, 'shop');
|
|
|
return this.favAPI.addFavAsync(uid, shopId, 'shop');
|
|
|
} else {
|
|
|
return favAPI.cancelFavAsync(uid, shopId, 'shop');
|
|
|
return this.favAPI.cancelFavAsync(uid, shopId, 'shop');
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
const getFavStatus = (uid, id, type) => {
|
|
|
return favAPI.isFavAsync(uid, id, type);
|
|
|
};
|
|
|
getFavStatus(uid, id, type) {
|
|
|
return this.favAPI.isFavAsync(uid, id, type);
|
|
|
}
|
|
|
|
|
|
module.exports = {
|
|
|
getFavStatus, // 收藏状态
|
|
|
toggleFavProduct, // 收藏商品
|
|
|
toggleFavBrand, // 收藏品牌
|
|
|
toggleFavShop // 收藏店铺
|
|
|
}; |
...
|
...
|
|