<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2017/12/6
 * Time: 下午3:49
 */

namespace App\Libs;

//require_once './allinpay/libs/ArrayAndXml.php';
//require_once './allinpay/libs/cURL.php';
//require_once './allinpay/libs/PhpTools.php';

//require_once ("./lianlianpay/llpay.config.php");
//require_once ("./lianlianpay/lib/llpay_apipost_submit.class.php");
//require_once ("./lianlianpay/lib/llpay_security.function.php");

use App\Libs\allinpay\Pay;
use App\Libs\lianlianpay\llpaypayment;


class PayHelper
{

    /**
     *
     * @param $payType [通联支付："allinpay"； 连连支付："lianlianpay"；]
     * @param $transactionSerialNumber [交易流水号]
     * @param $bankCode [银行代码]
     * @param $bankName [交易银行名称]
     * @param $bankAccountNO [银行卡账号]
     * @param $bankAccountName [银行卡户主名称]
     * @param $amount [金额]
     * @param $summary [交易附言]
     * @param $remark [备注]
     * @param $channelId [渠道ID]
     * @param $is_company 0:私人； 1:公司
     * @return mixed ["code" => 0, "msg" => "验签通过"]
     */
    public static function pay($payType,
                               $transactionSerialNumber,
                               $bankCode,
                               $bankName,
                               $bankAccountNO,
                               $bankAccountName,
                               $amount,
                               $summary,
                               $remark,
                               $channelId,
                               $is_company) {

        if("ALLINPAY" == $payType) {
            return Pay::payAllinPay($transactionSerialNumber, $bankCode, $bankName, $bankAccountNO, $bankAccountName, $amount, $summary, $remark, $channelId, $is_company);
        } else if("LIANLIANPAY" == $payType) {
            return llpaypayment::payLianLianPay($transactionSerialNumber, $bankCode, $bankName, $bankAccountNO, $bankAccountName, $amount, $summary, $remark, $channelId, $is_company);
        }
        return ["code" => 0, "msg" => "支付通道错误"];
    }

    /**
     * @param $payType
     * @param $transactionSerialNumber
     * @param $reqSn
     * @return mixed ["code" => 0, "msg" => "错误"]
     */
    public static function payQuery($payType, $transactionSerialNumber, $reqSn) {
        if("ALLINPAY" == $payType) {
            return Pay::payQuery($transactionSerialNumber, $reqSn);
        } else if("LIANLIANPAY" == $payType) {
            return llpaypayment::payQuery($transactionSerialNumber, $reqSn);
        }
        return ["code" => 0, "msg" => "支付通道错误"];
    }

    /**
     * 账户信息查询
     * @param $payType
     * @param $reqSn
     * @return array   balance:单位分
     */
    public static function payAccountInfo($payType, $reqSn) {
        if("ALLINPAY" == $payType) {
            return Pay::payAccountInfo($reqSn);
        } else if("LIANLIANPAY" == $payType) {
            return llpaypayment::payAccountInfo($reqSn);
        }
        return ["code" => 0, "msg" => "支付通道错误"];
    }

    /**
     * 历史余额查询
     * @param $payType
     * @param $reqSn
     * @param $startDay 开始日期 yyyyMMdd
     * @param $endDay 结束日期 yyyyMMdd
     * @return array|void
     */
    public static function payAccountHistoryBalanceAmount($payType, $reqSn, $startDay, $endDay) {
        if("ALLINPAY" == $payType) {
            return Pay::payAccountHistoryBalanceAmount($reqSn, $startDay, $endDay);
        }
        return ["code" => 0, "msg" => "支付通道错误"];
    }
}