From cd2a6c7b63f745f754dd6fad88944a4296f0a426 Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Mon, 5 Feb 2024 11:43:53 +0800 Subject: [PATCH] 卡顿的bug优化 --- packageE/pages/cart/cart2/cart2.js | 14 +++++++++++++- pages/cart/cart/cart.js | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------- 2 files changed, 165 insertions(+), 92 deletions(-) diff --git a/packageE/pages/cart/cart2/cart2.js b/packageE/pages/cart/cart2/cart2.js index 8909ab7..2bab08e 100644 --- a/packageE/pages/cart/cart2/cart2.js +++ b/packageE/pages/cart/cart2/cart2.js @@ -176,6 +176,9 @@ Page({ show_can_cx_map:{}, //优惠促销活动的集合 yhcx_act_map: {}, + + //优惠促销购买次数 + yhcx_buy_map:{} }, @@ -1364,7 +1367,10 @@ Page({ // item1.prom_id='' // item1.prom_type='' } else { + let user_pre_buynum = await th.getUserBuyPromNum_pre(item1.prom_id) //用户已经参与次数 + + if (user_pre_buynum < limit_num) { await th.add_prom_goods_map(item1); } else { @@ -1606,12 +1612,12 @@ Page({ let req_d1 = { user_id: getApp().globalData.user_id, goods_ids: [hr], store_id: os.stoid } - await getApp().request.promisePost("/api/weshop/order/getrebateSum", { is_json: 1, data: req_d1 }).then(grs => { if (grs.data.code == 0) item[c].use_commission = grs.data.data; }); + commission_gds.push(hr); } } @@ -6968,6 +6974,12 @@ Page({ }, //优惠促销用户参与次数 async getUserBuyPromNum_pre(prom_id){ + + //如果有缓存的数据,就用缓存的数据 + if(this.data.in_yhact[prom_id] && this.data.in_yhact[prom_id].buyed!=undefined){ + let user_pre_buynum=this.data.in_yhact[prom_id].buyed; + return user_pre_buynum; + } var userInfo = getApp().globalData.userInfo; var url = `/api/weshop/ordergoods/getUserBuyPromNum?is_all=1&store_id=${os.stoid}&user_id=${userInfo.user_id}&prom_type=3&prom_id=${prom_id}`; let res = await getApp().request.promiseGet(url, { diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 376dbf0..b2fd210 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -62,11 +62,13 @@ Page({ //送赠品的优化 cart_zp:{}, //-- dp_cart深拷贝的缓存 -- - dp_cart:null + dp_cart:null, + //优惠促销活动的集合 + yhcx_act_map: {}, }, - + onLoad: function () { var a = this, ee = a; @@ -559,9 +561,15 @@ Page({ i_fd=i_fd.goodsPromInfoRespDto; //-- 赋值多促销活动的优化-- carr[ia].more_cx=i_fd.more_cx; + //商品优惠促销的缓存 + if (i_fd.yhcx_pro) { + th.data.yhcx_act_map[i_fd.yhcx_pro.id] = i_fd.yhcx_pro; + } + //商品组合促销的缓存 if (i_fd.zh_pro) { th.data.zuhe_map[i_fd.zh_pro.id] = i_fd.zh_pro; } + //商品阶梯促销的缓存 if (i_fd.ladder_pro) { var ladder_pro = i_fd.ladder_pro; th.data.ladder_map[ladder_pro.id] = ladder_pro; @@ -699,7 +707,6 @@ Page({ th.disInvalid(item); continue; } - } } @@ -1593,7 +1600,6 @@ Page({ } - //-- 判断起购数量 -- if (!e.data.checkAllToggle) { //判断是不是有促销活动 @@ -1634,31 +1640,29 @@ Page({ // if (obj.prom_type == 10) ladder_calc.add_ladder_prom(dda, i, obj); //多门店,多优惠次数控制 - let pro_off1 = false - if (!e.data.checkAllToggle) { - //判断多店优惠促销次数控制 - if (th.data.requestData.length > 1) { - if (obj.prom_type == 3) { - - pro_off1 = await th.multiple_stores_pro(i, j) - } - } - } - - if (pro_off1) { - pro_off = true - let txt1 = "requestData[" + i + "].pro_off"; - e.setData({ - [txt1]: true, - [txt]: 0, - }); - - wx.showToast({ - title: '已超出优惠促销次数', - icon: 'none', - }); + // let pro_off1 = false + // if (!e.data.checkAllToggle) { + // //判断多店优惠促销次数控制 + // if (th.data.requestData.length > 1) { + // if (obj.prom_type == 3) { + // pro_off1 = await th.multiple_stores_pro(i, j) + // } + // } + // } + // if (pro_off1) { + // pro_off = true + // let txt1 = "requestData[" + i + "].pro_off"; + // e.setData({ + // [txt1]: true, + // [txt]: 0, + // }); + // + // wx.showToast({ + // title: '已超出优惠促销次数', + // icon: 'none', + // }); - } else { + // } else { if (!e.data.checkAllToggle) { //组合购的金额要另外算 @@ -1672,11 +1676,16 @@ Page({ offline_price += (item[j].goods_price - item[j].offline_price) * item[j].goods_num; offline_num += item[j].goods_num; } - } - e.setData({ - [txt]: !e.data.checkAllToggle, - }) + e.setData({ + [txt]: !e.data.checkAllToggle, + }) + + //} + + + + // if (!e.data.checkAllToggle) { // //组合购的金额要另外算 // if (item[j].prom_type != 7 && item[j].prom_type != 10) @@ -1952,36 +1961,44 @@ Page({ } //判断多店优惠促销次数控制 - if (th.data.requestData.length > 1) { - if (gd_info.prom_type == 3) { - pro_off1 = await th.multiple_stores_pro(pitems, i) - } - } - if (pro_off1) { - pro_off = true - e.setData({ - [txt]: 0, - }); - } else { - e.setData({ - [txt]: Number(!sele), - }); - } - } - var txt = "requestData[" + pitems + "].selected"; - if (pro_off) { - wx.showToast({ - title: '已超出优惠促销次数', - icon: 'none', - }); - e.setData({ - [txt]: 0, - }); - } else { + // if (th.data.requestData.length > 1) { + // if (gd_info.prom_type == 3) { + // pro_off1 = await th.multiple_stores_pro(pitems, i) + // } + // } + // if (pro_off1) { + // pro_off = true + // e.setData({ + // [txt]: 0, + // }); + // } else { + // e.setData({ + // [txt]: Number(!sele), + // }); + // } e.setData({ [txt]: Number(!sele), }); + } + var txt = "requestData[" + pitems + "].selected"; + // if (pro_off) { + // wx.showToast({ + // title: '已超出优惠促销次数', + // icon: 'none', + // }); + // e.setData({ + // [txt]: 0, + // }); + // } else { + // e.setData({ + // [txt]: Number(!sele), + // }); + // } + + e.setData({ + [txt]: Number(!sele), + }); //-- 选择了什么商品,就用什么商品来判断 -- var sele_arr = {}; @@ -2040,6 +2057,7 @@ Page({ //判断多门店,优惠促销次数的控制 async multiple_stores_pro(pitems, item) { + let a = this.data.requestData[pitems].goods[item]; let th = this let arr_pro = [] @@ -2049,21 +2067,31 @@ Page({ } }) let prom = null - await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + a.prom_id, {}).then(res => { - if (res.data.code == 0) { - prom = res.data.data; - } - }) - let user_pre_buynum = await this.getUserBuyPromNum_pre(a.prom_id) + //使用缓存,不在调用接口 + if(!prom && th.data.yhcx_act_map && th.data.yhcx_act_map[a.prom_id] ){ + prom=th.data.yhcx_act_map[a.prom_id]; + } + if(!prom) { + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + a.prom_id, {}).then(res => { + if (res.data.code == 0) { + prom = res.data.data; + } + }) + } + let user_pre_buynum = await this.getUserBuyPromNum_pre(a.prom_id); if (user_pre_buynum >= prom.limit_num) { return false } else { + let action_num = user_pre_buynum + 1; arr_pro.map(item => { + let found = false; item.goods.map(ite => { + if(found) return; if (ite.prom_type == 3 && ite.prom_id == a.prom_id && !ite.is_gift && ite.selected) { action_num += 1; + found=true; } }) }) @@ -2226,23 +2254,22 @@ Page({ } } - - let pro_off = false - //判断多店优惠促销次数控制 - if (th.data.requestData.length > 1) { - if (a.prom_type == 3 && !a.selected) { - //pro_off = await th.multiple_stores_pro(pitems, item) - } - } - - if (pro_off) { - wx.showToast({ - title: '已超出优惠促销次数', - icon: 'none', - }); - th.clear_clicking(); - return false; - } + // let pro_off = false + // //判断多店优惠促销次数控制 + // if (th.data.requestData.length > 1) { + // if (a.prom_type == 3 && !a.selected) { + // pro_off = await th.multiple_stores_pro(pitems, item) + // } + // } + // + // if (pro_off) { + // wx.showToast({ + // title: '已超出优惠促销次数', + // icon: 'none', + // }); + // th.clear_clicking(); + // return false; + // } var txt0 = "requestData[" + pitems + "].show_can_cx"; e.setData({ @@ -2492,6 +2519,9 @@ Page({ //-- 先批量判断一下活动的类型,同时要同步跟新 -- var offline_price = 0; var offline_num = 0; + + //-- 优惠促销活动限购次数的优化 -- + var ch_yc_map={}; for (var c = 0; c < item.length; c++) { //清理一下赠品 if (item[c].is_gift) { @@ -2504,6 +2534,20 @@ Page({ continue; } + let pro_off1 = false; + //-- 判断活动超出限购,要有选中的情况 -- + if (item[c].prom_type == 3 && item[c].selected && !ch_yc_map[a.prom_id]) { + //一个门店一个优惠促销就判断一次 + ch_yc_map[a.prom_id]=1; + pro_off1 = await th.multiple_stores_pro(a, c) + } + if (pro_off1) { + wx.showToast({ + title: '已超出优惠促销次数', + icon: 'none', + }); + } + all_num += item[c].goods_num; if (item[c].prom_type == 7) { @@ -2608,6 +2652,13 @@ Page({ } } + + + + + + + //总的价格,把组合商品的价格拿出来 var zh_calc_res = zh_calc.calculate_zh(car, a, th); console.log('.组合价-----------') @@ -4766,6 +4817,11 @@ Page({ async all_check_prom_activity() { this.data.duo_zp_num_arr = {}; + //用来存销赠品的--2024-2-1 + let cart_zp=this.data.cart_zp; + //要清空一下赠品数组 + cart_zp={}; + for (var i in this.data.requestData) { var cindex = i; var make_up_arr = new Array(); @@ -4781,11 +4837,6 @@ Page({ var no_gift_arr = []; - //用来存销赠品的--2024-2-1 - let cart_zp=this.data.cart_zp; - //要清空一下赠品数组 - cart_zp={}; - //主要判断有没有促销活动 var is_sele_prom = 0; var is_gift_del = 0; @@ -4857,11 +4908,20 @@ Page({ if (th.data.promgoods_map[p_item[0]]) { prom = th.data.promgoods_map[p_item[0]]; } else { - await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + p_item[0], {}).then(res => { - if (res.data.code == 0) { - prom = res.data.data; - } - }) + + //使用缓存,不在调用接口 + if(!prom && th.data.yhcx_act_map && th.data.yhcx_act_map[p_item[0]] ){ + prom=th.data.yhcx_act_map[p_item[0]]; + } + if(!prom){ + await getApp().request.promiseGet("/api/weshop/promgoods/get/" + os.stoid + "/" + p_item[0], {}).then(res => { + if (res.data.code == 0) { + prom = res.data.data; + } + }) + } + + } let limit_num = 0 let user_pre_buynum = 0 @@ -4910,6 +4970,7 @@ Page({ if (!promgoods_list) continue; th.data.promgoods_list[p_item[0]] = promgoods_list; } + if (!limit_num || user_pre_buynum < limit_num) { for (var i in promgoods_list) { var item = promgoods_list[i]; -- libgit2 0.21.4