ListData.php 4.98 KB
<?php

namespace LibModels\Wap\Product;

use Api\Yohobuy;
use Api\Sign;

/**
 * 商品列表相关的数据模型
 * 
 * @name ListData
 * @package LibModels/Wap/Product
 * @copyright yoho.inc
 * @version 1.0 (2015-10-15 20:15:02)
 * @author fei.hong <fei.hong@yoho.cn>
 */
class ListData
{

    const URI_PRODUCT = 'shops/service/v1/product';

    /**
     * 根据商品SKN获取商品的简要信息
     * 
     * @param array $skns
     * @return array
     */
    public static function productInfoBySkns($skns)
    {
//        // 调用搜索接口
//        $param = Yohobuy::param();
//        $param['method'] = 'app.search.li';
//        $param['query'] = implode(' ', $skns);
//        $param['limit'] = count($skns);
//        $param['order'] = 's_t_desc';
//        $param['client_secret'] = Sign::getSign($param);
//
//        return Yohobuy::get(API_URL, $param, 3600); // 有缓存1小时

        $condition = array();
        $condition['query'] = implode(' ', $skns);
        $condition['limit'] = count($skns);
        $condition['order'] = 's_t_desc';

        return SearchData::searchElasticByCondition($condition, 3600); // 有缓存1小时
    }

    /**
     * 根据商品SKC获取商品的简要信息
     * 
     * @param array $skcs
     * @return array
     */
    public static function productInfoBySkcs($skcs)
    {
        return Yohobuy::yarClient(SERVICE_URL . self::URI_PRODUCT, 'getLessInfoByProductSkcs', array(array('productSkcs' => $skcs)));
    }

    /**
     * 获取店铺装修的所有资源接口
     * @param int $shopId 店铺id
     * @param int $cache 接口缓存
     * @author sefon 2016-4-26 21:17:15
     * @return array
     */
    public static function getShopDecorator($shopId, $cache = 600)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.shopsdecorator.getList';
        $param['shop_id'] = $shopId;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 获取店铺信息
     * @param int $shopId 店铺id
     * @param int $uid 用户id 判断用户是否收藏店铺
     * @param int $cache 接口缓存
     * @author sefon 2016-4-26 21:32:57
     * @return array
     */
    public static function getShopInfo($shopId, $uid = 0, $cache = 600)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.shops.getIntro';
        $param['shop_id'] = $shopId;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 获取店铺下面的所有品牌
     * @param int $shopId 店铺id
     * @param int $cache 接口缓存
     * @author sefon 2016-4-26 21:48:30
     * @return array
     */
    public static function getShopBrands($shopId, $cache = 600)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.shops.getShopsBrands';
        $param['shop_id'] = $shopId;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(API_URL, $param);
//        return Yohobuy::get('http://devapi.yoho.cn:58078/', $param, $cache);
    }

    /**
     * 获取店铺下面的所有分类
     * @param int $shopId 店铺id
     * @param int $cache 接口缓存
     * @author sefon 2016-4-27 21:39:51
     * @return array
     */
    public static function getShopCategory($shopId, $channel, $cache = 600)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.shop.getSortInfo';
        $param['yh_channel'] = $channel;
        $param['shop_id'] = $shopId;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    public static function getShopDecoratorAndInfo($shopId, $uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.shopsdecorator.getList';
        $param['shop_id'] = $shopId;
        $param['client_secret'] = Sign::getSign($param);
        $urlList['decorator'] = Yohobuy::httpBuildQuery(API_URL, $param);

        $param2 = Yohobuy::param();
        $param2['method'] = 'app.shops.getIntro';
        $param2['shop_id'] = $shopId;
        $param2['uid'] = $uid;
        $param2['client_secret'] = Sign::getSign($param2);
        $urlList['shopInfo'] = Yohobuy::httpBuildQuery(API_URL, $param2);

        return Yohobuy::getMulti($urlList);

    }

    /**
     * 获取单品店店铺券
     http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/%E5%95%86%E5%93%81%E5%88%97%E8%A1%A8/brandShops.md#%E8%8E%B7%E5%8F%96%E5%8D%95%E5%93%81%E5%BA%97%E5%BA%97%E9%93%BA%E5%88%B8
     * @param int $shopId 店铺id
     * @param int $uid 用户uid
     * @return array
     */
    public static function shopCouponsList($shopId, $uid = '')
    {
        $param = Yohobuy::param();
        $param['method'] = 'shop.coupons.list';
        $param['shop_id'] = intval($shopId);

        if (!empty($uid)) {
            $param['uid'] = intval($uid);
        }

        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

}