default.blade.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. @extends('user.layouts')
  2. @section('content')
  3. <div class="page-content container">
  4. <div class="panel panel-bordered">
  5. <div class="panel-heading">
  6. <h1 class="panel-title cyan-600">
  7. <i class="icon wb-payment" aria-hidden="true"></i>{{ sysConfig('website_name') . ' - ' . trans('user.shop.pay_online') }}
  8. </h1>
  9. </div>
  10. <div class="panel-body border-primary ml-auto mr-auto w-p75">
  11. <div class="alert alert-info text-center">
  12. {!! trans('user.payment.qrcode_tips', ['software' => $pay_type]) !!}
  13. </div>
  14. <div class="row">
  15. <div class="col-md-6">
  16. <ul class="list-group list-group-dividered">
  17. <li class="list-group-item">{{ trans('user.shop.service') . ': ' . $name }}</li>
  18. <li class="list-group-item">{{ trans('user.shop.price') . ': ' . $payment->amount_tag }}</li>
  19. @if ($days !== 0)
  20. <li class="list-group-item">{{ trans('common.available_date') . ': ' . $days . trans_choice('common.days.attribute', 1) }}</li>
  21. @endif
  22. <li class="list-group-item"> {!! trans('user.payment.close_tips', ['minutes' => (time() - strtotime(sysConfig('tasks_close.orders'))) / 60]) !!}</li>
  23. </ul>
  24. </div>
  25. <div class="col-auto mx-auto">
  26. @if ($payment->qr_code && $payment->url)
  27. <div class=" w-p100 h-p100" id="qrcode"></div>
  28. @else
  29. <img class="h-250 w-250" src="{{ $payment->qr_code }}" alt="{{ trans('common.qrcode', ['attribute' => trans('user.pay')]) }}">
  30. @endif
  31. </div>
  32. </div>
  33. <div class="alert alert-danger text-center mt-10">
  34. {!! trans('user.payment.mobile_tips') !!}
  35. </div>
  36. </div>
  37. </div>
  38. </div>
  39. @endsection
  40. @section('javascript')
  41. @vite(['resources/js/app.js'])
  42. @if ($payment->qr_code && $payment->url)
  43. <script src="/assets/custom/easy.qrcode.min.js"></script>
  44. <script>
  45. // Create QRCode Object
  46. new QRCode(document.getElementById("qrcode"), {
  47. text: @json($payment->url),
  48. backgroundImage: '{{ asset($pay_type_icon) }}',
  49. autoColor: true
  50. });
  51. </script>
  52. @endif
  53. <script>
  54. window.i18n.extend({
  55. 'broadcast': {
  56. 'error': '{{ trans('common.error') }}',
  57. 'websocket_unavailable': '{{ trans('common.broadcast.websocket_unavailable') }}',
  58. 'websocket_disconnected': '{{ trans('common.broadcast.websocket_disconnected') }}',
  59. 'setup_failed': '{{ trans('common.broadcast.setup_failed') }}',
  60. 'disconnect_failed': '{{ trans('common.broadcast.disconnect_failed') }}'
  61. }
  62. });
  63. @if (config('broadcasting.default') !== 'null')
  64. let pollingStarted = false
  65. function onFinal(status, message) {
  66. window.broadcastingManager.stopPolling('payment-status'); // 停止轮询
  67. window.broadcastingManager.disconnect(); // 断开连接
  68. showMessage({
  69. title: message,
  70. icon: status === 'success' ? 'success' : 'error',
  71. showConfirmButton: false,
  72. callback: () => window.location.href = '{{ route('invoice.index') }}'
  73. })
  74. }
  75. function startPolling() {
  76. if (pollingStarted) return
  77. pollingStarted = true
  78. window.broadcastingManager.disconnect(); // 断开连接
  79. // 使用统一的广播管理器启动轮询
  80. window.broadcastingManager.startPolling('payment-status', () => {
  81. ajaxGet('{{ route('orderStatus') }}', {
  82. trade_no: '{{ $payment->trade_no }}'
  83. }, {
  84. success: ret => {
  85. if (['success', 'error'].includes(ret.status)) {
  86. onFinal(ret.status, ret.message)
  87. }
  88. },
  89. error: () => onFinal('error', "{{ trans('common.request_failed') }}")
  90. })
  91. }, 3000)
  92. }
  93. function setupPaymentListener() {
  94. // 使用统一的广播管理器检查 Echo 是否可用
  95. if (!window.broadcastingManager.isEchoAvailable()) {
  96. startPolling()
  97. return
  98. }
  99. try {
  100. // 使用统一的广播管理器订阅频道
  101. const success = window.broadcastingManager.subscribe(
  102. 'payment-status.{{ $payment->trade_no }}',
  103. '.payment.status.updated',
  104. (e) => {
  105. if (['success', 'error'].includes(e.status)) {
  106. onFinal(e.status, e.message)
  107. }
  108. }
  109. );
  110. if (!success) {
  111. startPolling()
  112. }
  113. } catch (e) {
  114. console.error('Echo 初始化失败:', e)
  115. startPolling()
  116. }
  117. }
  118. window.addEventListener('load', setupPaymentListener)
  119. @else
  120. startPolling()
  121. @endif
  122. </script>
  123. @endsection