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.

57 lines
1.5 KiB

  1. <?php
  2. namespace App\Service;
  3. use App\Model\OrderMain;
  4. use EasyWeChat\Factory;
  5. use Hyperf\DbConnection\Db;
  6. use App\Commons\Log;
  7. use App\Constants\LogLabel;
  8. use Hyperf\Di\Annotation\Inject;
  9. use Hyperf\Guzzle\CoroutineHandler;
  10. class WxRefundService implements WxRefundServiceInterface
  11. {
  12. /**
  13. * @Inject
  14. * @var Log
  15. */
  16. protected $log;
  17. /**
  18. * 微信支付退款
  19. */
  20. public function wxPayRefund($global_order_id)
  21. {
  22. $config = config('wxpay');
  23. $app = Factory::payment($config);
  24. $app['guzzle_handler'] = CoroutineHandler::class;
  25. $orderMain = $global_order_id;
  26. // 查询订单
  27. // $orderMain = OrderMain::query()
  28. // ->select('id','global_order_id','order_num','money','state')
  29. // ->where('global_order_id',$global_order_id)
  30. // ->where('pay_type',OrderMain::ORDER_PAY_WX)
  31. // ->where(Db::raw('refund_time is null'))
  32. // ->first()->toArray();
  33. if(empty($orderMain)){
  34. return false;
  35. };
  36. $options = [
  37. 'refund_desc' => '线上订单退款',
  38. // 'notify_url' => config('site_host') . '/wechat/notify/wxpayrefund'
  39. ];
  40. $result = $app->refund->byOutTradeNumber(
  41. $orderMain['global_order_id'],
  42. $orderMain['global_order_id'],
  43. $orderMain['money'] * 100,
  44. $orderMain['money'] * 100,
  45. $options
  46. );
  47. $this->log->event(LogLabel::WX_PAY_REFUND,$result);
  48. return $result;
  49. }
  50. }