buy.blade.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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">{{$username}} {{$goods->name}} </td>
  22. <td>{{trans('common.available_date')}}
  23. <strong>{{$goods->type === 1? $dataPlusDays:$goods->days}} {{trans('validation.attributes.day')}}</strong>
  24. <br>
  25. <strong>{{$goods->traffic_label}}</strong> {{trans('user.attribute.data')}}
  26. </td>
  27. <td class="text-middle"> ¥{{$goods->price}} </td>
  28. <td class="text-middle"> x 1</td>
  29. </tr>
  30. </tbody>
  31. </table>
  32. </div>
  33. <div class="row">
  34. @if($goods->type <= 2)
  35. <div class="col-lg-3 pl-30">
  36. <div class="input-group">
  37. <!--<input type="text" class="form-control" name="coupon_sn" id="coupon_sn" placeholder="{{trans('user.coupon.attribute')}}"/>-->
  38. <div class="input-group-btn">
  39. <!--<button type="submit" class="btn btn-info" onclick="redeemCoupon()">-->
  40. <!-- <i class="icon wb-loop" aria-hidden="true"></i> {{trans('common.apply')}}-->
  41. <!--</button>-->
  42. </div>
  43. </div>
  44. </div>
  45. <div class="col-lg-3 offset-lg-6 text-right">
  46. <p id="discount"></p>
  47. <p>{{trans('user.shop.subtotal')}}
  48. <span>¥{{$goods->price}}</span>
  49. </p>
  50. <p class="page-invoice-amount">{{trans('user.shop.total')}}
  51. <span class="grand-total">¥{{$goods->price}}</span>
  52. </p>
  53. </div>
  54. @endif
  55. <!--<div class="font-weight-400"></div>-->
  56. <li> <a href="/tickets" target="_blank" >购买须知:购买后48小时内可申请退款,具体查看退款规则 </a></li>
  57. <!--<li> <a href="/#wx_client" target="_blank" >微信支付请查看教程 </a></li>-->
  58. <!--<p <a href="https://user.vipone.xyz/#wx_client" target="_blank" >微信支付联系客服</a></p>-->
  59. <!--<li> 2.推荐使用支付宝支付 </li>-->
  60. <div class="col-md-12 mb-30">
  61. <div class="float-right">
  62. @include('user.components.purchase')
  63. @if($goods->type <= 2)
  64. <button class="btn btn-flat mt-2 mx-0 p-0" onclick="pay('credit','0')">
  65. <img src="/assets/images/payment/creditpay.svg" height="48px" alt="{{trans('user.shop.pay_credit')}}"/>
  66. </button>
  67. @endif
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. @endsection
  75. @section('javascript')
  76. <script>
  77. // 校验优惠券是否可用
  78. function redeemCoupon() {
  79. const coupon_sn = $('#coupon_sn').val();
  80. const goods_price = '{{$goods->price}}';
  81. $.ajax({
  82. method: 'POST',
  83. url: '{{route('redeemCoupon')}}',
  84. dataType: 'json',
  85. data: {_token: '{{csrf_token()}}', coupon_sn: coupon_sn, price: '{{$goods->price}}'},
  86. success: function(ret) {
  87. $('.input-group-prepend').remove();
  88. if (ret.status === 'success') {
  89. $('#coupon_sn').parent().prepend(
  90. '<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>');
  91. // 根据类型计算折扣后的总金额
  92. let total_price = 0;
  93. let coupon_text = document.getElementById('discount');
  94. if (ret.data.type === 2) {
  95. total_price = goods_price * (1 - ret.data.value / 100);
  96. coupon_text.innerHTML = '【{{trans('user.coupon.attribute')}}】:' + ret.data.name + ' - '
  97. + (100 - ret.data.value) + '%<br> {{trans('user.coupon.discount')}} - ¥' + total_price.toFixed(2);
  98. total_price = goods_price - total_price;
  99. } else {
  100. total_price = goods_price - ret.data.value;
  101. total_price = total_price > 0 ? total_price : 0;
  102. if (ret.data.type === 1) {
  103. coupon_text.innerHTML = '【{{trans('user.coupon.voucher')}}】:' + ret.data.name + ' -¥' + ret.data.value;
  104. }
  105. }
  106. // 四舍五入,保留2位小数
  107. $('.grand-total').text('¥' + total_price.toFixed(2));
  108. swal.fire({
  109. title: ret.message,
  110. icon: 'success',
  111. timer: 1300,
  112. showConfirmButton: false,
  113. });
  114. } else {
  115. $('.grand-total').text('¥' + goods_price);
  116. $('#coupon_sn').parent().prepend(
  117. '<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>');
  118. swal.fire({
  119. title: ret.title,
  120. text: ret.message,
  121. icon: 'error',
  122. });
  123. }
  124. },
  125. });
  126. }
  127. // 检查预支付
  128. function pay(method, pay_type) {
  129. // 存在套餐 和 购买类型为套餐时 出现提示
  130. if ('{{$activePlan}}' === '1' && '{{$goods->type}}' === '2') {
  131. swal.fire({
  132. title: '{{trans('user.shop.conflict')}}',
  133. html: '{!! trans('user.shop.conflict_tips') !!}',
  134. icon: 'info',
  135. showCancelButton: true,
  136. cancelButtonText: '{{trans('common.back')}}',
  137. confirmButtonText: '{{trans('common.continues')}}',
  138. }).then((result) => {
  139. if (result.value) {
  140. contiousPay(method, pay_type);
  141. }
  142. });
  143. } else {
  144. contiousPay(method, pay_type);
  145. }
  146. }
  147. function contiousPay(method, pay_type) {
  148. const goods_id = '{{$goods->id}}';
  149. const coupon_sn = $('#coupon_sn').val();
  150. $.ajax({
  151. method: 'POST',
  152. url: '{{route('purchase')}}',
  153. dataType: 'json',
  154. data: {
  155. _token: '{{csrf_token()}}',
  156. goods_id: goods_id,
  157. coupon_sn: coupon_sn,
  158. method: method,
  159. pay_type: pay_type,
  160. },
  161. success: function(ret) {
  162. if (ret.status === 'success') {
  163. swal.fire({
  164. title: ret.message,
  165. icon: 'success',
  166. timer: 1300,
  167. showConfirmButton: false,
  168. });
  169. if (method === 'credit') {
  170. swal.fire({title: ret.message, icon: 'success', timer: 1000, showConfirmButton: false}).then(() => window.location.href = '{{route('invoice')}}');
  171. }
  172. if (ret.data) {
  173. window.location.href = '{{route('orderDetail', '')}}/' + ret.data;
  174. } else if (ret.url) {
  175. window.location.href = ret.url;
  176. }
  177. } else if (ret.status === 'info') {
  178. swal.fire({title: ret.title, text: ret.message, icon: 'question'});
  179. } else {
  180. swal.fire({
  181. title: ret.message,
  182. icon: 'error',
  183. });
  184. }
  185. },
  186. error: function() {
  187. swal.fire('{{trans('user.unknown').trans('common.error')}}', '{{trans('user.shop.call4help')}}', 'error');
  188. },
  189. });
  190. }
  191. </script>
  192. @endsection