addOrder.blade.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. @extends('user.layouts')
  2. @section('css')
  3. <link href="/assets/pages/css/invoice-2.min.css" rel="stylesheet" type="text/css" />
  4. @endsection
  5. @section('title', trans('home.panel'))
  6. @section('content')
  7. <!-- BEGIN CONTENT BODY -->
  8. <div class="page-content" style="padding-top:0;">
  9. <!-- BEGIN PAGE BASE CONTENT -->
  10. <div class="invoice-content-2 bordered">
  11. <div class="row invoice-body">
  12. <div class="col-xs-12 table-responsive">
  13. <table class="table table-hover">
  14. <thead>
  15. <tr>
  16. <th class="invoice-title"> {{trans('home.service_name')}} </th>
  17. <th class="invoice-title text-center"> {{trans('home.service_price')}} </th>
  18. <th class="invoice-title text-center"> {{trans('home.service_quantity')}} </th>
  19. </tr>
  20. </thead>
  21. <tbody>
  22. <tr>
  23. <td style="padding: 10px;">
  24. <h2>{{$goods->name}}</h2>
  25. {{trans('home.service_traffic')}} {{$goods->traffic}}
  26. <br/>
  27. {{trans('home.service_days')}} {{$goods->days}} {{trans('home.day')}}
  28. </td>
  29. <td class="text-center"> ¥{{$goods->price}} </td>
  30. <td class="text-center"> x 1 </td>
  31. </tr>
  32. </tbody>
  33. </table>
  34. </div>
  35. </div>
  36. <div class="row invoice-subtotal">
  37. <div class="col-xs-3">
  38. <h2 class="invoice-title"> {{trans('home.service_subtotal_price')}} </h2>
  39. <p class="invoice-desc"> ¥{{$goods->price}} </p>
  40. </div>
  41. <div class="col-xs-3">
  42. <h2 class="invoice-title"> {{trans('home.service_total_price')}} </h2>
  43. <p class="invoice-desc grand-total"> ¥{{$goods->price}} </p>
  44. </div>
  45. <div class="col-xs-6">
  46. <h2 class="invoice-title"> {{trans('home.coupon')}} </h2>
  47. <p class="invoice-desc">
  48. <div class="input-group">
  49. <input class="form-control" type="text" name="coupon_sn" id="coupon_sn" placeholder="{{trans('home.coupon')}}" />
  50. <span class="input-group-btn">
  51. <button class="btn btn-default" type="button" onclick="redeemCoupon()"><i class="fa fa-refresh"></i> {{trans('home.redeem_coupon')}} </button>
  52. </span>
  53. </div>
  54. </p>
  55. </div>
  56. </div>
  57. <div class="row">
  58. <div class="col-xs-12" style="text-align: right;">
  59. @if($is_youzan)
  60. <a class="btn btn-lg red hidden-print" onclick="onlinePay()"> {{trans('home.online_pay')}} </a>
  61. @endif
  62. <a class="btn btn-lg blue hidden-print uppercase" onclick="pay()"> {{trans('home.service_pay_button')}} </a>
  63. </div>
  64. </div>
  65. </div>
  66. <!-- END PAGE BASE CONTENT -->
  67. </div>
  68. <!-- END CONTENT BODY -->
  69. @endsection
  70. @section('script')
  71. <script src="/js/layer/layer.js" type="text/javascript"></script>
  72. <script type="text/javascript">
  73. // 校验优惠券是否可用
  74. function redeemCoupon() {
  75. var coupon_sn = $('#coupon_sn').val();
  76. var goods_price = '{{$goods->price}}';
  77. $.ajax({
  78. type: "POST",
  79. url: "{{url('user/redeemCoupon')}}",
  80. async: false,
  81. data: {_token:'{{csrf_token()}}', coupon_sn:coupon_sn},
  82. dataType: 'json',
  83. beforeSend: function () {
  84. index = layer.load(1, {
  85. shade: [0.7,'#CCC']
  86. });
  87. },
  88. success: function (ret) {
  89. console.log(ret);
  90. layer.close(index);
  91. $("#coupon_sn").parent().removeClass("has-error");
  92. $("#coupon_sn").parent().removeClass("has-success");
  93. $(".input-group-addon").remove();
  94. if (ret.status == 'success') {
  95. $("#coupon_sn").parent().addClass('has-success');
  96. $("#coupon_sn").parent().prepend('<span class="input-group-addon"><i class="fa fa-check fa-fw"></i></span>');
  97. // 根据类型计算折扣后的总金额
  98. var total_price = 0;
  99. if (ret.data.type == '2') {
  100. total_price = goods_price * ret.data.discount / 10;
  101. } else {
  102. total_price = goods_price - ret.data.amount;
  103. total_price = total_price > 0 ? total_price : 0;
  104. }
  105. $(".grand-total").text("¥" + total_price);
  106. } else {
  107. $(".grand-total").text("¥" + goods_price);
  108. $("#coupon_sn").parent().addClass('has-error');
  109. $("#coupon_sn").parent().remove('.input-group-addon');
  110. $("#coupon_sn").parent().prepend('<span class="input-group-addon"><i class="fa fa-remove fa-fw"></i></span>');
  111. }
  112. }
  113. });
  114. }
  115. // 在线支付
  116. function onlinePay() {
  117. var goods_id = '{{$goods->id}}';
  118. var coupon_sn = $('#coupon_sn').val();
  119. index = layer.load(1, {
  120. shade: [0.7,'#CCC']
  121. });
  122. $.ajax({
  123. type: "POST",
  124. url: "{{url('payment/create')}}",
  125. async: false,
  126. data: {_token:'{{csrf_token()}}', goods_id:goods_id, coupon_sn:coupon_sn},
  127. dataType: 'json',
  128. beforeSend: function () {
  129. index = layer.load(1, {
  130. shade: [0.7,'#CCC']
  131. });
  132. },
  133. success: function (ret) {
  134. layer.msg(ret.message, {time:1300}, function() {
  135. if (ret.status == 'success') {
  136. window.location.href = '{{url('payment')}}' + "/" + ret.data;
  137. } else {
  138. layer.close(index);
  139. }
  140. });
  141. }
  142. //complete: function () {
  143. //
  144. //}
  145. });
  146. }
  147. // 余额支付
  148. function pay() {
  149. var goods_id = '{{$goods->id}}';
  150. var coupon_sn = $('#coupon_sn').val();
  151. index = layer.load(1, {
  152. shade: [0.7,'#CCC']
  153. });
  154. $.ajax({
  155. type: "POST",
  156. url: "{{url('user/addOrder')}}",
  157. async: false,
  158. data: {_token:'{{csrf_token()}}', goods_id:goods_id, coupon_sn:coupon_sn},
  159. dataType: 'json',
  160. beforeSend: function () {
  161. index = layer.load(1, {
  162. shade: [0.7,'#CCC']
  163. });
  164. },
  165. success: function (ret) {
  166. layer.msg(ret.message, {time:1300}, function() {
  167. if (ret.status == 'success') {
  168. window.location.href = '{{url('user/orderList')}}';
  169. } else {
  170. layer.close(index);
  171. }
  172. });
  173. }
  174. });
  175. }
  176. </script>
  177. @endsection