ListData.php 3.65 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);
        //TODO
        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);
        //TODO
        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);
    }

}