addOrder.blade.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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', '控制面板')
  6. @section('content')
  7. <!-- BEGIN CONTENT BODY -->
  8. <div class="page-content">
  9. <!-- BEGIN PAGE BREADCRUMB -->
  10. <ul class="page-breadcrumb breadcrumb">
  11. <li>
  12. <a href="{{url('user/addOrder')}}">购买</a>
  13. <i class="fa fa-circle"></i>
  14. </li>
  15. </ul>
  16. <!-- END PAGE BREADCRUMB -->
  17. <!-- BEGIN PAGE BASE CONTENT -->
  18. <div class="invoice-content-2 bordered">
  19. <div class="row invoice-body">
  20. <div class="col-xs-12 table-responsive">
  21. <table class="table table-hover">
  22. <thead>
  23. <tr>
  24. <th class="invoice-title uppercase"> 商品信息 </th>
  25. <th class="invoice-title uppercase text-center"> 单价 </th>
  26. <th class="invoice-title uppercase text-center"> 数量 </th>
  27. <th class="invoice-title uppercase text-center"> 小计 </th>
  28. </tr>
  29. </thead>
  30. <tbody>
  31. <tr>
  32. <td style="padding: 20px;">
  33. <h3>{{$goods->name}}</h3>
  34. <p> <img src="{{$goods->logo}}" style="width:100px; height:100px;"> 内含流量 {{$goods->traffic}} ,有效30天 </p>
  35. </td>
  36. <td class="text-center sbold"> ¥{{$goods->price}} </td>
  37. <td class="text-center sbold"> x 1 </td>
  38. <td class="text-center sbold"> ¥{{$goods->price}} </td>
  39. </tr>
  40. </tbody>
  41. </table>
  42. </div>
  43. </div>
  44. <div class="row invoice-subtotal">
  45. <div class="col-xs-3">
  46. <h2 class="invoice-title uppercase"> 共计 </h2>
  47. <p class="invoice-desc"> ¥{{$goods->price}} </p>
  48. </div>
  49. <div class="col-xs-3">
  50. <h2 class="invoice-title uppercase"> 优惠 </h2>
  51. <p class="invoice-desc">
  52. <div class="input-group">
  53. <input class="form-control" type="text" name="coupon_sn" id="coupon_sn" placeholder="优惠券" />
  54. <span class="input-group-btn">
  55. <button class="btn btn-default" type="button" onclick="redeemCoupon()"><i class="fa fa-refresh"></i> 使用 </button>
  56. </span>
  57. </div>
  58. </p>
  59. </div>
  60. <div class="col-xs-6">
  61. <h2 class="invoice-title uppercase"> 实际结算 </h2>
  62. <p class="invoice-desc grand-total"> ¥{{$goods->price}} </p>
  63. </div>
  64. </div>
  65. <div class="row">
  66. <div class="col-xs-12">
  67. <a class="btn btn-lg green-haze hidden-print uppercase print-btn" onclick="addOrder()"> 支付 </a>
  68. </div>
  69. </div>
  70. </div>
  71. <!-- END PAGE BASE CONTENT -->
  72. <!-- END CONTENT BODY -->
  73. @endsection
  74. @section('script')
  75. <script src="/assets/global/plugins/bootbox/bootbox.min.js" type="text/javascript"></script>
  76. <script type="text/javascript">
  77. // 校验优惠券是否可用
  78. function redeemCoupon() {
  79. var coupon_sn = $('#coupon_sn').val();
  80. var goods_price = '{{$goods->price}}';
  81. $.ajax({
  82. type: "POST",
  83. url: "{{url('user/redeemCoupon')}}",
  84. async: false,
  85. data: {_token:'{{csrf_token()}}', coupon_sn:coupon_sn},
  86. dataType: 'json',
  87. success: function (ret) {
  88. console.log(ret);
  89. $("#coupon_sn").parent().removeClass("has-error");
  90. $("#coupon_sn").parent().removeClass("has-success");
  91. $(".input-group-addon").remove();
  92. if (ret.status == 'success') {
  93. $("#coupon_sn").parent().addClass('has-success');
  94. $("#coupon_sn").parent().prepend('<span class="input-group-addon"><i class="fa fa-check fa-fw"></i></span>');
  95. // 根据类型计算折扣后的总金额
  96. var total_price = 0;
  97. if (ret.data.type == '2') {
  98. total_price = goods_price * ret.data.discount;
  99. } else {
  100. total_price = goods_price - ret.data.amount;
  101. }
  102. $(".grand-total").text("¥" + total_price);
  103. } else {
  104. $("#coupon_sn").parent().addClass('has-error');
  105. $("#coupon_sn").parent().remove('.input-group-addon');
  106. $("#coupon_sn").parent().prepend('<span class="input-group-addon"><i class="fa fa-remove fa-fw"></i></span>');
  107. }
  108. }
  109. });
  110. }
  111. // 添加订单
  112. function addOrder() {
  113. var goods_id = '{{$goods->id}}';
  114. var coupon_sn = $('#coupon_sn').val();
  115. $.ajax({
  116. type: "POST",
  117. url: "{{url('user/addOrder')}}",
  118. async: false,
  119. data: {_token:'{{csrf_token()}}', goods_id:goods_id, coupon_sn:coupon_sn},
  120. dataType: 'json',
  121. success: function (ret) {
  122. if (ret.status == 'success') {
  123. bootbox.alert(ret.message, function () {
  124. window.location.href = '{{url('user/orderList')}}';
  125. });
  126. } else {
  127. bootbox.alert(ret.message);
  128. }
  129. }
  130. });
  131. }
  132. </script>
  133. @endsection