buy.blade.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. @if($goods->type == 3)
  12. <thead>
  13. <tr>
  14. <th class="invoice-title"> {{trans('home.service_name')}} </th>
  15. <th class="invoice-title"> {{trans('home.service_price')}} </th>
  16. </tr>
  17. </thead>
  18. <tbody>
  19. <tr>
  20. <td class="p-10">
  21. <h2>{{$goods->name}}</h2>
  22. 充值金额:{{$goods->price}}元
  23. </td>
  24. <td> ¥{{$goods->price}} </td>
  25. </tr>
  26. </tbody>
  27. @else
  28. <thead>
  29. <tr>
  30. <th>{{trans('home.service_name')}}</th>
  31. <th>{{trans('home.service_desc')}} </th>
  32. <th>{{trans('home.service_price')}}</th>
  33. <th>{{trans('home.service_quantity')}}</th>
  34. </tr>
  35. </thead>
  36. <tbody>
  37. <tr>
  38. <td class="text-middle">{{$goods->name}} </td>
  39. <td>{{trans('home.service_days')}}
  40. <strong>{{$goods->type==1? $dataPlusDays:$goods->days}} {{trans('home.day')}}</strong>
  41. <br>
  42. <strong>{{$goods->traffic_label}}</strong> {{trans('home.bandwidth')}}
  43. </td>
  44. <td class="text-middle"> ¥{{$goods->price}} </td>
  45. <td class="text-middle"> x 1</td>
  46. </tr>
  47. </tbody>
  48. @endif
  49. </table>
  50. </div>
  51. @if($goods->type <= 2)
  52. <div class="row">
  53. <div class="col-lg-3 pl-30">
  54. <div class="input-group">
  55. <input type="text" class="form-control" name="coupon_sn" id="coupon_sn" placeholder="{{trans('home.coupon')}}"/>
  56. <div class="input-group-btn">
  57. <button type="submit" class="btn btn-info" onclick="redeemCoupon()"><i class="icon wb-loop" aria-hidden="true"></i> {{trans('home.redeem_coupon')}}</button>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="col-lg-3 offset-lg-6 text-right">
  62. <p>{{trans('home.service_subtotal_price')}}
  63. <span>¥{{$goods->price}}</span>
  64. </p>
  65. <p class="page-invoice-amount">{{trans('home.service_total_price')}}
  66. <span class="grand-total">¥{{$goods->price}}</span>
  67. </p>
  68. </div>
  69. @endif
  70. <div class="col-md-12 mb-30">
  71. <div class="float-right">
  72. @if(\App\Components\Helpers::systemConfig()['is_alipay'])
  73. <button class="btn btn-lg btn-success" onclick="checkPrePaid('4')"> 支付宝扫码</button>
  74. @elseif(\App\Components\Helpers::systemConfig()['is_f2fpay'])
  75. <button class="btn btn-lg btn-success" onclick="checkPrePaid('5')"> 支付宝扫码</button>
  76. @endif
  77. @if($goods->type <= 2)
  78. <button class="btn btn-lg btn-primary" onclick="checkPrePaid('1')"> {{trans('home.service_pay_button')}} </button>
  79. @endif
  80. </div>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. </div>
  86. @endsection
  87. @section('script')
  88. <script type="text/javascript">
  89. // 校验优惠券是否可用
  90. function redeemCoupon() {
  91. const coupon_sn = $('#coupon_sn').val();
  92. const goods_price = '{{$goods->price}}';
  93. $.ajax({
  94. type: "POST",
  95. url: "/redeemCoupon",
  96. async: false,
  97. data: {_token: '{{csrf_token()}}', coupon_sn: coupon_sn, price: '{{$goods->price}}'},
  98. dataType: 'json',
  99. success: function (ret) {
  100. $(".input-group-prepend").remove();
  101. if (ret.status === 'success') {
  102. $("#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>');
  103. // 根据类型计算折扣后的总金额
  104. let total_price = 0;
  105. if (ret.data.type === 2) {
  106. total_price = goods_price * (1 - ret.data.discount / 10);
  107. $(".page-invoice-amount").parent().prepend('<p>优惠码 - ' + ret.data.name + ' ' + ret.data.discount + '折<br> 优惠 <span>¥ - ' + total_price.toFixed(2) + '</span></p>');
  108. total_price = goods_price - total_price;
  109. } else {
  110. total_price = goods_price - ret.data.amount;
  111. total_price = total_price > 0 ? total_price : 0;
  112. if (ret.data.type === 1) {
  113. $(".page-invoice-amount").parent().prepend('优惠码-' + ret.data.name + ' <span>¥ - ' + ret.data.amount + '</span>');
  114. }
  115. }
  116. // 四舍五入,保留2位小数
  117. $(".grand-total").text('¥' + total_price.toFixed(2));
  118. swal.fire({
  119. title: ret.message,
  120. type: 'success',
  121. timer: 1300,
  122. showConfirmButton: false
  123. });
  124. } else {
  125. $(".grand-total").text("¥" + goods_price);
  126. $("#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>');
  127. swal.fire({
  128. title: ret.title,
  129. text: ret.message,
  130. type: 'error'
  131. });
  132. }
  133. }
  134. });
  135. }
  136. // 检查预支付
  137. function checkPrePaid(pay_type) {
  138. // 存在套餐 和 购买类型为套餐时 出现提示
  139. if ('{{$activePlan}}' === '1' && '{{$goods->type}}' === '2') {
  140. swal.fire({
  141. title: '套餐存在冲突',
  142. html: '<p>当前购买套餐将自动设置为 <code>预支付套餐</code><p><ol class="text-left"><li> 预支付套餐会在生效中的套餐失效后自动开通!</li><li> 您可以在支付后手动激活套餐!</li></ol>',
  143. type: 'info',
  144. showCancelButton: true,
  145. cancelButtonText: '返 回',
  146. confirmButtonText: '继 续',
  147. }).then((result) => {
  148. if (result.value) {
  149. pay(pay_type);
  150. }
  151. })
  152. } else {
  153. pay(pay_type);
  154. }
  155. }
  156. // 支付
  157. function pay(pay_type) {
  158. const goods_id = '{{$goods->id}}';
  159. const coupon_sn = $('#coupon_sn').val();
  160. $.ajax({
  161. type: "POST",
  162. url: "/payment/create",
  163. async: false,
  164. data: {_token: '{{csrf_token()}}', goods_id: goods_id, coupon_sn: coupon_sn, pay_type: pay_type},
  165. dataType: 'json',
  166. success: function (ret) {
  167. if (ret.status === 'success') {
  168. swal.fire({
  169. title: ret.message,
  170. type: 'success',
  171. timer: 1300,
  172. showConfirmButton: false
  173. });
  174. if (pay_type === '1') {
  175. swal.fire({title: ret.message, type: 'success', timer: 1000, showConfirmButton: false})
  176. .then(() => window.location.href = '/invoices')
  177. } else if (pay_type === '4') {
  178. // 如果是Alipay支付写入Alipay的支付页面
  179. document.body.innerHTML += ret.data;
  180. document.forms['alipaysubmit'].submit();
  181. } else {
  182. window.location.href = '/payment/' + ret.data;
  183. }
  184. } else if (ret.status === 'info') {
  185. swal.fire({title: ret.title, text: ret.message, type: 'question'});
  186. } else {
  187. swal.fire({
  188. title: ret.message,
  189. type: 'error'
  190. })
  191. }
  192. },
  193. error: function () {
  194. swal.fire('未知错误', '请开工单通知客服', 'error')
  195. }
  196. });
  197. }
  198. </script>
  199. @endsection