IndexData.php 5.01 KB
<?php

namespace LibModels\Web\Home;

use Api\Yohobuy;
use Api\Sign;

class IndexData
{

    //分类服务
    const URL_OPERATIONS_CATEGORY = 'operations/service/v1/category';
    //资源位地址
    const URL_OPERATIONS_RESOURCE_GET = 'operations/api/v5/resource/get';
    
    const URI_LEFTNAV_CATEGORY = 'operations/api/v6/category/getCategory';

    /**
     * 获取导航数据
     * 
     * @param int $status  (default)
     * @param string $fields (default)
     * @return array
     */
    public static function getNavData()
    {
        $params = Yohobuy::param();
        $params['client_type'] = 'web'; // 调用web手机网站的
        $params['private_key'] = '0ed29744ed318fd28d2c07985d3ba633'; // 调用Android的private_key不然会有参数验证错误的bug
        $params['client_secret'] = Sign::getSign($params);
        return Yohobuy::get(SERVICE_URL . self::URI_LEFTNAV_CATEGORY, $params);
    }

    /**
     * 获取热搜词数据
     * 
     * @param int $status  (default)
     * @param string $fields (default)
     * @return array
     */
    public static function getHotSearchData()
    {
        $params = Yohobuy::param();
        $params['client_type'] = 'web'; // 调用web手机网站的
        $params['method'] = 'app.search.getTerms';
        $params['private_key'] = Yohobuy::$privateKeyList['web'];
        $params['client_secret'] = Sign::getSign($params);
        return Yohobuy::get(API_URL, $params, true);
    }

    /**
     * 获取资源数据
     * 
     * @param string $content_code
     * @param string $client_type
     * @param boolean $isOnlyUrl false
     * @return array
     */
    public static function getResourceData($content_code, $client_type = 'web', $isOnlyUrl = false)
    {
        // 构建必传参数
        $params = Yohobuy::param();
        $params['content_code'] = $content_code;
        $params['client_type'] = $client_type;
        $params['private_key'] = Yohobuy::$privateKeyList[$client_type];
        $params['client_secret'] = Sign::getSign($params);
        if($isOnlyUrl) {
            return Yohobuy::httpBuildQuery(SERVICE_URL . self::URL_OPERATIONS_RESOURCE_GET, $params);
        }
        return Yohobuy::get(SERVICE_URL . self::URL_OPERATIONS_RESOURCE_GET, $params, false, false, 2);
    }

    /**
     * 邮箱订阅
     * 
     * @param string $email
     * @param int $uid
     * @author sefon 2016-4-22 18:33:51
     * @return array
     */
    public static function emailSubscriber($email, $uid = 0)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'open.subscriber.subscriber';
        $param['email'] = $email;
        $param['uid'] = $uid;
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 意见反馈
     * 
     * @param int $feedback_id
     * @param int $question_id
     * @param string $answer
     * @param int $solution
     * @author sefon 2016-4-22 18:34:02
     * @return array
     */
    public static function suggestFeedback($feedback_id, $question_id, $answer, $solution)
    {
        $param = Yohobuy::param();
        $param['method'] = 'open.feedback.submit';
        $param['feedback_id'] = $feedback_id;
        $param['question_id'] = $question_id;
        $param['answer'] = $answer;
        $param['solution'] = $solution;
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 消息提示——未读消息
     *
     * @param int $uid 用户ID
     * @return array 接口返回的数据
     */
    public static function infoNum($uid, $udid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.home.getInfoNum';
        $param['uid'] = $uid;
        $param['udid'] = $udid;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 消息提示——未确认订单数量
     * @param type $uid
     * @return type
     */
    public static function getPendingOrderCount($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'web.SpaceOrders.getPendingOrderCount';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 消息提示——未评论数量
     * @param type $uid
     * @return type
     */
    public static function notCommentRecordCount($uid)
    {
        $param = Yohobuy::param();
        $param['method'] = 'show.notCommentRecordCount';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

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

}