buy.blade.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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('home.service_name')}}</th>
  14. <th>{{trans('home.service_desc')}} </th>
  15. <th>{{trans('home.service_price')}}</th>
  16. <th>{{trans('home.service_quantity')}}</th>
  17. </tr>
  18. </thead>
  19. <tbody>
  20. <tr>
  21. <td class="text-middle">{{$goods->name}} </td>
  22. <td>{{trans('home.service_days')}}
  23. <strong>{{$goods->type === 1? $dataPlusDays:$goods->days}} {{trans('home.day')}}</strong>
  24. <br>
  25. <strong>{{$goods->traffic_label}}</strong> {{trans('home.bandwidth')}}
  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('home.coupon')}}"/>
  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('home.redeem_coupon')}}
  41. </button>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="col-lg-3 offset-lg-6 text-right">
  46. <p>{{trans('home.service_subtotal_price')}}
  47. <span>¥{{$goods->price}}</span>
  48. </p>
  49. <p class="page-invoice-amount">{{trans('home.service_total_price')}}
  50. <span class="grand-total">¥{{$goods->price}}</span>
  51. </p>
  52. </div>
  53. @endif
  54. <div class="col-md-12 mb-30">
  55. <div class="float-right">
  56. @include('user.components.purchase')
  57. @if($goods->type <= 2)
  58. <button class="btn btn-flat mt-2 mx-0 p-0" onclick="pay('credit','0')">
  59. <img src="/assets/images/payment/creditpay.svg" height="48px" alt="{{trans('home.service_pay_button')}}"/>
  60. </button>
  61. @endif
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. @endsection
  69. @section('javascript')
  70. <script>
  71. // 校验优惠券是否可用
  72. function redeemCoupon() {
  73. const coupon_sn = $('#coupon_sn').val();
  74. const goods_price = '{{$goods->price}}';
  75. $.ajax({
  76. method: 'POST',
  77. url: '{{route('redeemCoupon')}}',
  78. async: false,
  79. data: {_token: '{{csrf_token()}}', coupon_sn: coupon_sn, price: '{{$goods->price}}'},
  80. dataType: 'json',
  81. success: function(ret) {
  82. $('.input-group-prepend').remove();
  83. if (ret.status === 'success') {
  84. $('#coupon_sn').parent().prepend(
  85. '<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>');
  86. // 根据类型计算折扣后的总金额
  87. let total_price = 0;
  88. if (ret.data.type === 2) {
  89. total_price = goods_price * (1 - ret.data.value / 100);
  90. $('.page-invoice-amount').parent().prepend('<p>优惠码 - ' + ret.data.name + ' ' + ret.data.value + '折<br> 优惠 <span>¥ - ' +
  91. total_price.toFixed(2) + '</span></p>');
  92. total_price = goods_price - total_price;
  93. } else {
  94. total_price = goods_price - ret.data.value;
  95. total_price = total_price > 0 ? total_price : 0;
  96. if (ret.data.type === 1) {
  97. $('.page-invoice-amount').parent().prepend('优惠码-' + ret.data.name + ' <span>¥ - ' + ret.data.value + '</span>');
  98. }
  99. }
  100. // 四舍五入,保留2位小数
  101. $('.grand-total').text('¥' + total_price.toFixed(2));
  102. swal.fire({
  103. title: ret.message,
  104. icon: 'success',
  105. timer: 1300,
  106. showConfirmButton: false,
  107. });
  108. } else {
  109. $('.grand-total').text('¥' + 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. swal.fire({
  113. title: ret.title,
  114. text: ret.message,
  115. icon: 'error',
  116. });
  117. }
  118. },
  119. });
  120. }
  121. // 检查预支付
  122. function pay(method, pay_type) {
  123. // 存在套餐 和 购买类型为套餐时 出现提示
  124. if ('{{$activePlan}}' === '1' && '{{$goods->type}}' === '2') {
  125. swal.fire({
  126. title: '套餐存在冲突',
  127. html: '<p>当前购买套餐将自动设置为 <code>预支付套餐</code><p><ol class="text-left"><li> 预支付套餐会在生效中的套餐失效后自动开通!</li><li> 您可以在支付后手动激活套餐!</li></ol>',
  128. icon: 'info',
  129. showCancelButton: true,
  130. cancelButtonText: '返 回',
  131. confirmButtonText: '继 续',
  132. }).then((result) => {
  133. if (result.value) {
  134. contiousPay(method, pay_type);
  135. }
  136. });
  137. } else {
  138. contiousPay(method, pay_type);
  139. }
  140. }
  141. function contiousPay(method, pay_type) {
  142. const goods_id = '{{$goods->id}}';
  143. const coupon_sn = $('#coupon_sn').val();
  144. $.ajax({
  145. method: 'POST',
  146. url: '{{route('purchase')}}',
  147. async: false,
  148. data: {
  149. _token: '{{csrf_token()}}',
  150. goods_id: goods_id,
  151. coupon_sn: coupon_sn,
  152. method: method,
  153. pay_type: pay_type,
  154. },
  155. dataType: 'json',
  156. success: function(ret) {
  157. if (ret.status === 'success') {
  158. swal.fire({
  159. title: ret.message,
  160. icon: 'success',
  161. timer: 1300,
  162. showConfirmButton: false,
  163. });
  164. if (method === 'credit') {
  165. swal.fire({title: ret.message, icon: 'success', timer: 1000, showConfirmButton: false}).then(() => window.location.href = '{{route('invoice')}}');
  166. }
  167. if (ret.data) {
  168. window.location.href = '{{route('orderDetail', '')}}/' + ret.data;
  169. } else if (ret.url) {
  170. window.location.href = ret.url;
  171. }
  172. } else if (ret.status === 'info') {
  173. swal.fire({title: ret.title, text: ret.message, icon: 'question'});
  174. } else {
  175. swal.fire({
  176. title: ret.message,
  177. icon: 'error',
  178. });
  179. }
  180. },
  181. error: function() {
  182. swal.fire('未知错误', '请开工单通知客服', 'error');
  183. },
  184. });
  185. }
  186. </script>
  187. @endsection