diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index c023208..8655d71 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -178,7 +178,17 @@ Page({ yhcx_act_map: {}, //优惠促销购买次数 - yhcx_buy_map:{} + 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:[], + }, + }, @@ -1463,8 +1473,6 @@ Page({ } else { - - item1.act = th.data.zhhe_act_map[item1.prom_id]; } } @@ -2980,6 +2988,9 @@ Page({ } } + //重置订单促销判断累计 + this.re_set_order_prom_map_ck(); + for (var i in c_arr) { var cart_item = c_arr[i]; cart_item.prom_pt_json=[]; @@ -3009,7 +3020,7 @@ Page({ //-- 经纬度不循环调用接口 -- var lon = 0; var lat = 0; - //---循环购物车--- + //---循环购物车,按照门店订单进行循环--- for (var i in c_arr) { //因为搭配购买也是再这里计算,搭配购的is_b_now==1 if (th.data.is_b_now == 0) { @@ -3053,9 +3064,7 @@ Page({ //普通券的时候 if (quan_no && th.data.using_quan[pickid].isby != 1) { - var IsUserWare=1; - //---获取优惠券优惠--- await getApp().request.promiseGet("/api/weshop/couponList/getUseCouponPrice", { data: { @@ -3076,13 +3085,10 @@ Page({ quan_price=0; break; } - } - } }) - if(!IsUserWare){ wx.showToast({ @@ -3115,6 +3121,8 @@ Page({ 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); } var is_no_zh = 0; @@ -3124,11 +3132,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); //有订单优惠叠加的时候,就要构建数据解救 } //阶梯购的商品,且有订单优惠的叠加,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); //有订单优惠叠加的时候,就要构建数据解救 } if (is_no_zh) { @@ -3144,13 +3154,16 @@ Page({ var gd_price=item[jc].goods_price; if(item[jc].account_fir) gd_price=item[jc].account_fir; - - //组合购和阶梯购是订单优惠是另外算的 + //组合购和阶梯购是订单优惠是另外算的,不参与订单促销的时候 if(!item[jc].is_order_yh && !item[jc].whsle_id && item[jc].prom_type!=7 && item[jc].prom_type!=10){ no_order_yh+=gd_price * item[jc].goods_num; if(item[jc].quan_num) no_order_yh-=item[jc].quan_num; //券要把他补回去 - } + //参与订单促销的时候 + 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); //有订单优惠叠加的时候,就要构建数据解救 + } + if(!item[jc].is_post_temp){ no_post_temp+=gd_price * item[jc].goods_num; if(item[jc].quan_num) no_post_temp-=item[jc].quan_num; //券要把他补回去 @@ -3236,21 +3249,24 @@ Page({ ord_prom_condition=o_price - quan_price - whsle_goods_price - no_order_yh; } + //判断订单促销的实收价的累计 + this.data.order_prom_map_ck.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 } - }).then(res => { - if (res.data.code == 0) { - ord_prom = res.data.data; - } - }) + // 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 } + // }).then(res => { + // if (res.data.code == 0) { + // ord_prom = res.data.data; + // } + // }) + //获取当前时间段的进行中的订单促销 + ord_prom=await th.get_cur_ord_prom(); //如果有使用优惠券,如何订单促销有控制使用优惠券不参与此活动的话 if(quan_price>0 && ord_prom && ord_prom.is_xz_yh ){ ord_prom=null; } - //--如果是物流,且选择了地址,就要开始显示包邮券,且包邮券也已经优惠了优惠活动的金额-- if (cart_item.exp_type == 0 && th.data.user_addr != null && !cart_item.is_xz_yh) { @@ -3300,10 +3316,24 @@ Page({ //-- 如果没有订单优惠,或者订单优惠中有勾选包邮模板 -- if (!ord_prom || ord_prom.is_post_temp) { - var user_addr = th.data.user_addr; + + 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: + + break; + case 2: + + + break; + } + + var req_d = { province: user_addr.province, city: user_addr.city, district: user_addr.district, - wuliu: parseFloat(o_price - quan_price - whsle_goods_price - no_post_temp).toFixed(2), store_id: os.stoid + wuliu: c_wuliu, store_id: os.stoid } await getApp().request.promisePost("/api/weshop/order/areaFreight", { is_json: 1, data: req_d @@ -3313,7 +3343,6 @@ Page({ } } - //如果是包邮券的时候,要看看券的情况 if (quan_no && th.data.using_quan[pickid].isby == 1) { var quan = th.data.using_quan[pickid]; @@ -3504,23 +3533,28 @@ Page({ } var order_m = 0; - //么有使用券,或者活动没有限制使用优惠券 if (ord_prom && (quan_price <= 0 || !ord_prom.is_xz_yh)) { order_prom_id = ord_prom['id']; - switch (ord_prom['type']) { - case 0: - order_m = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折 - order_prom_amount = (o_condition - order_m).toFixed(2); - break; - case 1: - //order_m = o_condition - ord_prom['expression'];//满额优惠金额 - var bs = 1; - if (ord_prom.is_bz) { - bs = Math.floor(o_condition / ord_prom.money); - } - order_prom_amount = ord_prom['expression']; - break; + + if(ord_prom.discount_field>0){ + + }else{ + //-- 订单促销是按照实收价格进行计算的时候 -- + switch (ord_prom['type']) { + case 0: + order_m = Math.round(o_condition * ord_prom['expression']) / 100;//满额打折 + order_prom_amount = (o_condition - order_m).toFixed(2); + break; + case 1: + //order_m = o_condition - ord_prom['expression'];//满额优惠金额 + var bs = 1; + if (ord_prom.is_bz) { + bs = Math.floor(o_condition / ord_prom.money); + } + order_prom_amount = ord_prom['expression']; + break; + } } } @@ -8689,16 +8723,125 @@ Page({ //原始数据要有深拷贝不能有地址的牵连 th.data.cartlist_y = JSON.parse(JSON.stringify(goods)) - - //重新调用cart_next,进行下一步计算 wx.showLoading({ title: "处理中.", }) this.get_cart_next(null, 1, {prom_type: 0, prom_id: 0}); + }, + + //---订单促销累计的数据结构的构建,购物车计算流程的那一部分 + 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; + 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); + }, + + //重置订单促销判断累计 + re_set_order_prom_map_ck() { + this.data.order_prom_map_ck = { + shop_price_all: 0, //手店价的累计 + market_price_all: 0, //市场价的累计 + goodsList: [], + } + }, + + //获取当前进行中订单促销,同时带入相应的金额判断订单促销是不是运行,同时订单促销的条件不是实收价判断的话,默认的时候,订单促销是不参与运算的 + async get_cur_ord_prom() { + let ord_prom = null; + let order_prom_map_ck = this.data.order_prom_map_ck; + + //获取当前进行中的优惠促销 + await getApp().request.promiseGet("/api/weshop/promorder/getPromOrder", { + data: { + store_id: os.stoid, + orderAmount: -1, //-1为不判断金额条件 + user_id: getApp().globalData.user_id + } + }).then(res => { + if (res.data.code == 0) { + ord_prom = res.data.data; + } + }) + + if (!ord_prom) return null; + //用于计算订单促销的金额 + let calculate_price=0; + //-- 此时判断活动的金额满足与否 -- + switch (ord_prom.discount_field) { + //实收价的时候 + case 0: + if (ord_prom.money > order_prom_map_ck.goods_price_all){ + return null; + } + break; + //手店价的时候 + case 1: + if (ord_prom.money > order_prom_map_ck.shop_price_all){ + return null; + } + //要显示订单促销使用的按钮 + this.setData({ + show_ord_prom: 1, + join_ord_prom_goodslist:order_prom_map_ck.goodsList //用于筛选商品的价格选手 + }); + //要用户点击了同意使用订单优惠的按钮后,才允许使用订单优惠 + if (!this.data.can_use_ord_prom) { + return null; + } + calculate_price=order_prom_map_ck.shop_price_all; + + break; + //市场价的时候 + case 2: + if (ord_prom.money > order_prom_map_ck.market_price_all){ + return null; + } + //要显示订单促销使用的按钮 + this.setData({ + show_ord_prom: 2, + join_ord_prom_goodslist:order_prom_map_ck.goodsList //用于筛选商品的价格选手 + }); + //要用户点击了同意使用订单优惠的按钮后,才允许使用订单优惠 + if (!this.data.can_use_ord_prom) { + return null; + } + calculate_price = order_prom_map_ck.market_price_all; + break; + } + + if (calculate_price > 0) { + //-- 订单促销是按照实收价格进行计算的时候 -- + switch (ord_prom['type']) { + case 0: + order_m = Math.round(calculate_price * ord_prom['expression']) / 100;//满额打折 + order_prom_amount = (calculate_price - order_m).toFixed(2); + break; + case 1: + //order_m = o_condition - ord_prom['expression'];//满额优惠金额 + var bs = 1; + if (ord_prom.is_bz) { + bs = Math.floor(calculate_price / ord_prom.money); + } + order_prom_amount = ord_prom['expression']; + break; + } + //保存到订单促销中,订单促销的金额 + ord_prom.real_order_prom_amount = order_prom_amount; + ord_prom.real_condition_price = calculate_price; + } + return ord_prom; } + + }); diff --git a/packageE/pages/cart/cart2/cart2.wxml b/packageE/pages/cart/cart2/cart2.wxml index 4e3b855..a2d2d9e 100644 --- a/packageE/pages/cart/cart2/cart2.wxml +++ b/packageE/pages/cart/cart2/cart2.wxml @@ -107,7 +107,8 @@ - {{filters.toFix(items.goods_price,2)}}({{items.discount}}折) + {{util.fm_join_ord_prom_price(items,join_ord_prom_goodslist,item.show_ord_prom,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}} x{{items.goods_num}} diff --git a/packageE/pages/cart/cart2/filter.wxs b/packageE/pages/cart/cart2/filter.wxs index d32491d..2428e13 100644 --- a/packageE/pages/cart/cart2/filter.wxs +++ b/packageE/pages/cart/cart2/filter.wxs @@ -49,14 +49,38 @@ function check_is_last(index,goods_id){ return true; } return false; - } +//-- 用于筛选商品的价格显示 -- +function fm_join_ord_prom_price(gd,join_gd_list,show_ord_prom,count){ + var price=gd.goods_price; + //在join_gd_list中查找是否已经存在gd商品,靠购物车的id来判断 + for(var i=0;i