buy.blade.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. @extends('user.layouts')
  2. @section('css')
  3. <link href="/assets/css/invoice.min.css" rel="stylesheet">
  4. @endsection
  5. @section('content')
  6. <div class="page-content">
  7. <div class="panel">
  8. <div class="panel-body container-fluid">
  9. <div class="page-invoice-table table-responsive">
  10. <table class="table table-hover text-md-center">
  11. <thead>
  12. <tr>
  13. <th>{{ trans('user.shop.service') }}</th>
  14. <th>{{ trans('user.shop.description') }} </th>
  15. <th>{{ trans('user.shop.price') }}</th>
  16. <th>{{ trans('user.shop.quantity') }}</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr>
  21. <td class="text-middle">{{ $goods->name }} </td>
  22. <td>{{ trans('common.available_date') }}
  23. <strong>{{ $goods->type === 1 ? $dataPlusDays : $goods->days }} {{ trans_choice('common.days.attribute', 1) }}</strong>
  24. <br>
  25. <strong>{{ $goods->traffic_label }}</strong> {{ trans('user.attribute.data') }}
  26. <br>
  27. {{ trans('user.account.speed_limit') }}
  28. <strong> {{ $goods->speed_limit ? $goods->speed_limit . ' Mbps' : trans('user.service.unlimited') }} </strong>
  29. </td>
  30. <td class="text-middle"> {{ $goods->price_tag }} </td>
  31. <td class="text-middle"> x 1</td>
  32. </tr>
  33. </tbody>
  34. </table>
  35. </div>
  36. <div class="row">
  37. @if ($goods->type <= 2)
  38. <div class="col-lg-3 pl-30">
  39. <div class="input-group">
  40. <input class="form-control" id="coupon_sn" name="coupon_sn" type="text" placeholder="{{ trans('model.coupon.attribute') }}" />
  41. <div class="input-group-btn">
  42. <button class="btn btn-info" type="submit" onclick="redeemCoupon()">
  43. <i class="icon wb-loop" aria-hidden="true"></i> {{ trans('common.apply') }}
  44. </button>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="col-lg-3 offset-lg-6 text-right">
  49. <p id="discount"></p>
  50. <p>{{ trans('user.shop.subtotal') }}
  51. <span>{{ $goods->price_tag }}</span>
  52. </p>
  53. <p class="page-invoice-amount">{{ trans('user.shop.total') }}
  54. <span class="grand-total">{{ $goods->price_tag }}</span>
  55. </p>
  56. </div>
  57. @endif
  58. <div class="col-md-12 mb-30">
  59. <div class="float-right">
  60. @include('user.components.purchase')
  61. @if ($goods->type <= 2)
  62. <button class="btn btn-flat mt-2 mx-0 p-0" onclick="pay('credit', '0')">
  63. <img src="/assets/images/payment/creditpay.svg" alt="{{ trans('user.shop.pay_credit') }}" height="48px" />
  64. </button>
  65. @endif
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. @endsection
  73. @section('javascript')
  74. <script>
  75. function redeemCoupon() { // 校验优惠券是否可用
  76. const coupon_sn = $('#coupon_sn').val();
  77. let tag = '{{ $goods->price_tag }}'.match(/(.*?[^0-9])(\d+\.?.*)/);
  78. const goods_price = tag[2];
  79. const sign = tag[1];
  80. ajaxPost('{{ route('shop.coupon.check', $goods) }}', {
  81. coupon_sn: coupon_sn
  82. }, {
  83. success: function(ret) {
  84. $('.input-group-prepend').remove();
  85. if (ret.status === 'success') {
  86. $('#coupon_sn').parent().prepend(
  87. '<div class="input-group-prepend"><span class="input-group-text bg-green-700"><i class="icon wb-check white" aria-hidden="true"></i></span></div>'
  88. );
  89. // 根据类型计算折扣后的总金额
  90. let total_price;
  91. let coupon_text = document.getElementById('discount');
  92. if (ret.data.type === 2) {
  93. const discount = goods_price * (1 - ret.data.value / 100);
  94. coupon_text.innerHTML = '【{{ trans('admin.coupon.type.discount') }}】: ' + ret.data.name + ' _ ' +
  95. (100 - ret.data.value) + '%<br> {{ trans('user.coupon.discount') }}: ➖ ' + sign +
  96. discount.toFixed(2);
  97. total_price = goods_price - discount;
  98. } else {
  99. total_price = goods_price - ret.data.value.match(/(.*?[^0-9])(\d+\.?.*)/)[2];
  100. total_price = total_price > 0 ? total_price : 0;
  101. if (ret.data.type === 1) {
  102. coupon_text.innerHTML = '【{{ trans('admin.coupon.type.voucher') }}】: ' + ret.data.name + ' -' +
  103. ret.data.value;
  104. }
  105. }
  106. // 四舍五入,保留2位小数
  107. $('.grand-total').text(sign + total_price.toFixed(2));
  108. } else {
  109. $('.grand-total').text(sign + goods_price);
  110. $('#coupon_sn').parent().prepend(
  111. '<div class="input-group-prepend"><span class="input-group-text bg-red-700"><i class="icon wb-close white" aria-hidden="true"></i></span></div>'
  112. );
  113. }
  114. }
  115. });
  116. }
  117. function pay(method, pay_type) { // 检查预支付
  118. if ('{{ $activePlan }}' === '1' && '{{ $goods->type }}' === '2') { // 存在套餐 和 购买类型为套餐时 出现提示
  119. showConfirm({
  120. title: '{{ trans('user.shop.conflict') }}',
  121. html: '{!! trans('user.shop.conflict_tips') !!}',
  122. icon: 'info',
  123. cancelButtonText: '{{ trans('common.back') }}',
  124. confirmButtonText: '{{ trans('common.continue') }}',
  125. onConfirm: function() {
  126. continuousPayment(method, pay_type);
  127. }
  128. });
  129. } else {
  130. continuousPayment(method, pay_type);
  131. }
  132. }
  133. function continuousPayment(method, pay_type) {
  134. ajaxPost('{{ route('purchase') }}', {
  135. goods_id: '{{ $goods->id }}',
  136. coupon_sn: $('#coupon_sn').val(),
  137. method: method,
  138. pay_type: pay_type,
  139. }, {
  140. success: function(ret) {
  141. let options = {};
  142. if (ret.status === 'success') {
  143. if (method === 'credit') {
  144. options.redirectUrl = '{{ route('invoice.index') }}';
  145. } else if (ret.data) {
  146. options.redirectUrl = '{{ route('orderDetail', '') }}/' + ret.data;
  147. } else if (ret.url) {
  148. options.redirectUrl = ret.url;
  149. }
  150. }
  151. handleResponse(ret, options)
  152. }
  153. });
  154. }
  155. </script>
  156. @endsection