From 1d3825f1e78d0a68414e3c954fa23ae7aed7472f Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Thu, 3 Mar 2022 14:16:06 +0800 Subject: [PATCH] 包邮模板, 超重运费计算的bug优化 --- pages/cart/cart2/cart2.js | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------- 1 file changed, 106 insertions(+), 41 deletions(-) diff --git a/pages/cart/cart2/cart2.js b/pages/cart/cart2/cart2.js index e4caecb..4e12a82 100644 --- a/pages/cart/cart2/cart2.js +++ b/pages/cart/cart2/cart2.js @@ -1378,6 +1378,15 @@ Page({ wx.showLoading({ title: "处理中." }) + + //是不是区域包邮 + th.data.is_area_by=0; + //当不是区域不包邮的时候,没有不包邮商品的时候 + th.data.free1=0; + th.data.cut_o_shipping_price=0; + th.data.cut_goods_piece=0; + th.data.cut_goods_weight=0; + var all_price = 0; //所有的商品总价 var all_shipping_m = 0; //所有的物流总价 var all_total_m = 0; //所有的订单应付总价 @@ -1391,6 +1400,9 @@ Page({ var umoney = th.data.userinfo.user_money - th.data.txmon - (th.data.userinfo.frozen_money ? th.data.userinfo.frozen_money : 0); var freight_free = ee.freight_free; //全场满多少包邮 + var free1=freight_free; + + var weight_free = ee.weight_free; //多少kg内包邮 var no_ex_id = ee.no_ex_id; var no_ex_good = null; @@ -1503,16 +1515,6 @@ Page({ } o_price += item[j].goods_price * item[j].goods_num; - //判断是否有设置限制重量包邮,先看商品有没有包邮 - if (item[j]['is_past'] !== 1 && item[j]['exp_sum_type'] == 2) { - if (goods_weight < 0) goods_weight = 0; - //累积商品重量 每种商品的重量 * 数量 - goods_weight += item[j]['weight'] * item[j]['goods_num']; - if (weight_free > 0) { - out_of_weight = (weight_free * 1000) - goods_weight; - } - } - } //判断是不是有组合购的金额 var f_o_price = o_price; @@ -1564,12 +1566,14 @@ Page({ th.data.is_no_past = 1; //不包邮标识符 + var no_ex_good_arr = null; //--有不包邮区域,且不免运费,全场的计算,要减到优惠金额 和券的金额-- 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)) { //如果有设置不包邮区域的时候 if (by_qc.region_list != "" && by_qc.region_list != null && by_qc.region_list != undefined) { if (th.check_by_area(by_qc.region_list)) { freight_free = 0; + th.data.is_area_by=1; //goods_weight = -1; //out_of_weight = 0; th.data.is_no_by[pickid] = 1; @@ -1580,11 +1584,61 @@ Page({ freight_free = 0; //goods_weight = -1; //out_of_weight = 0; - th.data.is_no_by[pickid] = 1; + //th.data.is_no_by[pickid] = 1; no_ex_good = by_qc.goods_list; + if (no_ex_good) no_ex_good_arr = no_ex_good.split(','); } } + + + + var is_in_no_ex_goods_arr=0; + var by_g_weight=0; + //--------循环计算商品总物流----------- + for (var jo = 0; jo < item.length; jo++) { + //----------------如果是选择了物流--------------------- + if (cart_item.exp_type == 0 && item[jo].is_free_shipping == 0 && th.data.user_addr != null){ + + //判断是否有设置限制重量包邮,先看商品有没有包邮 + if(!no_ex_good_arr || no_ex_good_arr.indexOf(item[jo].goods_id + '')== -1){ + if(!th.data.is_area_by) th.data.free1=free1; + //此时是 模板里面没有不包邮商品列表或者是 该商品没有再不包邮商品列表礼包 + if (item[jo]['is_past'] !== 1 && item[jo]['exp_sum_type'] == 2) { + if (goods_weight < 0) goods_weight = 0; + //累积商品重量 每种商品的重量 * 数量 + goods_weight += item[jo]['weight'] * item[jo]['goods_num']; + by_g_weight+=item[jo]['weight'] * item[jo]['goods_num']; + if (weight_free > 0) { + out_of_weight = (weight_free * 1000) - by_g_weight; + }else{ + out_of_weight= -by_g_weight; + } + } + } + //这个是在不包邮列表礼包 + else if(no_ex_good_arr.indexOf(item[jo].goods_id + '') > -1){ + is_in_no_ex_goods_arr=1; + if (item[jo]['is_past'] !== 1 && item[jo]['exp_sum_type'] == 2) { + if (goods_weight < 0) goods_weight = 0; + //累积商品重量 每种商品的重量 * 数量 + goods_weight += item[jo]['weight'] * item[jo]['goods_num']; + } + + } + } + } + + //当商品没有超出的时候 + if(out_of_weight>=0){ + out_of_weight= -by_g_weight; + }else{ + out_of_weight= -weight_free * 1000; + } + + //所有的商品都不在不包邮商品列表,freight_free为0的时候,以及不是区域包邮 + if(!is_in_no_ex_goods_arr && !freight_free && !th.data.is_area_by) freight_free=free1; + //--如果是物流,且选择了地址,就要开始显示包邮券,且包邮券也已经优惠了优惠活动的金额-- if (cart_item.exp_type == 0 && th.data.user_addr != null && !cart_item.is_xz_yh) { //看是不是有调用过包邮券 @@ -1669,23 +1723,20 @@ Page({ if (no_ex_good) { is_good_no_by = th.check_by_goods(no_ex_good, item[j].goods_id); } - //如果达到全场包邮的条件,同时,没有地区不包邮,或者商品不包邮 并且没有超出重量 + /*-- 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 ) { continue; - } - + }--*/ //--如果是包邮券使用的情况下,如果商品是包邮的,那么就不进行计算-- if (th.data.using_quan[pickid] && th.data.using_quan[pickid].isby == 1 && !is_good_no_by) { continue; } - var no_ex_good_arr = null; - if (no_ex_good) no_ex_good_arr = no_ex_good.split(','); - + //var no_ex_good_arr = null; + //if (no_ex_good) no_ex_good_arr = no_ex_good.split(','); //----------------如果是选择了物流--------------------- - 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)) { - + if (cart_item.exp_type == 0 && item[j].is_free_shipping == 0) { //如果地址不为空 if (th.data.user_addr != null) { switch (item[j]['exp_sum_type']) { @@ -1693,14 +1744,6 @@ Page({ //统一运费 o_shipping_price += item[j]['uniform_exp_sum']; break; - // case 2: - // if (goods_weight < 0) goods_weight = 0; - // //累积商品重量 每种商品的重量 * 数量 - // goods_weight += item[j]['weight'] * item[j]['goods_num']; - // if (weight_free > 0) { - // out_of_weight = (weight_free * 1000) - goods_weight; - // } - // break; case 3: if (goods_piece < 0) goods_piece = 0; //累积商品数量 @@ -1708,12 +1751,28 @@ Page({ break; } } - }else{ + + if(!no_ex_good_arr || no_ex_good_arr.indexOf(item[j].goods_id + '')== -1){ + switch (item[j]['exp_sum_type']) { + case 1: + //统一运费 + th.data.cut_o_shipping_price += item[j]['uniform_exp_sum']; + break; + case 3: + //累积商品数量 + th.data.cut_goods_piece += item[j]['goods_num']; + break; + } + } + + + }else{ + /*-- if(item[j]['exp_sum_type']==2 && out_of_weight!==0){ goods_weight = -1; out_of_weight = 0; - } + }--*/ } } @@ -1753,8 +1812,6 @@ Page({ o_condition = o_price_no_zh - quan_price; } - - var order_m = 0; //---判断是不是有订单优惠--- await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { @@ -3124,6 +3181,14 @@ Page({ var fw_price = 0, fp_price = 0; item = item.config; if (item == null) return o_shipping_price; + + //------超出重量---------- + if (out_of_weight < 0 && o_price >= freight_free && !th.data.is_no_by[pickid]) { + goods_weight=goods_weight+ out_of_weight; + if(goods_weight==0) goods_weight=-1; + } + + //------按重量---------- if (goods_weight >= 0 && item['money']) { fw_price = parseFloat(item['money']); @@ -3133,16 +3198,13 @@ Page({ fw_price = fw_price + n * parseFloat(item['add_money']); } } - //------超出重量---------- - if (out_of_weight < 0 && o_price >= freight_free && !th.data.is_no_by[pickid]) { - fw_price = parseFloat(item['money']); - var out_of_weight = Math.abs(out_of_weight); - if (out_of_weight > item['first_weight']) { - var fw = out_of_weight - item['first_weight']; - var n = Math.ceil(fw / item['second_weight']) - fw_price = fw_price + n * parseFloat(item['add_money']); - } - } + + if(th.data.free1 && freight_free<=0) freight_free=th.data.free1; + + + //当有包邮和不包邮混合在一起的时候,件数要重新计算 + if(freight_free>0 && o_price >= freight_free && goods_piece>0 && th.data.cut_goods_piece) + goods_piece=goods_piece-th.data.cut_goods_piece; //------按件数---------- if (goods_piece > 0 && item['piecemoney']) { fp_price = parseFloat(item['piecemoney']); @@ -3152,6 +3214,9 @@ Page({ fp_price = fp_price + m * parseFloat(item['add_piecemoney']); } } + //当有包邮和不包邮混合在一起的时候,统一运费要重新计算 + if(freight_free>0 && o_price >= freight_free && th.data.cut_o_shipping_price && price>0) price=price-th.data.cut_o_shipping_price; + var rspice = parseFloat(price + fw_price + fp_price); return rspice; }, -- libgit2 0.21.4