diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index 8655d71..043f3ea 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -181,13 +181,12 @@ Page({ yhcx_buy_map:{}, //-- 订单促销判断积累 ---2024-2-20 - order_prom_map_ck: { - shop_price_all:0, //手店价的累计 - market_price_all:0, //市场价的累计 - goods_price_all:0, //实收价的累计 - no_ord_price:0, //要累计上不参与订单促销的金额 - goodsList:[], - }, + order_prom_map_ck: {}, + + //能不能使用订单促销 + can_use_ord_prom:{}, + show_ord_prom:{}, + join_ord_prom_goodslist:{} }, @@ -1043,6 +1042,23 @@ Page({ for (var i = 0; i < carr.length; i++) { let item1 = carr[i]; + + //如果有户有点击参与订单促销的话,那么可以参与订单促销的商品的活动都要清理成0 + if(this.data.can_use_ord_prom[item.pick_id]){ + //从订单促销的order_prom_map_ck数据结构中获取到可以参与的商品列表 + let gdlist=this.data.order_prom_map_ck[item.pick_id]?this.data.order_prom_map_ck[item.pick_id].goodsList:null; + if(gdlist && gdlist.length){ + //查找商品item1有没有在gdlist中,就要把商品的prom_type清理0 + let f_idx=gdlist.findIndex(function (ele) { + return ele.id == item1.id + }); + if (f_idx!=-1){ + carr[i].prom_type=0; + continue; //要跳过 + } + } + } + //如果不是活动的时候,不是代发商品的时候,不是赠品的时候,不是阶梯商品拆分的,不是组合购拆分的 if([1, 2, 4, 6, 8, 9].indexOf(item1.prom_type)== -1 && !item1.whsle_id && !item1.is_gift && !item1.is_ld_split && !item1.is_zh_split ){ @@ -3058,6 +3074,8 @@ Page({ var no_order_yh = 0; //-- 有些活动不能和订单优惠叠加的金额 -- var no_post_temp = 0; //-- 有些活动不能和包邮模板的金额 -- + var no_post_temp_shop_price = 0; //-- 有些活动不能和包邮模板的金额 --因为订单促销有手店价取价 + var no_post_temp_market_price = 0; //-- 有些活动不能和包邮模板的金额 --因为订单促销有市场价取价 if (th.data.using_quan[pickid] != null && th.data.using_quan[pickid] != undefined) quan_no = th.data.using_quan[pickid].coupon_no; @@ -3114,15 +3132,22 @@ Page({ var whsle_goods_price = 0; + var whsle_shop_price = 0; + var whsle_market_price = 0; + var no_zh_all_quan_num=0; //不是组合购商品的使用的优惠券综合 //--------循环计算总价----------- for (var jc = 0; jc < item.length; jc++) { + if (item[jc].prom_type == 0) { //如果item的prom_type==0,没有如果活动的时候 + th.get_order_prom_map_ck(item,pickid); + } + if (item[jc].whsle_id > 0) { whsle_goods_price += item[jc].goods_price * item[jc].goods_num; - }else if (item[jc].prom_type == 0) { //如果item的prom_type==0,没有如果活动的时候 - th.get_order_prom_map_ck(item); + whsle_shop_price += item[jc].shop_price * item[jc].goods_num; + whsle_market_price += item[jc].goods_market_price * item[jc].goods_num; } var is_no_zh = 0; @@ -3132,13 +3157,13 @@ Page({ if (item[jc].prom_type == 7 && th.data.zhhe_act_map && th.data.zhhe_act_map[item[jc].prom_id] && th.data.zhhe_act_map[item[jc].prom_id].is_orderyh) { is_no_zh = 1; - th.get_order_prom_map_ck(item); //有订单优惠叠加的时候,就要构建数据解救 + th.get_order_prom_map_ck(item[jc],pickid); //有订单优惠叠加的时候,就要构建数据解救 } //阶梯购的商品,且有订单优惠的叠加,is_orderyh就是优惠叠加,就要累积阶梯促销的金额 if (item[jc].prom_type == 10 && ladder_prom_goods && ladder_prom_goods[item[jc].prom_id] && th.data.ladder_map[item[jc].prom_id].is_useorderyh) { is_no_zh = 1; - th.get_order_prom_map_ck(item); //有订单优惠叠加的时候,就要构建数据解救 + th.get_order_prom_map_ck(item[jc],pickid); //有订单优惠叠加的时候,就要构建数据解救 } if (is_no_zh) { @@ -3161,16 +3186,23 @@ Page({ } //参与订单促销的时候 if(item[jc].is_order_yh && !item[jc].whsle_id && item[jc].prom_type!=7 && item[jc].prom_type!=10){ - th.get_order_prom_map_ck(item); //有订单优惠叠加的时候,就要构建数据解救 + th.get_order_prom_map_ck(item[jc],pickid); //有订单优惠叠加的时候,就要构建数据解救 } if(!item[jc].is_post_temp){ no_post_temp+=gd_price * item[jc].goods_num; + no_post_temp_shop_price+=item[jc].shop_price * item[jc].goods_num; + no_post_temp_market_price+=item[jc].goods_market_price * item[jc].goods_num; if(item[jc].quan_num) no_post_temp-=item[jc].quan_num; //券要把他补回去 } } + + //-- 商品是不是没有参与优惠促销的话 -- + th.ch_no_order_prom_map_ck(item[jc],pickid) } + + //判断是不是有组合购的金额 var f_o_price = o_price; //如果又优惠的钱,就要减价 @@ -3250,7 +3282,16 @@ Page({ } //判断订单促销的实收价的累计 - this.data.order_prom_map_ck.goods_price_all=ord_prom_condition; + if(!this.data.order_prom_map_ck[pickid]){ + this.data.order_prom_map_ck[pickid]={ + shop_price_all:0, //手店价的累计 + market_price_all:0, //市场价的累计 + goods_price_all:0, //实收价的累计 + no_ord_price:0, //要累计上不参与订单促销的金额 + goodsList:[], + } + } + this.data.order_prom_map_ck[pickid].goods_price_all=ord_prom_condition; //---判断是不是有订单优惠--- // await getApp().request.promiseGet("/api/weshop/promorder/getOrderPromotion", { // data: { store_id: os.stoid, orderAmount: parseFloat(ord_prom_condition).toFixed(2), user_id: getApp().globalData.user_id } @@ -3260,7 +3301,7 @@ Page({ // } // }) //获取当前时间段的进行中的订单促销 - ord_prom=await th.get_cur_ord_prom(); + ord_prom=await th.get_cur_ord_prom(pickid); //如果有使用优惠券,如何订单促销有控制使用优惠券不参与此活动的话 if(quan_price>0 && ord_prom && ord_prom.is_xz_yh ){ @@ -3320,17 +3361,16 @@ Page({ let user_addr = th.data.user_addr; let c_wuliu=parseFloat(o_price - quan_price - whsle_goods_price - no_post_temp).toFixed(2); + //-- 因为订单促销的取价规则,所以要判断一下各种情况 -- switch (ord_prom && ord_prom.discount_field){ case 1: - + c_wuliu=parseFloat(ord_prom.real_condition_price - whsle_shop_price - no_post_temp_shop_price).toFixed(2); break; case 2: - - + c_wuliu=parseFloat(ord_prom.real_condition_price - whsle_market_price - no_post_temp_market_price).toFixed(2); break; } - var req_d = { province: user_addr.province, city: user_addr.city, district: user_addr.district, wuliu: c_wuliu, store_id: os.stoid @@ -8732,31 +8772,69 @@ Page({ }, //---订单促销累计的数据结构的构建,购物车计算流程的那一部分 - get_order_prom_map_ck(item) { - this.data.order_prom_map_ck.shop_price_all += item.shop_price * item.goods_num; - this.data.order_prom_map_ck.market_price_all += item.goods_market_price * item.goods_num; + get_order_prom_map_ck(item,pickid) { + + var order_prom_map_ck= this.data.order_prom_map_ck; + if(!order_prom_map_ck[pickid]){ + order_prom_map_ck[pickid]={ + shop_price_all:0, //手店价的累计 + market_price_all:0, //市场价的累计 + goods_price_all:0, //实收价的累计 + no_ord_price:0, //要累计上不参与订单促销的金额 + goodsList:[], + } + } + + let pk_ord_map=order_prom_map_ck[pickid]; + pk_ord_map.shop_price_all += item.shop_price * item.goods_num; + pk_ord_map.market_price_all += item.goods_market_price * item.goods_num; + let ite = { id: item.id, goods_id: item.goods_id, goods_num: item.goods_num, prom_type: item.prom_type } - this.data.order_prom_map_ck.goodsList.push(item); + pk_ord_map.goodsList.push(ite); + + console.log('pk_ord_map'); + console.log(pk_ord_map); + + }, + + //寻找一下商品有没有参与订单促销 + ch_no_order_prom_map_ck(item,pickid){ + var order_prom_map_ck= this.data.order_prom_map_ck; + if(!order_prom_map_ck[pickid]){ + order_prom_map_ck[pickid]={ + shop_price_all:0, //手店价的累计 + market_price_all:0, //市场价的累计 + goods_price_all:0, //实收价的累计 + no_ord_price:0, //要累计上不参与订单促销的金额 + goodsList:[], + } + } + let pk_ord_map=order_prom_map_ck[pickid]; + + //快速查找item有没有在goodsList中 + var fg = pk_ord_map.goodsList.findIndex(function (ite){ + return ite.id==item.id + }) + if(fg==-1){ + pk_ord_map.no_ord_price= item.goods_price * item.goods_num; + } }, //重置订单促销判断累计 re_set_order_prom_map_ck() { - this.data.order_prom_map_ck = { - shop_price_all: 0, //手店价的累计 - market_price_all: 0, //市场价的累计 - goodsList: [], - } + this.data.order_prom_map_ck = {} }, //获取当前进行中订单促销,同时带入相应的金额判断订单促销是不是运行,同时订单促销的条件不是实收价判断的话,默认的时候,订单促销是不参与运算的 - async get_cur_ord_prom() { + async get_cur_ord_prom(pickid) { let ord_prom = null; - let order_prom_map_ck = this.data.order_prom_map_ck; + let order_prom_map_ck = this.data.order_prom_map_ck[pickid]; + if(!order_prom_map_ck) return null; //获取当前进行中的优惠促销 await getApp().request.promiseGet("/api/weshop/promorder/getPromOrder", { @@ -8774,6 +8852,11 @@ Page({ if (!ord_prom) return null; //用于计算订单促销的金额 let calculate_price=0; + + + let txt1='show_ord_prom['+pickid+']'; + let txt2='join_ord_prom_goodslist['+pickid+']'; + //-- 此时判断活动的金额满足与否 -- switch (ord_prom.discount_field) { //实收价的时候 @@ -8789,14 +8872,16 @@ Page({ } //要显示订单促销使用的按钮 this.setData({ - show_ord_prom: 1, - join_ord_prom_goodslist:order_prom_map_ck.goodsList //用于筛选商品的价格选手 + [txt1]: 1, + [txt2]:order_prom_map_ck.goodsList //用于筛选商品的价格选手 }); //要用户点击了同意使用订单优惠的按钮后,才允许使用订单优惠 if (!this.data.can_use_ord_prom) { return null; } - calculate_price=order_prom_map_ck.shop_price_all; + + //计算金额是参与订单促销的金额+不参与订单促销的金额 + calculate_price=order_prom_map_ck.shop_price_all+order_prom_map_ck.no_ord_price; break; //市场价的时候 @@ -8804,24 +8889,31 @@ Page({ if (ord_prom.money > order_prom_map_ck.market_price_all){ return null; } + + console.log('aaa'); + console.log(order_prom_map_ck.goodsList); + //要显示订单促销使用的按钮 this.setData({ - show_ord_prom: 2, - join_ord_prom_goodslist:order_prom_map_ck.goodsList //用于筛选商品的价格选手 + [txt1]: 2, + [txt2]:order_prom_map_ck.goodsList //用于筛选商品的价格选手 }); //要用户点击了同意使用订单优惠的按钮后,才允许使用订单优惠 if (!this.data.can_use_ord_prom) { return null; } - calculate_price = order_prom_map_ck.market_price_all; + //计算金额是参与订单促销的金额+不参与订单促销的金额 + calculate_price = order_prom_map_ck.market_price_all+order_prom_map_ck.no_ord_price; break; } - if (calculate_price > 0) { + let order_prom_amount=0; + //如果用户有点击按钮要参与订单促销的时候 + if (calculate_price > 0 && this.data.can_use_ord_prom[pickid]) { //-- 订单促销是按照实收价格进行计算的时候 -- switch (ord_prom['type']) { case 0: - order_m = Math.round(calculate_price * ord_prom['expression']) / 100;//满额打折 + let order_m = Math.round(calculate_price * ord_prom['expression']) / 100;//满额打折 order_prom_amount = (calculate_price - order_m).toFixed(2); break; case 1: @@ -8839,6 +8931,20 @@ Page({ } return ord_prom; + }, + + //设置能够参与订单促销 + set_can_use_ord_prom:function (e){ + let pickid=e.currentTarget.dataset.pd; + let txt='can_use_ord_prom['+pickid+']'; + let can_use=this.data.can_use_ord_prom[pickid]?this.data.can_use_ord_prom[pickid]:0; + this.setData({ + [txt]:!can_use + }) + + let carr=ut.deep_cp(th.data.cartlist_y); + //-- 重新计算一下价格 -- + this.get_cart_next(carr); } diff --git a/packageE/pages/cart/cart2/cart2.wxml b/packageE/pages/cart/cart2/cart2.wxml index a2d2d9e..e67d64d 100644 --- a/packageE/pages/cart/cart2/cart2.wxml +++ b/packageE/pages/cart/cart2/cart2.wxml @@ -107,7 +107,8 @@ - {{util.fm_join_ord_prom_price(items,join_ord_prom_goodslist,item.show_ord_prom,2)}} + + {{util.fm_join_ord_prom_price(items,join_ord_prom_goodslist[item.pickup_id],show_ord_prom[item.pickup_id],2)}} {{filters.toFix(items.goods_price,2)}}({{items.discount}}折) {{filters.toFix(items.goods_price,2)}} 佣金:{{filters.toFix(items.use_commission/items.goods_num,2)}}*{{items.goods_num}} @@ -346,6 +347,14 @@ + + + + + 参与订单促销 + + + diff --git a/packageE/pages/cart/cart2/filter.wxs b/packageE/pages/cart/cart2/filter.wxs index 2428e13..a2a8fd6 100644 --- a/packageE/pages/cart/cart2/filter.wxs +++ b/packageE/pages/cart/cart2/filter.wxs @@ -54,10 +54,22 @@ function check_is_last(index,goods_id){ //-- 用于筛选商品的价格显示 -- function fm_join_ord_prom_price(gd,join_gd_list,show_ord_prom,count){ var price=gd.goods_price; + + console.log('1111'); + console.log(gd.id); + //在join_gd_list中查找是否已经存在gd商品,靠购物车的id来判断 for(var i=0;i