PayData.php 8.65 KB
<?php

namespace LibModels\Web\Product;

use Api\Sign;
use Api\Yohobuy;

/**
 * 支付操作类
 *
 * @package LibModels\Web\Product
 * @author Gtskk
 * @copyright 2016/3/24 14:23 Gtskk<iamgtskk@gmail.com>
 * @version: 0.0.1
 */
class PayData
{
    /**
     * 获取指定用户的订单数目
     *
     * @param int $uid 用户ID
     * @return mixed
     */
    public static function getOrderCountByUid($uid)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['uid'] = intval($uid);
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.getOrderCountByUid';

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

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

    /**
     * 获取支付方式列表
     *
     * @return mixed
     */
    public static function getPaymentList()
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.getPaymentList';

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

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

    /**
     * 根据支付方式id获取单个支付方式有关信息
     *
     * @param int $id 支付方式id
     * @return mixed
     */
    public static function getPaymentById($id)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.getPaymentById';
        $param['id'] = $id;

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

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

    /**
     * ERP提交订单状态
     *
     * @param string $orderCode 订单号
     * @param int $payment 支付方式id
     * @param string $bankName 银行名称
     * @param string $bankCode 银行代码
     * @param string $amount 金额
     * @param string $payOrderCode 支付订单代码
     * @param string $tradeNo 交易码
     * @param string $bankBillNo 银行订单码
     * @return mixed
     */
    public static function submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.submitOrderStatus';
        $param['order_code'] = $orderCode;
        $param['payment'] = $payment;
        $param['bank_name'] = $bankName;
        $param['bank_code'] = $bankCode;
        $param['amount'] = $amount;
        $param['payOrderCode'] = $payOrderCode;
        $param['trade_no'] = $tradeNo;
        $param['bank_bill_no'] = $bankBillNo;

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

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


    /**
     * 更新订单的状态
     *
     * @param int $id 订单ID
     * @param int $uid 用户ID
     * @param int $payment 支付方式ID
     * @param string $paymentStatus 支付状态(Y或者N)
     * @param string $bankCode 银行代码
     * @return mixed
     */
    public static function updateOrderStatus($id, $uid, $payment, $paymentStatus, $bankCode)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.updatePaymentStatus';
        $param['id'] = $id;
        $param['uid'] = $uid;
        $param['payment'] = $payment;
        $param['payment_status'] = $paymentStatus;
        $param['bank_code'] = $bankCode;

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

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

    /**
     * 获取订单的支付银行
     *
     * @param string $orderCode 订单号
     * @return mixed
     */
    public static function getBankByOrder($orderCode)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.getOrderPayBank';
        $param['orderCode'] = $orderCode;

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

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

    /**
     * 添加订单支付银行记录
     *
     * @param string $orderCode 订单号
     * @param int $payment 支付方式ID
     * @param string $bankCode 银行码
     * @return mixed
     */
    public static function setOrderPayBank($orderCode, $payment, $bankCode)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.addOrderPayBank';
        $param['orderCode'] = $orderCode;
        $param['payment'] = $payment;
        $param['bankCode'] = $bankCode;

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

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

    /**
     * 更改订单支付银行记录
     *
     * @param string $orderCode 订单号
     * @param int $payment 支付方式ID
     * @param string $bankCode 银行码
     * @return mixed
     */
    public static function updateOrderPayBank($orderCode, $payment, $bankCode)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.modifyOrderPayBank';
        $param['orderCode'] = $orderCode;
        $param['payment'] = $payment;
        $param['bankCode'] = $bankCode;

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

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


    /**
     * 发送短信息(默认不传递area参数,传递了就是给特定国家码的手机号发送短信)
     *
     * @param string $mobile 手机号
     * @param string $template 模板类型
     * @param string $codes 对应模板中的参数
     * @return mixed
     */
    public static function sendMessage($mobile, $template, $codes)
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'app.message.sendMsg';
        $param['mobile'] = $mobile;
        $param['template'] = $template;
        $param['codes'] = $codes;

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

        return Yohobuy::get(API_URL, $param);
    }
    
    /**
     * 支付成功后--更新订单状态
     * @param type string $orderCode 订单号
     * @param type int $payment 支付方式
     * @param type double $amount 金额(单位:元)
     * @param type string $bankName 银行名称
     * @param type string $bankCode 银行代码
     * @param type string $tradeNo 交易流水号
     * @param type string $bankBillNo 银行流水号
     * @return type []
     */
    public static function pcpayNotify($orderCode, $payment, $amount, $bankName = '', $bankCode = '', $tradeNo = '', $bankBillNo = '')
    {
        $param = Yohobuy::param();
        $param['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $param['method'] = 'web.SpaceOrders.pcpayNotify';
        $param['order_code'] = $orderCode;
        $param['payment'] = $payment;
        $param['bank_name'] = $bankName;
        $param['bank_code'] = $bankCode;
        $param['amount'] = $amount;
        $param['trade_no'] = $tradeNo;
        $param['bank_bill_no'] = $bankBillNo;
        $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['client_type'] = 'web';
        $param['private_key'] = Yohobuy::$privateKeyList['web'];
        $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::post(API_URL, $param);
        
    }
}