You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.4 KiB
55 lines
1.4 KiB
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Model\OrderMain;
|
|
use EasyWeChat\Factory;
|
|
use Hyperf\DbConnection\Db;
|
|
use App\Constants\ErrorCode;
|
|
use App\Commons\Log;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
class WxRefundService implements WxRefundServiceInterface
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var Log
|
|
*/
|
|
protected $log;
|
|
|
|
/**
|
|
* 微信支付退款
|
|
*/
|
|
public function wxPayRefund($global_order_id)
|
|
{
|
|
$config = config('wxpay');
|
|
$app = Factory::payment($config);
|
|
$app['guzzle_handler'] = CoroutineHandler::class;
|
|
|
|
// 查询订单
|
|
$orderMain = OrderMain::query()
|
|
->select('id','global_order_id','order_num','money','state')
|
|
->where('global_order_id',$global_order_id)
|
|
->where('pay_type',OrderMain::ORDER_PAY_WX)
|
|
->where(Db::raw('refund_time is null'))
|
|
->first();
|
|
if(empty($orderMain)){
|
|
return false;
|
|
};
|
|
$options = [
|
|
'refund_desc' => '',
|
|
'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund'
|
|
];
|
|
$result = $app->refund->byOutTradeNumber(
|
|
$orderMain->global_order_id,
|
|
$orderMain->global_order_id,
|
|
$orderMain->money * 100,
|
|
$orderMain->money * 100,
|
|
$options
|
|
);
|
|
|
|
$this->log->event('wx_pay_refund',$result);
|
|
return $result;
|
|
}
|
|
|
|
}
|