Commit 1d3825f1e78d0a68414e3c954fa23ae7aed7472f
1 parent
b03a4dc6
包邮模板, 超重运费计算的bug优化
Showing
1 changed file
with
106 additions
and
41 deletions
pages/cart/cart2/cart2.js
@@ -1378,6 +1378,15 @@ Page({ | @@ -1378,6 +1378,15 @@ Page({ | ||
1378 | wx.showLoading({ | 1378 | wx.showLoading({ |
1379 | title: "处理中." | 1379 | title: "处理中." |
1380 | }) | 1380 | }) |
1381 | + | ||
1382 | + //是不是区域包邮 | ||
1383 | + th.data.is_area_by=0; | ||
1384 | + //当不是区域不包邮的时候,没有不包邮商品的时候 | ||
1385 | + th.data.free1=0; | ||
1386 | + th.data.cut_o_shipping_price=0; | ||
1387 | + th.data.cut_goods_piece=0; | ||
1388 | + th.data.cut_goods_weight=0; | ||
1389 | + | ||
1381 | var all_price = 0; //所有的商品总价 | 1390 | var all_price = 0; //所有的商品总价 |
1382 | var all_shipping_m = 0; //所有的物流总价 | 1391 | var all_shipping_m = 0; //所有的物流总价 |
1383 | var all_total_m = 0; //所有的订单应付总价 | 1392 | var all_total_m = 0; //所有的订单应付总价 |
@@ -1391,6 +1400,9 @@ Page({ | @@ -1391,6 +1400,9 @@ Page({ | ||
1391 | 1400 | ||
1392 | var umoney = th.data.userinfo.user_money - th.data.txmon - (th.data.userinfo.frozen_money ? th.data.userinfo.frozen_money : 0); | 1401 | var umoney = th.data.userinfo.user_money - th.data.txmon - (th.data.userinfo.frozen_money ? th.data.userinfo.frozen_money : 0); |
1393 | var freight_free = ee.freight_free; //全场满多少包邮 | 1402 | var freight_free = ee.freight_free; //全场满多少包邮 |
1403 | + var free1=freight_free; | ||
1404 | + | ||
1405 | + | ||
1394 | var weight_free = ee.weight_free; //多少kg内包邮 | 1406 | var weight_free = ee.weight_free; //多少kg内包邮 |
1395 | var no_ex_id = ee.no_ex_id; | 1407 | var no_ex_id = ee.no_ex_id; |
1396 | var no_ex_good = null; | 1408 | var no_ex_good = null; |
@@ -1503,16 +1515,6 @@ Page({ | @@ -1503,16 +1515,6 @@ Page({ | ||
1503 | } | 1515 | } |
1504 | o_price += item[j].goods_price * item[j].goods_num; | 1516 | o_price += item[j].goods_price * item[j].goods_num; |
1505 | 1517 | ||
1506 | - //判断是否有设置限制重量包邮,先看商品有没有包邮 | ||
1507 | - if (item[j]['is_past'] !== 1 && item[j]['exp_sum_type'] == 2) { | ||
1508 | - if (goods_weight < 0) goods_weight = 0; | ||
1509 | - //累积商品重量 每种商品的重量 * 数量 | ||
1510 | - goods_weight += item[j]['weight'] * item[j]['goods_num']; | ||
1511 | - if (weight_free > 0) { | ||
1512 | - out_of_weight = (weight_free * 1000) - goods_weight; | ||
1513 | - } | ||
1514 | - } | ||
1515 | - | ||
1516 | } | 1518 | } |
1517 | //判断是不是有组合购的金额 | 1519 | //判断是不是有组合购的金额 |
1518 | var f_o_price = o_price; | 1520 | var f_o_price = o_price; |
@@ -1564,12 +1566,14 @@ Page({ | @@ -1564,12 +1566,14 @@ Page({ | ||
1564 | 1566 | ||
1565 | th.data.is_no_past = 1; //不包邮标识符 | 1567 | th.data.is_no_past = 1; //不包邮标识符 |
1566 | 1568 | ||
1569 | + var no_ex_good_arr = null; | ||
1567 | //--有不包邮区域,且不免运费,全场的计算,要减到优惠金额 和券的金额-- | 1570 | //--有不包邮区域,且不免运费,全场的计算,要减到优惠金额 和券的金额-- |
1568 | if (no_ex_id && freight_free > 0 && (o_price - quan_price) >= freight_free && cart_item.exp_type == 0 && (by_qc.region_list || by_qc.goods_list)) { | 1571 | if (no_ex_id && freight_free > 0 && (o_price - quan_price) >= freight_free && cart_item.exp_type == 0 && (by_qc.region_list || by_qc.goods_list)) { |
1569 | //如果有设置不包邮区域的时候 | 1572 | //如果有设置不包邮区域的时候 |
1570 | if (by_qc.region_list != "" && by_qc.region_list != null && by_qc.region_list != undefined) { | 1573 | if (by_qc.region_list != "" && by_qc.region_list != null && by_qc.region_list != undefined) { |
1571 | if (th.check_by_area(by_qc.region_list)) { | 1574 | if (th.check_by_area(by_qc.region_list)) { |
1572 | freight_free = 0; | 1575 | freight_free = 0; |
1576 | + th.data.is_area_by=1; | ||
1573 | //goods_weight = -1; | 1577 | //goods_weight = -1; |
1574 | //out_of_weight = 0; | 1578 | //out_of_weight = 0; |
1575 | th.data.is_no_by[pickid] = 1; | 1579 | th.data.is_no_by[pickid] = 1; |
@@ -1580,11 +1584,61 @@ Page({ | @@ -1580,11 +1584,61 @@ Page({ | ||
1580 | freight_free = 0; | 1584 | freight_free = 0; |
1581 | //goods_weight = -1; | 1585 | //goods_weight = -1; |
1582 | //out_of_weight = 0; | 1586 | //out_of_weight = 0; |
1583 | - th.data.is_no_by[pickid] = 1; | 1587 | + //th.data.is_no_by[pickid] = 1; |
1584 | no_ex_good = by_qc.goods_list; | 1588 | no_ex_good = by_qc.goods_list; |
1589 | + if (no_ex_good) no_ex_good_arr = no_ex_good.split(','); | ||
1585 | } | 1590 | } |
1586 | } | 1591 | } |
1587 | 1592 | ||
1593 | + | ||
1594 | + | ||
1595 | + | ||
1596 | + var is_in_no_ex_goods_arr=0; | ||
1597 | + var by_g_weight=0; | ||
1598 | + //--------循环计算商品总物流----------- | ||
1599 | + for (var jo = 0; jo < item.length; jo++) { | ||
1600 | + //----------------如果是选择了物流--------------------- | ||
1601 | + if (cart_item.exp_type == 0 && item[jo].is_free_shipping == 0 && th.data.user_addr != null){ | ||
1602 | + | ||
1603 | + //判断是否有设置限制重量包邮,先看商品有没有包邮 | ||
1604 | + if(!no_ex_good_arr || no_ex_good_arr.indexOf(item[jo].goods_id + '')== -1){ | ||
1605 | + if(!th.data.is_area_by) th.data.free1=free1; | ||
1606 | + //此时是 模板里面没有不包邮商品列表或者是 该商品没有再不包邮商品列表礼包 | ||
1607 | + if (item[jo]['is_past'] !== 1 && item[jo]['exp_sum_type'] == 2) { | ||
1608 | + if (goods_weight < 0) goods_weight = 0; | ||
1609 | + //累积商品重量 每种商品的重量 * 数量 | ||
1610 | + goods_weight += item[jo]['weight'] * item[jo]['goods_num']; | ||
1611 | + by_g_weight+=item[jo]['weight'] * item[jo]['goods_num']; | ||
1612 | + if (weight_free > 0) { | ||
1613 | + out_of_weight = (weight_free * 1000) - by_g_weight; | ||
1614 | + }else{ | ||
1615 | + out_of_weight= -by_g_weight; | ||
1616 | + } | ||
1617 | + } | ||
1618 | + } | ||
1619 | + //这个是在不包邮列表礼包 | ||
1620 | + else if(no_ex_good_arr.indexOf(item[jo].goods_id + '') > -1){ | ||
1621 | + is_in_no_ex_goods_arr=1; | ||
1622 | + if (item[jo]['is_past'] !== 1 && item[jo]['exp_sum_type'] == 2) { | ||
1623 | + if (goods_weight < 0) goods_weight = 0; | ||
1624 | + //累积商品重量 每种商品的重量 * 数量 | ||
1625 | + goods_weight += item[jo]['weight'] * item[jo]['goods_num']; | ||
1626 | + } | ||
1627 | + | ||
1628 | + } | ||
1629 | + } | ||
1630 | + } | ||
1631 | + | ||
1632 | + //当商品没有超出的时候 | ||
1633 | + if(out_of_weight>=0){ | ||
1634 | + out_of_weight= -by_g_weight; | ||
1635 | + }else{ | ||
1636 | + out_of_weight= -weight_free * 1000; | ||
1637 | + } | ||
1638 | + | ||
1639 | + //所有的商品都不在不包邮商品列表,freight_free为0的时候,以及不是区域包邮 | ||
1640 | + if(!is_in_no_ex_goods_arr && !freight_free && !th.data.is_area_by) freight_free=free1; | ||
1641 | + | ||
1588 | //--如果是物流,且选择了地址,就要开始显示包邮券,且包邮券也已经优惠了优惠活动的金额-- | 1642 | //--如果是物流,且选择了地址,就要开始显示包邮券,且包邮券也已经优惠了优惠活动的金额-- |
1589 | if (cart_item.exp_type == 0 && th.data.user_addr != null && !cart_item.is_xz_yh) { | 1643 | if (cart_item.exp_type == 0 && th.data.user_addr != null && !cart_item.is_xz_yh) { |
1590 | //看是不是有调用过包邮券 | 1644 | //看是不是有调用过包邮券 |
@@ -1669,23 +1723,20 @@ Page({ | @@ -1669,23 +1723,20 @@ Page({ | ||
1669 | if (no_ex_good) { | 1723 | if (no_ex_good) { |
1670 | is_good_no_by = th.check_by_goods(no_ex_good, item[j].goods_id); | 1724 | is_good_no_by = th.check_by_goods(no_ex_good, item[j].goods_id); |
1671 | } | 1725 | } |
1672 | - | ||
1673 | //如果达到全场包邮的条件,同时,没有地区不包邮,或者商品不包邮 并且没有超出重量 | 1726 | //如果达到全场包邮的条件,同时,没有地区不包邮,或者商品不包邮 并且没有超出重量 |
1727 | + /*-- | ||
1674 | if (o_price - quan_price >= freight_free && freight_free > 0 && !is_good_no_by && th.data.is_no_by[pickid] != 1 && out_of_weight >=0 ) { | 1728 | if (o_price - quan_price >= freight_free && freight_free > 0 && !is_good_no_by && th.data.is_no_by[pickid] != 1 && out_of_weight >=0 ) { |
1675 | continue; | 1729 | continue; |
1676 | - } | ||
1677 | - | 1730 | + }--*/ |
1678 | //--如果是包邮券使用的情况下,如果商品是包邮的,那么就不进行计算-- | 1731 | //--如果是包邮券使用的情况下,如果商品是包邮的,那么就不进行计算-- |
1679 | if (th.data.using_quan[pickid] && th.data.using_quan[pickid].isby == 1 && !is_good_no_by) { | 1732 | if (th.data.using_quan[pickid] && th.data.using_quan[pickid].isby == 1 && !is_good_no_by) { |
1680 | continue; | 1733 | continue; |
1681 | } | 1734 | } |
1682 | 1735 | ||
1683 | - var no_ex_good_arr = null; | ||
1684 | - if (no_ex_good) no_ex_good_arr = no_ex_good.split(','); | ||
1685 | - | 1736 | + //var no_ex_good_arr = null; |
1737 | + //if (no_ex_good) no_ex_good_arr = no_ex_good.split(','); | ||
1686 | //----------------如果是选择了物流--------------------- | 1738 | //----------------如果是选择了物流--------------------- |
1687 | - if (cart_item.exp_type == 0 && item[j].is_free_shipping == 0 && (!no_ex_good_arr || no_ex_good_arr.indexOf(item[j].goods_id + '') > -1)) { | ||
1688 | - | 1739 | + if (cart_item.exp_type == 0 && item[j].is_free_shipping == 0) { |
1689 | //如果地址不为空 | 1740 | //如果地址不为空 |
1690 | if (th.data.user_addr != null) { | 1741 | if (th.data.user_addr != null) { |
1691 | switch (item[j]['exp_sum_type']) { | 1742 | switch (item[j]['exp_sum_type']) { |
@@ -1693,14 +1744,6 @@ Page({ | @@ -1693,14 +1744,6 @@ Page({ | ||
1693 | //统一运费 | 1744 | //统一运费 |
1694 | o_shipping_price += item[j]['uniform_exp_sum']; | 1745 | o_shipping_price += item[j]['uniform_exp_sum']; |
1695 | break; | 1746 | break; |
1696 | - // case 2: | ||
1697 | - // if (goods_weight < 0) goods_weight = 0; | ||
1698 | - // //累积商品重量 每种商品的重量 * 数量 | ||
1699 | - // goods_weight += item[j]['weight'] * item[j]['goods_num']; | ||
1700 | - // if (weight_free > 0) { | ||
1701 | - // out_of_weight = (weight_free * 1000) - goods_weight; | ||
1702 | - // } | ||
1703 | - // break; | ||
1704 | case 3: | 1747 | case 3: |
1705 | if (goods_piece < 0) goods_piece = 0; | 1748 | if (goods_piece < 0) goods_piece = 0; |
1706 | //累积商品数量 | 1749 | //累积商品数量 |
@@ -1708,12 +1751,28 @@ Page({ | @@ -1708,12 +1751,28 @@ Page({ | ||
1708 | break; | 1751 | break; |
1709 | } | 1752 | } |
1710 | } | 1753 | } |
1711 | - }else{ | ||
1712 | 1754 | ||
1755 | + | ||
1756 | + if(!no_ex_good_arr || no_ex_good_arr.indexOf(item[j].goods_id + '')== -1){ | ||
1757 | + switch (item[j]['exp_sum_type']) { | ||
1758 | + case 1: | ||
1759 | + //统一运费 | ||
1760 | + th.data.cut_o_shipping_price += item[j]['uniform_exp_sum']; | ||
1761 | + break; | ||
1762 | + case 3: | ||
1763 | + //累积商品数量 | ||
1764 | + th.data.cut_goods_piece += item[j]['goods_num']; | ||
1765 | + break; | ||
1766 | + } | ||
1767 | + } | ||
1768 | + | ||
1769 | + | ||
1770 | + }else{ | ||
1771 | + /*-- | ||
1713 | if(item[j]['exp_sum_type']==2 && out_of_weight!==0){ | 1772 | if(item[j]['exp_sum_type']==2 && out_of_weight!==0){ |
1714 | goods_weight = -1; | 1773 | goods_weight = -1; |
1715 | out_of_weight = 0; | 1774 | out_of_weight = 0; |
1716 | - } | 1775 | + }--*/ |
1717 | } | 1776 | } |
1718 | } | 1777 | } |
1719 | 1778 | ||
@@ -1753,8 +1812,6 @@ Page({ | @@ -1753,8 +1812,6 @@ Page({ | ||
1753 | o_condition = o_price_no_zh - quan_price; | 1812 | o_condition = o_price_no_zh - quan_price; |
1754 | } | 1813 | } |
1755 | 1814 | ||
1756 | - | ||
1757 | - | ||
1758 | var order_m = 0; | 1815 | var order_m = 0; |
1759 | //---判断是不是有订单优惠--- | 1816 | //---判断是不是有订单优惠--- |
1760 | await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { | 1817 | await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { |
@@ -3124,6 +3181,14 @@ Page({ | @@ -3124,6 +3181,14 @@ Page({ | ||
3124 | var fw_price = 0, fp_price = 0; | 3181 | var fw_price = 0, fp_price = 0; |
3125 | item = item.config; | 3182 | item = item.config; |
3126 | if (item == null) return o_shipping_price; | 3183 | if (item == null) return o_shipping_price; |
3184 | + | ||
3185 | + //------超出重量---------- | ||
3186 | + if (out_of_weight < 0 && o_price >= freight_free && !th.data.is_no_by[pickid]) { | ||
3187 | + goods_weight=goods_weight+ out_of_weight; | ||
3188 | + if(goods_weight==0) goods_weight=-1; | ||
3189 | + } | ||
3190 | + | ||
3191 | + | ||
3127 | //------按重量---------- | 3192 | //------按重量---------- |
3128 | if (goods_weight >= 0 && item['money']) { | 3193 | if (goods_weight >= 0 && item['money']) { |
3129 | fw_price = parseFloat(item['money']); | 3194 | fw_price = parseFloat(item['money']); |
@@ -3133,16 +3198,13 @@ Page({ | @@ -3133,16 +3198,13 @@ Page({ | ||
3133 | fw_price = fw_price + n * parseFloat(item['add_money']); | 3198 | fw_price = fw_price + n * parseFloat(item['add_money']); |
3134 | } | 3199 | } |
3135 | } | 3200 | } |
3136 | - //------超出重量---------- | ||
3137 | - if (out_of_weight < 0 && o_price >= freight_free && !th.data.is_no_by[pickid]) { | ||
3138 | - fw_price = parseFloat(item['money']); | ||
3139 | - var out_of_weight = Math.abs(out_of_weight); | ||
3140 | - if (out_of_weight > item['first_weight']) { | ||
3141 | - var fw = out_of_weight - item['first_weight']; | ||
3142 | - var n = Math.ceil(fw / item['second_weight']) | ||
3143 | - fw_price = fw_price + n * parseFloat(item['add_money']); | ||
3144 | - } | ||
3145 | - } | 3201 | + |
3202 | + if(th.data.free1 && freight_free<=0) freight_free=th.data.free1; | ||
3203 | + | ||
3204 | + | ||
3205 | + //当有包邮和不包邮混合在一起的时候,件数要重新计算 | ||
3206 | + if(freight_free>0 && o_price >= freight_free && goods_piece>0 && th.data.cut_goods_piece) | ||
3207 | + goods_piece=goods_piece-th.data.cut_goods_piece; | ||
3146 | //------按件数---------- | 3208 | //------按件数---------- |
3147 | if (goods_piece > 0 && item['piecemoney']) { | 3209 | if (goods_piece > 0 && item['piecemoney']) { |
3148 | fp_price = parseFloat(item['piecemoney']); | 3210 | fp_price = parseFloat(item['piecemoney']); |
@@ -3152,6 +3214,9 @@ Page({ | @@ -3152,6 +3214,9 @@ Page({ | ||
3152 | fp_price = fp_price + m * parseFloat(item['add_piecemoney']); | 3214 | fp_price = fp_price + m * parseFloat(item['add_piecemoney']); |
3153 | } | 3215 | } |
3154 | } | 3216 | } |
3217 | + //当有包邮和不包邮混合在一起的时候,统一运费要重新计算 | ||
3218 | + if(freight_free>0 && o_price >= freight_free && th.data.cut_o_shipping_price && price>0) price=price-th.data.cut_o_shipping_price; | ||
3219 | + | ||
3155 | var rspice = parseFloat(price + fw_price + fp_price); | 3220 | var rspice = parseFloat(price + fw_price + fp_price); |
3156 | return rspice; | 3221 | return rspice; |
3157 | }, | 3222 | }, |