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.

46 lines
1.2 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 PayRefundService implements PayRefundServiceInterface
  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. $result = [
  18. 'status' => 0,
  19. 'msg' => '退款成功'
  20. ];
  21. // 查询订单
  22. $orderMain = OrderMain::query()
  23. ->select('id','code','order_num','money','state')
  24. ->where('global_order_id',$global_order_id)
  25. ->where('pay_type',OrderMain::ORDER_PAY_WX)
  26. ->where(Db::raw('refund_time is null'))
  27. ->first();
  28. if(empty($orderMain)){
  29. return ['status'=>1, 'msg'=>'订单不存在或已退款'];
  30. }
  31. $optional = [];
  32. $result = $app->refund->byOutTradeNumber(
  33. $orderMain->code,
  34. $orderMain->code,
  35. $orderMain->money * 100,
  36. $orderMain->money * 100,
  37. $optional
  38. );
  39. return $result;
  40. }
  41. }