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.

40 lines
1.1 KiB

  1. <?php
  2. namespace App\Service;
  3. use App\Model\OrderMain;
  4. use EasyWeChat\Factory;
  5. use Hyperf\DbConnection\Db;
  6. use App\Constants\ErrorCode;
  7. class WxRefundService implements WxRefundServiceInterface
  8. {
  9. /**
  10. * 微信支付退款
  11. */
  12. public function wxPayRefund($global_order_id)
  13. {
  14. $config = config('wxpay');
  15. $app = Factory::payment($config);
  16. $app['guzzle_handler'] = CoroutineHandler::class;
  17. // 查询订单
  18. $orderMain = OrderMain::query()
  19. ->select('id','global_order_id','order_num','money','state')
  20. ->where('global_order_id',$global_order_id)
  21. ->where('pay_type',OrderMain::ORDER_PAY_WX)
  22. ->where(Db::raw('refund_time is null'))
  23. ->first();
  24. if(empty($orderMain)){
  25. return false;
  26. };
  27. $result = $app->refund->byOutTradeNumber(
  28. $orderMain->global_order_id,
  29. $orderMain->global_order_id,
  30. $orderMain->money * 100,
  31. $orderMain->money * 100
  32. );
  33. return $result;
  34. }
  35. }