FavoriteData.php 2.36 KB
<?php

namespace LibModels\Web\Product;

use Api\Yohobuy;
use Api\Sign;

/**
 * FavoriteData
 * 收藏相关接口
 * @author Administrator
 */
class FavoriteData
{

    const URL_PRODUCT_FAVORITE = 'shops/service/v1/favorite/';

    /**
     * 根据uid和商品的skn查询是否被用户收藏
     * @param $uid
     * @param $productSkn
     * @return boolean 收藏 true 未收藏 false
     */
    public static function getUidProductFav($uid, $productSkn)
    {
        return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_PRODUCT_FAVORITE, 'getUidProductFav', array($uid, $productSkn));
    }

    /**
     * 根据uid和商品的skn收藏商品
     * @param $uid
     * @param $productSkn
     * @return bool
     */
    public static function addUidProductFav($uid, $productSkn, $isBrand = false)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.favorite.add';
        $param['id'] = $productSkn;
        $param['uid'] = $uid;
        $param['type'] = $isBrand ? 'brand' : 'product';
        $param['client_secret'] = Sign::getSign($param);
        
        return Yohobuy::post(Yohobuy::API_URL, $param);
    }

    /**
     * 根据uid和商品的skn取消收藏商品
     * @param $uid
     * @param $productSkn
     * @return bool
     */
    public static function delUidProductFav($uid, $productSkn, $isBrand = false)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.favorite.cancel';
        $param['fav_id'] = $productSkn;
        $param['uid'] = $uid;
        $param['type'] = $isBrand ? 'brand' : 'product';
        $param['client_secret'] = Sign::getSign($param);
        
        return Yohobuy::post(Yohobuy::API_URL, $param);
    }

    /**
     * 根据uid和商品的skn收藏或取消收藏商品
     * @param $uid
     * @param $productSkn
     * @return bool
     */
    public static function changeFavoriteProduct($uid, $productSkn)
    {
        return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_PRODUCT_FAVORITE, 'toggleProduct', array($uid, $productSkn));
    }

    /**
     * 根据uid和商品的skn添加或取消收藏品牌
     * @param $uid
     * @param $productSkn
     * @return bool
     */
    public static function changeFavoriteBrand($uid, $productSkn)
    {
        return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_PRODUCT_FAVORITE, 'toggleBrandFav', array($uid, $productSkn));
    }

}