buy.blade.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. @extends('user.layouts')
  2. @section('css')
  3. <link rel="stylesheet" href="/assets/examples/css/pages/invoice.css">
  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-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 text-center"> {{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 class="text-center"> ¥{{$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->days}} {{trans('home.day')}}</strong>
  41. <br>
  42. @if($goods->type == '2')
  43. <strong>{{$goods->traffic_label}}</strong> {{trans('home.account_bandwidth_usage')}}/{{trans('home.month')}}
  44. @else
  45. <strong>{{$goods->traffic_label}}</strong> {{trans('home.account_bandwidth_usage')}}/{{$goods->days}} {{trans('home.day')}}
  46. @endif</td>
  47. <td class="text-middle"> ¥{{$goods->price}} </td>
  48. <td class="text-middle"> x 1</td>
  49. </tr>
  50. </tbody>
  51. @endif
  52. </table>
  53. </div>
  54. @if($goods->type <= 2)
  55. <div class="row">
  56. <div class="col-lg-3 pl-30">
  57. <div class="input-group">
  58. <input class="form-control" type="text" name="coupon_sn" id="coupon_sn" placeholder="{{trans('home.coupon')}}"/>
  59. <div class="input-group-btn">
  60. <button type="submit" class="btn btn-info" onclick="redeemCoupon()"><i class="icon wb-loop" aria-hidden="true"></i> {{trans('home.redeem_coupon')}}
  61. </button>
  62. </div>
  63. </div>
  64. </div>
  65. <div class="col-lg-3 offset-lg-6 text-right">
  66. <p>{{trans('home.service_subtotal_price')}}
  67. <span>¥{{$goods->price}}</span>
  68. </p>
  69. <p class="page-invoice-amount">{{trans('home.service_total_price')}}
  70. <span class="grand-total">¥{{$goods->price}}</span>
  71. </p>
  72. </div>
  73. @endif
  74. <div class="col-md-12 mb-30">
  75. <div class="float-right">
  76. @if(\App\Components\Helpers::systemConfig()['is_youzan'])
  77. <button class="btn btn-lg btn-danger" onclick="onlinePay(0)"> {{trans('home.online_pay')}} </button>
  78. @elseif(\App\Components\Helpers::systemConfig()['is_alipay'])
  79. <button class="btn btn-lg btn-success" onclick="onlinePay(4)"> 支付宝扫码 </button>
  80. @elseif(\App\Components\Helpers::systemConfig()['is_f2fpay'])
  81. <button class="btn btn-lg btn-success" onclick="onlinePay(5)"> 支付宝扫码 </button>
  82. @endif
  83. @if($goods->type <= 2)
  84. <button class="btn btn-lg btn-primary" onclick="pay()"> {{trans('home.service_pay_button')}} </button>
  85. @endif
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </div>
  92. @endsection
  93. @section('script')
  94. <script type="text/javascript">
  95. // 校验优惠券是否可用
  96. function redeemCoupon() {
  97. const coupon_sn = $('#coupon_sn').val();
  98. const goods_price = '{{$goods->price}}';
  99. $.ajax({
  100. type: "POST",
  101. url: "/redeemCoupon",
  102. async: false,
  103. data: {_token: '{{csrf_token()}}', coupon_sn: coupon_sn},
  104. dataType: 'json',
  105. success: function (ret) {
  106. $(".input-group-prepend").remove();
  107. if (ret.status === 'success') {
  108. $("#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>');
  109. // 根据类型计算折扣后的总金额
  110. let total_price = 0;
  111. if (ret.data.type === '2') {
  112. total_price = goods_price * ret.data.discount / 10;
  113. } else {
  114. total_price = goods_price - ret.data.amount;
  115. total_price = total_price > 0 ? total_price : 0;
  116. }
  117. // 四舍五入,保留2位小数
  118. $(".grand-total").text("¥" + total_price.toFixed(2));
  119. swal.fire({
  120. title: ret.message,
  121. type: 'success',
  122. timer: 1500,
  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.message,
  129. type: 'error',
  130. timer: 1500,
  131. });
  132. }
  133. }
  134. });
  135. }
  136. // 在线支付
  137. function onlinePay(pay_type) {
  138. const goods_id = '{{$goods->id}}';
  139. const coupon_sn = $('#coupon_sn').val();
  140. $.ajax({
  141. type: "POST",
  142. url: "/payment/create",
  143. async: false,
  144. data: {_token: '{{csrf_token()}}', goods_id: goods_id, coupon_sn: coupon_sn, pay_type: pay_type},
  145. dataType: 'json',
  146. success: function (ret) {
  147. if (ret.status === 'success') {
  148. swal.fire({
  149. title: ret.message,
  150. type: 'success',
  151. timer: 1300,
  152. });
  153. if (pay_type === 4) {
  154. // 如果是Alipay支付写入Alipay的支付页面
  155. document.body.innerHTML += ret.data;
  156. document.forms['alipaysubmit'].submit();
  157. } else {
  158. window.location.href = '/payment/' + ret.data;
  159. }
  160. } else {
  161. swal.fire({
  162. title: ret.message,
  163. type: 'error',
  164. })
  165. }
  166. },
  167. error: function () {
  168. swal.fire('未知错误', '请开工单通知客服', 'error')
  169. }
  170. });
  171. }
  172. // 余额支付
  173. function pay() {
  174. const goods_id = '{{$goods->id}}';
  175. const coupon_sn = $('#coupon_sn').val();
  176. $.ajax({
  177. type: "POST",
  178. url: "/buy/" + goods_id,
  179. async: false,
  180. data: {_token: '{{csrf_token()}}', coupon_sn: coupon_sn},
  181. dataType: 'json',
  182. success: function (ret) {
  183. if (ret.status === 'success') {
  184. swal.fire({title: ret.message, type: 'success',})
  185. .then(() => window.location.href = '/invoices')
  186. } else {
  187. swal.fire({title: ret.message, type: 'error',})
  188. }
  189. },
  190. error: function () {
  191. swal.fire({title: '未知错误!请开工单通知客服', type: 'error',})
  192. }
  193. });
  194. }
  195. </script>
  196. @endsection