OrderData.php 8.18 KB
<?php

namespace LibModels\Web\Home;

use Api\Yohobuy;
use Api\Sign;

class OrderData
{

    /**
     * 我的订单-分页
     * @param type $uid
     * @param type $page
     * @param type $limit
     * @param type $type 获取订单类型 type=1全部,type=2待付款,type=3待发货,type=4待收货,type=5待评论(已成功) 7取消
     * @return type
     */
    public static function getUserOrders($uid, $page = 1, $limit = 10, $type = 1)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.get';
        $param['uid'] = $uid;
        $param['type'] = $type;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 订单详情
     * @param type $uid
     * @param type $orderCode
     * @return type
     */
    public static function getOrderDetail($uid, $orderCode)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.detail';

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

        $param['order_code'] = $orderCode;
        $param['client_secret'] = Sign::getSign($param);
        $data = Yohobuy::get(API_URL, $param);

        //展览票不显示区域,上面要求的。@高扬、@徐洪云,2016/7/6
        if (isset($data['data']) && !empty($data['data']['order_goods'])) {
            foreach ($data['data']['order_goods'] as $key => $val) {
                if ($val['product_skn'] * 1 === EXHIBITION_TICKET) {
                    $val['size_name'] = '';
                }
                $data['data']['order_goods'][$key] = $val;
            }
        }

        return $data;
    }

    /**
     * 取消订单
     * @param type $uid
     * @param type $orderCode
     * @return type
     */
    public static function cancelUserOrder($uid, $orderCode, $reason = false, $reasonId = false)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.close';
        $param['uid'] = $uid;
        $param['order_code'] = $orderCode;
        //取消订单原因
        if ($reasonId) {
            $param['reasonId'] = $reasonId;
            $param['reasons'] = $reason;
        }
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 确认订单
     * @param type $uid
     * @param type $orderCode
     * @return type
     */
    public static function confirmUserOrder($uid, $orderCode)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.confirm';
        $param['uid'] = $uid;
        $param['order_code'] = $orderCode;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 获取虚拟订单ticketCode
     * @param type $orderCode
     * @return type
     */
    public static function getTicketCode($orderCode, $uid)
    {
        if (empty($orderCode)) {
            return array('code' => 500, 'message' => '订单号不能为空!');
        }

        if (empty($uid)) {
            return array('code' => 500, 'message' => 'uid不能为空!');
        }

        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.getQrByOrderCode';
        $param['order_code'] = $orderCode;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $param);
    }

    /**
     * 我的订单-查看物流
     * 
     * @param int $orderCode 订单号
     * @param int $uid 用户ID
     * @return array
     */
    public static function getLogisticsData($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);
    }

    /**
     * 获取历史订单
     * @param type $uid
     * @param type $page
     * @param type $limit
     */
    public static function getHistoryOrders($uid, $page = 1, $limit = 10)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.SpaceOrders.history';
        $param['uid'] = $uid;
        $param['page'] = $page;
        $param['limit'] = $limit;
        $param['client_secret'] = Sign::getSign($param);
        return Yohobuy::get(API_URL, $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);
    }

    /**
     * 取消订单原因列表
     * @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, 3600);
    }

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

        // 调用接口获得数据
        return Yohobuy::post(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.info';
        $param['order_code'] = $orderCode;
        $param['uid'] = $uid;
        $param['session_key'] = $sessionKey;
        $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 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);
    }

}