OrderData.php 6.81 KB
<?php

namespace LibModels\Wap\Home;

use Api\Yohobuy;
use Api\Sign;

/**
 * 订单相关的数据模型
 * 
 */
class OrderData
{
    /*
     * 获取订单数据
     */

    public static function getOrderData($type, $page, $limit, $gender, $channel, $uid)
    {
        //构建必传参数
        $param = Yohobuy::param();
        $param['gender'] = $gender;
        $param['limit'] = $limit;
        $param['method'] = 'app.SpaceOrders.get';
        $param['page'] = $page;
        $param['type'] = $type;
        $param['uid'] = $uid;
        $param['yh_channel'] = $channel;
        $param['client_secret'] = Sign::getSign($param);
        //调用接口获得数据
        return Yohobuy::get(API_URL, $param);
    }

    /*
     * 取消订单
     */

    public static function cancelOrderData($orderCode, $uid, $gender, $channel, $reason = false, $reasonId = false)
    {
        //构建必传参数
        $param = Yohobuy::param();
        $param['order_code'] = $orderCode;
        $param['uid'] = $uid;
        $param['gender'] = $gender;
        $param['yh_channel'] = $channel;
        if ($reasonId) {
            $param['reasonId'] = $reasonId;
            $param['reasons'] = $reason;
        }
        $param['method'] = 'app.SpaceOrders.close';
        $param['client_secret'] = Sign::getSign($param);
        //调用接口获得数据
        return Yohobuy::get(API_URL, $param);
    }

    /*
     * 删除订单
     */

    public static function deleteOrderData($orderCode, $uid, $gender, $channel)
    {
        //构建必传参数
        $param = Yohobuy::param();
        $param['order_code'] = $orderCode;
        $param['uid'] = $uid;
        $param['gender'] = $gender;
        $param['yh_channel'] = $channel;
        $param['method'] = 'app.SpaceOrders.delOrderByCode';
        $param['client_secret'] = Sign::getSign($param);
        //调用接口删除订单
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 查看订单详情
     * 
     * @param string $orderCode 订单号
     * @param int $uid 用户ID
     * @param string $sessionKey 用户会话
     * @return array
     */
    public static function viewOrderData($orderCode, $uid, $sessionKey)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.detail';
        $param['order_code'] = $orderCode;

        //异步回调无uid
        if (!empty($uid)) {
            $param['uid'] = $uid;
        }

        $param['session_key'] = $sessionKey;
        $param['client_secret'] = Sign::getSign($param);

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

    /*
     * 我的订单-查看物流
     * 
     * @param int $orderCode 订单号
     * @param int $uid 用户ID
     * @return array
     */

    public static function LogisticsData($orderCode, $uid)
    {
        //构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'app.express.li';
        $param['order_code'] = $orderCode;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);
        //调用接口获得数据
        return Yohobuy::get(API_URL, $param);
    }

    /*
     * 支付页面的资源位
     */

    public static function paymentData($gender, $yh_channel, $code)
    {
        //构建必传参数
        $param = Yohobuy::param();
        $param['content_code'] = $code;
        $param['gender'] = $gender;
        $param['yh_channel'] = $yh_channel;
        $param['client_secret'] = Sign::getSign($param);
        //调用接口获得数据
        return Yohobuy::get(SERVICE_URL . '/operations/api/v5/resource/get', $param);
    }

    /*
     * 随便逛逛url
     * 
     * 备注:暂不使用
     */

    public static function strollData($gender, $yh_channel, $code)
    {
        //构建必传参数
        $param = Yohobuy::param();
        $param['content_code'] = $code;
        $param['gender'] = $gender;
        $param['yh_channel'] = $yh_channel;
        $param['client_secret'] = Sign::getSign($param);
        //调用接口获得数据
        return Yohobuy::get(SERVICE_URL . '/operations/api/v5/resource/get', $param);
    }

    /**
     * 更新订单的支付方式
     * 
     * @param int $orderCode 订单号
     * @param int $payment 支付方式
     * @param int $uid 用户ID
     * @return array
     */
    public static function updateOrderPayment($orderCode, $payment, $uid)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.updateOrdersPaymentByCode';
        $param['order_code'] = (int) $orderCode;
        $param['payment'] = $payment;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        // 调用接口获得数据
        return Yohobuy::post(API_URL, $param);
    }

    /**
     * 订单详情页——地址修改
     * @param $order_code
     * @param $address_id
     * @param $uid
     * @return mixed
     */
    public static function updateDeliveryAddress($order_code, $address_id, $uid)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.updateDeliveryAddress';
        $param['order_code'] = $order_code;
        $param['address_id'] = $address_id;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        // 调用接口获得数据
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 取消订单原因列表
     * @return type
     */
    public static function closeReasons()
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.closeReasons';
        $param['client_secret'] = Sign::getSign($param);

        // 调用接口获得数据
        return Yohobuy::get(API_URL, $param);
    }

    /** 再次购买
     * @param type $uid
     * @param type $orderCode
     * @return type
     */
    public static function reAddData($uid, $orderCode)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.readd';
        $param['uid'] = $uid;
        $param['order_code'] = $orderCode;
        $param['client_secret'] = Sign::getSign($param);

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

    /**
     * 支付成功后--支付确认接口
     * @param type int $orderCode 订单号
     * @param type int $paymentId 支付方式
     * @param type int $uid 用户ID
     * @return type []
     */
    public static function payConfirm($orderCode, $paymentId, $uid)
    {
        // 构建必传参数
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.payConfirm';
        $param['order_code'] = $orderCode;
        $param['payment_id'] = $paymentId;
        $param['uid'] = intval($uid);
        $param['client_secret'] = Sign::getSign($param);

        // 调用接口获得数据
        return Yohobuy::get(API_URL, $param);
    }
}