Commit a0a783ea2fd6f4d7d18b8ad12c2430aa21aa0373
1 parent
ceaac519
平摊算法的优化
Showing
1 changed file
with
9 additions
and
6 deletions
pages/cart/cart2/cart2.js
@@ -699,7 +699,7 @@ Page({ | @@ -699,7 +699,7 @@ Page({ | ||
699 | 699 | ||
700 | //有活动,且优惠活动并没有限制使用优惠券,且有减价 | 700 | //有活动,且优惠活动并没有限制使用优惠券,且有减价 |
701 | //--看有没有减价-- | 701 | //--看有没有减价-- |
702 | - if(item_map.prom_price && item_map.price-item_map.prom_price){ | 702 | + if(item_map.prom_price>=0 && item_map.price-item_map.prom_price){ |
703 | if(cart_item.prom_pt_json){ | 703 | if(cart_item.prom_pt_json){ |
704 | cart_item.prom_pt_json.push({"prom_id":item_map.prom_id,"dis":(item_map.price-item_map.prom_price).toFixed(2),"ispt":0}) | 704 | cart_item.prom_pt_json.push({"prom_id":item_map.prom_id,"dis":(item_map.price-item_map.prom_price).toFixed(2),"ispt":0}) |
705 | }else{ | 705 | }else{ |
@@ -743,7 +743,7 @@ Page({ | @@ -743,7 +743,7 @@ Page({ | ||
743 | var m_item = item_map.goods[i]; | 743 | var m_item = item_map.goods[i]; |
744 | var m_all_amount = m_item.goods_price * m_item.goods_num - m_item.goods_price * m_item.goods_num * per; | 744 | var m_all_amount = m_item.goods_price * m_item.goods_num - m_item.goods_price * m_item.goods_num * per; |
745 | var account = Math.floor(100 * m_all_amount /m_item.goods_num) / 100; | 745 | var account = Math.floor(100 * m_all_amount /m_item.goods_num) / 100; |
746 | - if (account) { | 746 | + if (account>=0) { |
747 | item_map.goods[i].account = account; | 747 | item_map.goods[i].account = account; |
748 | account_all += account * m_item.goods_num; //累加总实收 | 748 | account_all += account * m_item.goods_num; //累加总实收 |
749 | } | 749 | } |
@@ -1540,6 +1540,7 @@ Page({ | @@ -1540,6 +1540,7 @@ Page({ | ||
1540 | //比例太小不平摊 | 1540 | //比例太小不平摊 |
1541 | if(per<0.001){ | 1541 | if(per<0.001){ |
1542 | goods.account_yu=th.data.formData.cut_price; | 1542 | goods.account_yu=th.data.formData.cut_price; |
1543 | + item.is_discount_amount=1; | ||
1543 | }else{ | 1544 | }else{ |
1544 | per=Math.floor(per*1000)/1000; | 1545 | per=Math.floor(per*1000)/1000; |
1545 | var all_amount=goods.goods_price*goods.goods_num-goods.goods_price*goods.goods_num*per; //商品总实收 | 1546 | var all_amount=goods.goods_price*goods.goods_num-goods.goods_price*goods.goods_num*per; //商品总实收 |
@@ -1547,6 +1548,7 @@ Page({ | @@ -1547,6 +1548,7 @@ Page({ | ||
1547 | var account_yu=account*goods.goods_num-(goods.goods_price*goods.goods_num-th.data.formData.cut_price); //算出余数 | 1548 | var account_yu=account*goods.goods_num-(goods.goods_price*goods.goods_num-th.data.formData.cut_price); //算出余数 |
1548 | goods.account=account; | 1549 | goods.account=account; |
1549 | goods.account_yu=parseFloat(account_yu.toFixed(2)); | 1550 | goods.account_yu=parseFloat(account_yu.toFixed(2)); |
1551 | + item.is_discount_amount=1; | ||
1550 | } | 1552 | } |
1551 | } | 1553 | } |
1552 | item.order_goods.push(goods); | 1554 | item.order_goods.push(goods); |
@@ -1672,9 +1674,10 @@ Page({ | @@ -1672,9 +1674,10 @@ Page({ | ||
1672 | }; | 1674 | }; |
1673 | 1675 | ||
1674 | //把优惠的平摊结果写进去 | 1676 | //把优惠的平摊结果写进去 |
1675 | - if(g_item.account){ | ||
1676 | - goods.account=g_item.account; | ||
1677 | - goods.account_yu=g_item.account_yu; | 1677 | + if(g_item.account>=0 || g_item.account_yu>0){ |
1678 | + if(g_item.account>=0) goods.account=g_item.account; | ||
1679 | + if(g_item.account_yu>=0) goods.account_yu=g_item.account_yu; | ||
1680 | + item.is_discount_amount=1; | ||
1678 | } | 1681 | } |
1679 | 1682 | ||
1680 | //--把券的钱,写入从表--- | 1683 | //--把券的钱,写入从表--- |
@@ -1756,7 +1759,7 @@ Page({ | @@ -1756,7 +1759,7 @@ Page({ | ||
1756 | 1759 | ||
1757 | if (pdata.length==0) return; | 1760 | if (pdata.length==0) return; |
1758 | var str = JSON.stringify(pdata); | 1761 | var str = JSON.stringify(pdata); |
1759 | - | 1762 | + |
1760 | wx.showLoading({title: "加载中"}); | 1763 | wx.showLoading({title: "加载中"}); |
1761 | wx.request({ | 1764 | wx.request({ |
1762 | url: oo.url + '/api/weshop/order/createWxdOrder', | 1765 | url: oo.url + '/api/weshop/order/createWxdOrder', |