favorite.js 1.87 KB
/**
 * 收藏相关接口
 * @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);
    }

};