Payment.php 2.3 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * Trait类 微信公众号
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Factories\Wechat
 * @package   App\Factories\Wechat
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年5月6日10:44:56
 * @copyright 2019-2020 Richer (http://www.umu888.com)
 * @license   http://www.xxxxxx.com License
 * @link      http://www.xxxxxx.com
 */
namespace App\Factories\Wechat;

/**
 * Trait Payment
 *
 * @category  App\Factories\Wechat
 * @package   App\Factories\Wechat
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年5月6日10:44:56
 * @copyright 2019-2020 Richer (http://www.umu888.com)
 * @license   http://www.xxxxxx.com License
 * @link      http://www.xxxxxx.com
 */
trait Payment
{
    /**
     * 企业付款
     *
     * @param $out_trade_no
     * @param $openId
     * @param $amount
     * @return bool
     */
    public function enterprisePay($out_trade_no, $openId, $amount)
    {
        $result = $this->payment->transfer->toBalance([
            'partner_trade_no' => $out_trade_no,
            'openid' => $openId,
            'check_name' => 'NO_CHECK', //不校验真实姓名
            'amount' => $amount * 100,
            'desc' => '提现转账',
        ]);

        if ($result) {
            if ($result['return_code'] == 'FAIL') {
                $this->errMsg = $result['return_msg'];
                \Log::info('用户申请提现转账失败!,申请编号:' . $out_trade_no . ',失败原因:' . $result['return_msg']);

                return false;
            } else {
                if ($result['result_code'] == 'FAIL') {
                    $this->errMsg = $result['err_code_des'];
                    \Log::info('用户申请提现转账失败!,申请编号:' . $out_trade_no . ',失败原因:' . $result['err_code_des']);

                    return false;
                }
            }
        } else {
            $this->errMsg = '系统错误!';
            \Log::info('用户申请提现转账失败!,申请编号:' . $out_trade_no);

            return false;
        }

        return true;
    }
}