buy.blade.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. @if(\App\Components\Helpers::systemConfig()['is_alipay'])
  55. <button class="btn btn-lg btn-success" onclick="checkPrePaid('4')"> 支付宝扫码</button>
  56. @elseif(\App\Components\Helpers::systemConfig()['is_f2fpay'])
  57. <button class="btn btn-lg btn-success" onclick="checkPrePaid('5')"> 支付宝扫码</button>
  58. @endif
  59. @if($goods->type <= 2)
  60. <button class="btn btn-lg btn-primary" onclick="checkPrePaid('1')"> {{trans('home.service_pay_button')}} </button>
  61. @endif
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </div>
  68. @endsection
  69. @section('script')
  70. <script type="text/javascript">
  71. // 校验优惠券是否可用
  72. function redeemCoupon() {
  73. const coupon_sn = $('#coupon_sn').val();
  74. const goods_price = '{{$goods->price}}';
  75. $.ajax({
  76. type: "POST",
  77. url: "/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('<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>');
  85. // 根据类型计算折扣后的总金额
  86. let total_price = 0;
  87. if (ret.data.type === 2) {
  88. total_price = goods_price * (1 - ret.data.discount / 10);
  89. $(".page-invoice-amount").parent().prepend('<p>优惠码 - ' + ret.data.name + ' ' + ret.data.discount + '折<br> 优惠 <span>¥ - ' + total_price.toFixed(2) + '</span></p>');
  90. total_price = goods_price - total_price;
  91. } else {
  92. total_price = goods_price - ret.data.amount;
  93. total_price = total_price > 0 ? total_price : 0;
  94. if (ret.data.type === 1) {
  95. $(".page-invoice-amount").parent().prepend('优惠码-' + ret.data.name + ' <span>¥ - ' + ret.data.amount + '</span>');
  96. }
  97. }
  98. // 四舍五入,保留2位小数
  99. $(".grand-total").text('¥' + total_price.toFixed(2));
  100. swal.fire({
  101. title: ret.message,
  102. type: 'success',
  103. timer: 1300,
  104. showConfirmButton: false
  105. });
  106. } else {
  107. $(".grand-total").text("¥" + goods_price);
  108. $("#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>');
  109. swal.fire({
  110. title: ret.title,
  111. text: ret.message,
  112. type: 'error'
  113. });
  114. }
  115. }
  116. });
  117. }
  118. // 检查预支付
  119. function checkPrePaid(pay_type) {
  120. // 存在套餐 和 购买类型为套餐时 出现提示
  121. if ('{{$activePlan}}' === '1' && '{{$goods->type}}' === '2') {
  122. swal.fire({
  123. title: '套餐存在冲突',
  124. html: '<p>当前购买套餐将自动设置为 <code>预支付套餐</code><p><ol class="text-left"><li> 预支付套餐会在生效中的套餐失效后自动开通!</li><li> 您可以在支付后手动激活套餐!</li></ol>',
  125. type: 'info',
  126. showCancelButton: true,
  127. cancelButtonText: '返 回',
  128. confirmButtonText: '继 续',
  129. }).then((result) => {
  130. if (result.value) {
  131. pay(pay_type);
  132. }
  133. })
  134. } else {
  135. pay(pay_type);
  136. }
  137. }
  138. // 支付
  139. function pay(pay_type) {
  140. const goods_id = '{{$goods->id}}';
  141. const coupon_sn = $('#coupon_sn').val();
  142. $.ajax({
  143. type: "POST",
  144. url: "/payment/create",
  145. async: false,
  146. data: {_token: '{{csrf_token()}}', goods_id: goods_id, coupon_sn: coupon_sn, pay_type: pay_type},
  147. dataType: 'json',
  148. success: function (ret) {
  149. if (ret.status === 'success') {
  150. swal.fire({
  151. title: ret.message,
  152. type: 'success',
  153. timer: 1300,
  154. showConfirmButton: false
  155. });
  156. if (pay_type === '1') {
  157. swal.fire({title: ret.message, type: 'success', timer: 1000, showConfirmButton: false})
  158. .then(() => window.location.href = '/invoices')
  159. } else if (pay_type === '4') {
  160. // 如果是Alipay支付写入Alipay的支付页面
  161. document.body.innerHTML += ret.data;
  162. document.forms['alipaysubmit'].submit();
  163. } else {
  164. window.location.href = '/payment/' + ret.data;
  165. }
  166. } else if (ret.status === 'info') {
  167. swal.fire({title: ret.title, text: ret.message, type: 'question'});
  168. } else {
  169. swal.fire({
  170. title: ret.message,
  171. type: 'error'
  172. })
  173. }
  174. },
  175. error: function () {
  176. swal.fire('未知错误', '请开工单通知客服', 'error')
  177. }
  178. });
  179. }
  180. </script>
  181. @endsection