ListData.php 3.23 KB
<?php

namespace LibModels\Wap\Guang;

use Api\Sign;
use Api\Yohobuy;
use Plugin\Cache;

/**
 * 逛首页列表相关的数据模型
 * 
 * @name ListData
 * @package LibModels/Wap/Guang
 * @copyright yoho.inc
 * @version 1.0 (2015-10-10 9:54:07)
 * @author fei.hong <fei.hong@yoho.cn>
 */
class ListData
{
    const URI_CATEGORY = 'guang/api/v1/category/get';
    const URI_ARTICLELIST = 'guang/api/v2/article/getList';
    const URI_AUTHOR = 'guang/service/v1/author/';

    /**
     * 逛分类
     * 
     * 备注: id (0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士)
     * 
     * @return array
     */
    public static function category()
    {
        $param = Yohobuy::param();
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_CATEGORY, $param, 3600); // 有缓存1小时
    }

    /**
     * 逛内容列表
     * 
     * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示所有
     * @param int $sortId 分类ID
     * @param int $uid 用户ID
     * @param string $udid 客户端唯一标识
     * @param int $page 分页第几页, 默认第1页
     * @param string $tag 标签
     * @param int $authorId 作者ID
     * @return array
     */
    public static function article($gender, $sortId, $uid = 0, $udid = '', $page = 1, $tag = null, $authorId = null)
    {
        $param = Yohobuy::param();
        $param['gender'] = $gender;
        $param['page'] = $page;
        $param['uid'] = $uid;
        $param['udid'] = $udid;
        if (isset($sortId)) {
            $param['sort_id'] = $sortId;
        }
        if (isset($tag)) {
            $param['tag'] = $tag;
        }
        if (isset($authorId) && is_numeric($authorId)) {
            $param['author_id'] = $authorId;
        }
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
    }

    /**
     * 根据分类进行分组的逛内容列表
     * 
     * @param array $category 分类
     * @param string $gender "1,3"表示男, "2,3"表示女
     * @param int $uid 用户ID
     * @param string $udid 客户端唯一标识
     * @param int $page 分页第几页, 默认第1页
     * @return array
     */
    public static function articleGroup($category, $gender, $uid = 0, $udid, $page = 1)
    {
        $urlList = array();
        $param = array();

        foreach ($category as $value) {
            $param = Yohobuy::param();
            $param['gender'] = $gender;
            $param['page'] = $page;
            $param['sort_id'] = $value['id'];
            $param['uid'] = $uid;
            $param['udid'] = $udid;
            $param['client_secret'] = Sign::getSign($param);

            $urlList[$value['id']] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
        }

        return Yohobuy::getMulti($urlList);
    }

    /**
     * 获取作者信息
     * 
     * @param int $id 作者ID
     * @return array
     */
    public static function author($id)
    {
        $result = array();

        if (is_numeric($id)) {
            $result = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_AUTHOR, 'getAuthor', array($id));
        }

        return $result;
    }

}