From 2adcd0faa5e58cbe43537a523537f8a97b6a2705 Mon Sep 17 00:00:00 2001 From: banche Date: Fri, 18 Mar 2022 20:25:33 +0800 Subject: [PATCH] fix:购物车问题 --- packageA/pages/goodsInfo/goodsInfo.js | 14 ++++++-------- pages/cart/cart/cart.js | 229 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------- 2 files changed, 138 insertions(+), 105 deletions(-) diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index 1f9f186..bb4ddd7 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -906,13 +906,6 @@ Page({ // 输入的数量 + 购物车同款商品的数量 var maxNum = parseInt(t) + parseInt(cartGoodsNum); - if (maxNum > redisNum) { - wx.showModal({ - title: '超出活动库存', - }); - return false; - } - // 是否开启个人限购 if (th.data.sele_g.viplimited > 0) { @@ -925,7 +918,12 @@ Page({ } - + if (maxNum > redisNum) { + wx.showModal({ + title: '超出活动库存', + }); + return false; + } } diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 786d303..610ce3c 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -2016,19 +2016,84 @@ Page({ th = e; var user_id = getApp().globalData.user_id; var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num"; + e.setData({ [txt]: t.goods_num }); - // if(t.prom_type == 1) { - - // } else { - - - // }; + + if(t.prom_type == 1) { - await e.checkCartNum(t, item, pitem); + var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num"; + var redis_num = 0; + + //------判断活动是否抢光----- + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + + t.store_id + "/" + t.prom_type + "/" + t.prom_id, { + 1: 1 + }).then(res => { + redis_num = res.data.data; + }); + + // 检测库存 + if(redis_num == 0) { + wx.showModal({ + title: '超出活动库存1', + }); + th.setData({[txt]: redis_num}); + return false; + }; + + // 个人限购 + //----获取用户活动购买数---- + await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+t.store_id+"&user_id="+getApp().globalData.user_id+"&card_id="+t.goods_id+"&prom_type="+t.prom_type+"&prom_id="+t.prom_id, { + }).then(tt => { + if (tt.data.code == 0) { + th.setData({ + promcardbuynum: tt.data.data.promcardbuynum, + cardbuynum: tt.data.data.cardbuynum, + }); + }; + }); + + var buylimit = 0 + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, { + + }).then(res => { + if(res.data.code == 0) { + + th.data.sele_g = res.data.data; + th.data.sele_g.viplimited = res.data.data.buy_limit; + buylimit = res.data.data.buy_limit; + }; + }); + //--秒杀:判断商品是否超出活动限购-- + if (buylimit > 0) { + + var gd_buy_num = th.data.promcardbuynum; + + // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” + if(t.goods_num + gd_buy_num > buylimit) { + // 计算还可以购买的数量:库存量 - 已购数 + wx.showModal({ + title: '超出活动限购', + }); + th.setData({[txt]: buylimit}); + return false; + }; + + } + + if(t.goods_num > redis_num) { + wx.showModal({ + title: '超出活动库存2', + }); + th.setData({[txt]: redis_num}); + return false; + }; + + + } - await e.doCheckAll(); await e.update_cart_ser(t, pitem, item); @@ -2037,37 +2102,40 @@ Page({ // 检查购物车数量 - async checkCartNum(t, item, pitem) { + async checkCartNum(t, item, pitem) { var th = this; if(t.is_pd_normal) return false; if (t.prom_type == 1) { var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num"; - var redis_num = 0; + var redis_num = 0; + //------判断活动是否抢光----- - // await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + - // t.store_id + "/" + t.prom_type + "/" + t.prom_id, { - // 1: 1 - // }).then(res => { - // redis_num = res.data.data; - // if(redis_num == 0) { - // wx.showModal({ - // title: '来晚了,已被抢光~', - // }); - // return false; - // }; - // if(t.goods_num > redis_num) { - // wx.showModal({ - // title: '超出商品活动限购数量2', - // // title: '来晚了,已被抢光~', - // }); - // // th.setData({goodsInputNum: redis_num}) - // return false; - // }; - // }); - - - - //----获取活动购买数---- + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + + t.store_id + "/" + t.prom_type + "/" + t.prom_id, { + 1: 1 + }).then(res => { + redis_num = res.data.data; + }); + + // 检测库存 + if(redis_num == 0) { + wx.showModal({ + title: '超出活动库存', + }); + th.setData({[txt]: redis_num}); + return false; + }; + + if(t.goods_num > redis_num) { + wx.showModal({ + title: '超出活动库存', + }); + th.setData({[txt]: redis_num}); + return false; + }; + + // 个人限购 + //----获取用户活动购买数---- await getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { data: { store_id: t.store_id, @@ -2087,72 +2155,41 @@ Page({ }, }); - - - + + var buylimit = 0 await getApp().request.get("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, { success: function (res) { if(res.data.code == 0) { th.data.sele_g = res.data.data; - th.data.sele_g.viplimited = res.data.data.buy_limit; - //--秒杀:判断商品是否超出活动限购-- - if (th.data.sele_g.viplimited > 0) { - var gd_buy_num = th.data.promcardbuynum; - - // 如果限购数量>活动库存数量,增加数量时会先超过库存数量,此时应该提示“超出活动库存”; - // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” - - if(th.data.sele_g.viplimited > th.data.sele_g.goods_num) { - // 计算还可以购买的数量:库存量 - 已购数 - var num = th.data.sele_g.goods_num - gd_buy_num; - if(num < 0) num = 0; - if(t.goods_num > num) { - wx.showModal({ - title: '超出活动库存', - }); - - // var num = th.data.sele_g.goods_num; - th.setData({[txt]: num}); - // t.goods_num = num; - // th.doCheckAll(); - // th.update_cart_ser(t, pitem, item); - // return false; - - }; - - } else { - - if ((t.goods_num + gd_buy_num> th.data.sele_g.viplimited) && (t.goods_num <= th.data.sele_g.goods_num)) { - wx.showModal({ - title: '超出活动限购数量', - }); - - var num = th.data.sele_g.viplimited - gd_buy_num; - if (num <= 0) num = 1; - - th.setData({ - [txt]: num, - gdnum: num, - }); - - // return false; - } - - }; - - - t.goods_num = num; - th.doCheckAll(); - th.update_cart_ser(t, pitem, item); - - - - }; - + th.data.sele_g.viplimited = res.data.data.buy_limit; + buylimit = res.data.data.buy_limit; }; }, - }); - + }); + + + //--秒杀:判断商品是否超出活动限购-- + if (buylimit > 0) { + + var gd_buy_num = th.data.promcardbuynum; + + // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” + if(t.goods_num + gd_buy_num > buylimit) { + // 计算还可以购买的数量:库存量 - 已购数 + wx.showModal({ + title: '超出活动限购', + }); + th.setData({[txt]: buylimit}); + + }; + + } + + + th.doCheckAll(); + th.update_cart_ser(t, pitem, item); + + }; }, @@ -2275,9 +2312,7 @@ Page({ //--更新购物车--- update_cart_ser: function (t, pitem, item) { var e = this; - // if(t.prom_type == 1) { - // t.goods_num = e.data.gdnum; - // } + console.log('t===>', t); getApp().request.put("/api/weshop/cartService/update", { data: t, -- libgit2 0.21.4