buy.blade.php 7.8 KB

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