change_order.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <style>
  2. .line_p{line-height:26px;font-size:13px;margin-top:5px;}
  3. .goods_refund_form th{border: 1px solid #efefef;line-height: 34px;}
  4. .goods_refund_form td{border: 1px solid #efefef;line-height: 34px;padding: 9px 15px;}
  5. .w100{width:100px;}
  6. .lh30{line-height:30px;font-size:13px;}
  7. .mrt8{margin-top:8px;}
  8. .blu{color:blue;}
  9. </style>
  10. <form class="form-horizontal form-validate" id="form1" action="{:U('order/change_order')}" method="post" enctype="multipart/form-data">
  11. <input type='hidden' name='id' value="<?php echo $item['order_id']?>" />
  12. <div class="modal-dialog">
  13. <div class="modal-content" style="width:1000px;">
  14. <div class="modal-header">
  15. <button data-dismiss="modal" class="close" type="button">×</button>
  16. </div>
  17. <div class="modal-body" style = "padding: 10px;" >
  18. <div style="display: flex">
  19. <div class="goods_refund_form" style="width:100%;display: flex;flex-direction: column;justify-content: center;align-items: flex-start;padding-left: 5px">
  20. <table style="border: 1px solid #efefef;width:100%;">
  21. <tr>
  22. <th style="width:30%;text-align:center;" colspan="2">商品</th>
  23. <th style="width:10%;text-align:center;">单价</th>
  24. <th style="width:10%;text-align:center;">数量</th>
  25. <th style="width:10%;text-align:center;">价格</th>
  26. <th style="width:10%;text-align:center;">改价最多可减</th>
  27. <th style="width:25%;text-align:center;">涨价或减价</th>
  28. </tr>
  29. <?php $order_goods_total = 0;?>
  30. <?php $member_youhui = 0; ?>
  31. <?php foreach($order_goods as $goods){?>
  32. <tr>
  33. <?php $member_youhui += round(($goods['oldprice'] - $goods['price'])*$goods['quantity'],2); ?>
  34. <input type="hidden" name="order_goods_id[]" value="<?php echo $goods['order_goods_id']?>"/>
  35. <td style="text-align: right;padding-right: 0;magrin-right: 10px;border-right: none;">
  36. <img src="<?php echo $goods['goods_img_url'];?>" style='width:52px;height:52px;border:1px solid #efefef; padding:1px;' >
  37. </td>
  38. <td style="padding-left:10px;border-left: none;"><?php echo $goods['name'];?></td>
  39. <td style="text-align:center;">
  40. ¥<?php echo $goods['oldprice'];?>
  41. </td>
  42. <td style="text-align:center;">
  43. <?php echo $goods['quantity'];?>
  44. </td>
  45. <td style="text-align:center;">
  46. ¥<span id="goods_total_<?php echo $goods['order_goods_id']?>"><?php echo round($goods['old_total'],2);?></span>
  47. </td>
  48. <td style="text-align:center;">
  49. ¥<span id="goods_max_total_<?php echo $goods['order_goods_id']?>"><?php echo round($goods['total']-$goods['fullreduction_money']-$goods['voucher_credit']-$goods['score_for_money'],2);?></span>
  50. </td>
  51. <td style="text-align:center;">
  52. <input style="width: 35px; height: 35px; border: 2px white; float: left;" type="button" value="-" onclick="reduction(this)" order_goods_id="<?php echo $goods['order_goods_id']?>"/>
  53. <input type="text" name="change_price[]" class="layui-input change_price" id="change_price_<?php echo $goods['order_goods_id']?>" value="" maxlength="10" style="width: 100px;float: left;" order_goods_id="<?php echo $goods['order_goods_id']?>" onchange="validationNumber(this, 2)"/>
  54. <input style="width: 35px; height: 35px; border: 2px white;float: left;" type="button" value="+" onclick="add(this)" order_goods_id="<?php echo $goods['order_goods_id']?>"/>
  55. </td>
  56. </tr>
  57. <?php
  58. $order_goods_total = round($order_goods_total + $goods['old_total'],2);
  59. ?>
  60. <?php } ?>
  61. <!--
  62. <tr>
  63. <td colspan="7" style="text-align:right;">
  64. <?php
  65. $change_price = 0;
  66. if($item['is_change_price'] == 1){
  67. $change_price = round($item['total'] - $item['old_price'],2);
  68. }
  69. $youhui_total = round($item['voucher_credit']+$item['fullreduction_money']+$item['score_for_money']+$member_youhui,2);
  70. $free_tongji = round($order_goods_total + $item['shipping_fare']-$item['voucher_credit']-$item['fullreduction_money'] - $item['score_for_money'] - $member_youhui + $change_price,2);
  71. $order_goods_total2 = $order_goods_total + $change_price ;
  72. ?>
  73. <p> <span class="price-inner">商品合计:</span><span style="font-weight: bold;color:red;">¥<font id="goods_total_price"><?php echo $order_goods_total2;?></font></span></p>
  74. </td>
  75. </tr>
  76. -->
  77. <tr>
  78. <td colspan="7" style="text-align:left;">
  79. <?php
  80. $change_price = 0;
  81. if($item['is_change_price'] == 1){
  82. $change_price = round($item['total'] - $item['old_price'],2);
  83. }
  84. $youhui_total = round($item['voucher_credit']+$item['fullreduction_money']+$item['score_for_money']+$member_youhui,2);
  85. $free_tongji = round($order_goods_total + $item['shipping_fare']-$item['voucher_credit']-$item['fullreduction_money'] - $item['score_for_money'] - $member_youhui + $change_price,2);
  86. ?>
  87. <input type="hidden" id="order_total" name="order_total" value="<?php echo $order_goods_total;?>"/>
  88. <input type="hidden" id="youhui_total" name="youhui_total" value="<?php echo $youhui_total;?>"/>
  89. <input type="hidden" id="shipping_fare" name="shipping_fare" value="<?php echo $item['shipping_fare'];?>"/>
  90. <input type="hidden" id="free_tongji" name="free_tongji" value="<?php echo $free_tongji;?>"/>
  91. <input type="hidden" id="member_youhui" name="member_youhui" value="<?php echo -$member_youhui;?>"/>
  92. <input type="hidden" id="order_change_price" name="order_change_price" value="<?php echo $change_price;?>"/>
  93. <p>只有在订单未付款时才支持改价,商品改价后价格不能小于 0 元,订单修改的价格不包含优惠信息,运费价格是 0 的时候商品免运费</p>
  94. <p>买家实付 = 原价 + 运费 + 涨价或减价 - 优惠&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  95. 买家实付:<?php echo round($order_goods_total,2);?> + <?php echo round($item['shipping_fare'],2);?> <span id="change_price"><?php if($change_price >= 0){echo ' + '.$change_price;}else{echo ' - '.(0-$change_price);}?></span>
  96. <?php if($youhui_total >= 0){echo ' - '.$youhui_total;}else{echo ' + '.(0-$youhui_total);}?> = <span id="free_total"><?php echo $free_tongji;?></span>
  97. </td>
  98. </tr>
  99. </table>
  100. </div>
  101. <div style="clear:both;"></div>
  102. </div>
  103. </div>
  104. <div class="modal-footer">
  105. <input type="hidden" id="real_refund_quantity" name="real_refund_quantity" value="0" />
  106. <button class="btn btn-primary" type="submit" id="ck_opgoodsrefund">确认改价</button>
  107. <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
  108. </div>
  109. </div>
  110. </form>
  111. <script>
  112. function validationNumber(e, num) {
  113. var regu = /^[\-0-9]+\.?[0-9]*$/;
  114. var order_goods_id = $(e).attr("order_goods_id");
  115. var goods_total = parseFloat($('#goods_max_total_'+order_goods_id).html());
  116. if (e.value != "") {
  117. if (!regu.test(e.value)) {
  118. e.value = 0;
  119. e.focus();
  120. } else {
  121. if (num == 0) {
  122. if (e.value.indexOf('.') > -1) {
  123. e.value = e.value.substring(0, e.value.length - e.value.split('.')[1].length + 2);
  124. e.focus();
  125. }
  126. }
  127. if (e.value.indexOf('.') > -1) {
  128. if (e.value.split('.')[1].length > num) {
  129. e.value = e.value.substring(0, e.value.length - e.value.split('.')[1].length + 2);
  130. e.focus();
  131. }
  132. }
  133. var price = operation(parseFloat(goods_total),parseFloat(e.value),2,'add');
  134. if(price < 0.1){
  135. layer.msg("改价后的商品实付价格不能低于0.1元",{icon: 1,time: 2000});
  136. e.value = 0;
  137. e.focus();
  138. }
  139. }
  140. }
  141. cal_total(order_goods_id);
  142. }
  143. function validationNumber_reduce(e, num) {
  144. var regu = /^[\-0-9]+\.?[0-9]*$/;
  145. var order_goods_id = $(e).attr("order_goods_id");
  146. var goods_total = parseFloat($('#goods_max_total_'+order_goods_id).html());
  147. if (e.val() != "") {
  148. if (!regu.test(e.val())) {
  149. e.val(0);
  150. e.focus();
  151. } else {
  152. if (num == 0) {
  153. if (e.val().indexOf('.') > -1) {
  154. e.val(e.val().substring(0, e.val().length - e.val().split('.')[1].length + 2));
  155. e.focus();
  156. }
  157. }
  158. if (e.val().indexOf('.') > -1) {
  159. if (e.val().split('.')[1].length > num) {
  160. e.val(e.val().substring(0, e.val().length - e.val().split('.')[1].length + 2));
  161. e.focus();
  162. }
  163. }
  164. var price = operation(parseFloat(goods_total),parseFloat(e.val()),2,'add');
  165. if(price < 0.1){
  166. layer.msg("改价后的商品实付价格不能低于0.1元",{icon: 1,time: 2000});
  167. e.val(0);
  168. e.focus();
  169. }
  170. }
  171. }
  172. cal_total(order_goods_id);
  173. }
  174. function reduction(obj){
  175. var change_price = $.trim($(obj).parent().find('.change_price').val());
  176. var order_goods_id = $(obj).attr("order_goods_id");
  177. if(change_price == ''){
  178. $(obj).parent().find('.change_price').val(-1);
  179. }else{
  180. var price = parseFloat(change_price)-1;
  181. $(obj).parent().find('.change_price').val(price.toFixed(2));
  182. }
  183. validationNumber_reduce($('#change_price_'+order_goods_id), 2);
  184. }
  185. function add(obj){
  186. var change_price = $.trim($(obj).parent().find('.change_price').val());
  187. var order_goods_id = $(obj).attr("order_goods_id");
  188. if(change_price == ''){
  189. $(obj).parent().find('.change_price').val(1);
  190. }else{
  191. var price = parseFloat(change_price)+1;
  192. $(obj).parent().find('.change_price').val(price.toFixed(2));
  193. }
  194. cal_total(order_goods_id);
  195. }
  196. //计算商品合计
  197. function cal_total(order_goods_id){
  198. var order_total = $('#order_total').val();
  199. var change_price = 0;
  200. $('.change_price').each(function(){
  201. var price = $.trim($(this).val());
  202. if(price != ''){
  203. change_price = parseFloat(change_price) + parseFloat(price);
  204. }
  205. })
  206. var order_change_price = $('#order_change_price').val();
  207. var free_tongji = parseFloat($('#free_tongji').val());
  208. var free_total = parseFloat(free_tongji) + parseFloat(change_price);
  209. var goods_total_price = parseFloat(free_tongji) + parseFloat(change_price);
  210. $('#goods_total_price').html(goods_total_price.toFixed(2));
  211. if(free_total <= 0){
  212. layer.msg("买家实付金额不能小于0",{icon: 1,time: 2000});
  213. $('#change_price_'+order_goods_id).val(0);
  214. cal_total(order_goods_id);
  215. return false;
  216. }else{
  217. change_price = change_price + parseFloat(order_change_price);
  218. change_price = change_price.toFixed(2);
  219. if(change_price > 0){
  220. $('#change_price').html('+ '+change_price);
  221. }else{
  222. $('#change_price').html('- '+(0-change_price));
  223. }
  224. $('#free_total').html(free_total.toFixed(2));
  225. }
  226. }
  227. /*
  228. * 判断obj是否为一个整数
  229. */
  230. function isInteger(obj) {
  231. return Math.floor(obj) === obj;
  232. }
  233. /*
  234. * 将一个浮点数转成整数,返回整数和倍数。如 3.14 >> 314,倍数是 100
  235. * @param floatNum {number} 小数
  236. * @return {object}
  237. * {times:100, num: 314}
  238. */
  239. function toInteger(floatNum) {
  240. var ret = {times: 1, num: 0}
  241. var isNegative = floatNum < 0
  242. if (isInteger(floatNum)) {
  243. ret.num = floatNum
  244. return ret
  245. }
  246. var strfi = floatNum + ''
  247. var dotPos = strfi.indexOf('.')
  248. var len = strfi.substr(dotPos+1).length
  249. var times = Math.pow(10, len)
  250. var intNum = parseInt(Math.abs(floatNum) * times + 0.5, 10)
  251. ret.times = times
  252. if (isNegative) {
  253. intNum = -intNum
  254. }
  255. ret.num = intNum
  256. return ret
  257. }
  258. /*
  259. * 核心方法,实现加减乘除运算,确保不丢失精度
  260. * 思路:把小数放大为整数(乘),进行算术运算,再缩小为小数(除)
  261. *
  262. * @param a {number} 运算数1
  263. * @param b {number} 运算数2
  264. * @param digits {number} 精度,保留的小数点数,比如 2, 即保留为两位小数
  265. * @param op {string} 运算类型,有加减乘除(add/subtract/multiply/divide)
  266. *
  267. */
  268. function operation(a, b, digits, op) {
  269. var o1 = toInteger(a)
  270. var o2 = toInteger(b)
  271. var n1 = o1.num
  272. var n2 = o2.num
  273. var t1 = o1.times
  274. var t2 = o2.times
  275. var max = t1 > t2 ? t1 : t2
  276. var result = null
  277. switch (op) {
  278. case 'add':
  279. if (t1 === t2) { // 两个小数位数相同
  280. result = n1 + n2
  281. } else if (t1 > t2) { // o1 小数位 大于 o2
  282. result = n1 + n2 * (t1 / t2)
  283. } else { // o1 小数位 小于 o2
  284. result = n1 * (t2 / t1) + n2
  285. }
  286. return result / max
  287. case 'subtract':
  288. if (t1 === t2) {
  289. result = n1 - n2
  290. } else if (t1 > t2) {
  291. result = n1 - n2 * (t1 / t2)
  292. } else {
  293. result = n1 * (t2 / t1) - n2
  294. }
  295. return result / max
  296. case 'multiply':
  297. result = (n1 * n2) / (t1 * t2)
  298. return result
  299. case 'divide':
  300. result = (n1 / n2) * (t2 / t1)
  301. return result
  302. }
  303. }
  304. </script>