From 8b9fa55269eefdf172345336dd5c1a5846640413 Mon Sep 17 00:00:00 2001 From: banche Date: Tue, 22 Mar 2022 10:23:11 +0800 Subject: [PATCH] fix;服务卡项购物车超限购 --- packageA/pages/goodsInfo/goodsInfo.js | 117 ++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------- 1 file changed, 40 insertions(+), 77 deletions(-) diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index 6eaec01..fcd3500 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -859,16 +859,16 @@ Page({ return false; }; - + // 秒杀活动 if(this.data.prom_type == 1) { this.data.sele_g.viplimited = this.data.sele_g.buy_limit; - // 每人限购数 + // 每人最大限购数 th.data.sele_g.viplimited = th.data.sele_g.buy_limit; //----获取用户活动购买数---- - // 已经付款的单数 + // 已经付款的单数,已经成功购买的数量 var gd_buy_num = 0; await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+os.stoid+"&user_id="+getApp().globalData.user_id+"&card_id="+th.data.options.goods_id+"&prom_type="+th.data.options.prom_type+"&prom_id="+th.data.options.prom_id, { }).then(res => { @@ -884,51 +884,51 @@ Page({ }; }); - // 获取购物车同款数量 判断是否超库存 - var cartGoodsNum = 0; - await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+os.stoid+"&user_id="+oo.user_id+"&service_id="+th.data.data.id+"&pick_id="+th.data.sto_sele_id, - { }).then(res => { - if (res.data.data.pageData.length > 0) { - const tmpObj = res.data.data.pageData[0]; - cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num; - } - - }); - - // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程 - // 没有库存,已抢光的情况下,走正常购买流程 + // 没有库存,已抢光的情况下,走正常购买流程 if(redisNum > 0 && !this.data.is_normal) { // 输入的数量 var t = th.data.goodsInputNum; + // 获取购物车同款数量 + var cartGoodsNum = 0; + + // 购物车 + if (action != "buy") { + await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+os.stoid+"&user_id="+oo.user_id+"&service_id="+th.data.data.id+"&pick_id="+th.data.sto_sele_id, + { }).then(res => { + if (res.data.data.pageData.length > 0) { + const tmpObj = res.data.data.pageData[0]; + cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num; + } + + }); + + // 输入的数量 + 购物车同款商品的数量 + t = parseInt(t) + parseInt(cartGoodsNum); + } + + // 剩余购买数量 + let num = th.data.sele_g.viplimited - gd_buy_num; + num = num < 0 ? 0 : num; if (t > redisNum) { wx.showToast({ - title: '超出活动库存' + redisNum, + title: '超出活动库存', icon: 'none' }); // 开启限购 if (th.data.sele_g.viplimited > 0) { - let num = th.data.sele_g.viplimited - gd_buy_num; - if (action !="buy") { - // 购物车 - if (num > redisNum) { - th.setData({goodsInputNum: redisNum}); - } else { - th.setData({goodsInputNum: num}); - } - } else { - // 立即购买 - if (num > redisNum) { - th.setData({goodsInputNum: redisNum}); - } else { - th.setData({goodsInputNum: num}); - } + if (t > num) { + th.setData({goodsInputNum: num}); } + if (redisNum < num) { + th.setData({goodsInputNum: redisNum}); + } + } else { th.setData({goodsInputNum: redisNum}); @@ -937,64 +937,27 @@ Page({ return false; } - - - // 跳过<立即购买> 购物车 - if (action !="buy") { - - // 输入的数量 + 购物车同款商品的数量 - var maxNum = parseInt(t) + parseInt(cartGoodsNum); - // 是否开启个人限购 - if (th.data.sele_g.viplimited > 0) { - if (maxNum + gd_buy_num > th.data.sele_g.buy_limit) { - wx.showToast({ - title: '超出活动限购数量', - icon: 'none' - }); - - // 可购买数量 - let num = th.data.sele_g.viplimited - gd_buy_num - cartGoodsNum; - th.setData({goodsInputNum: num < 0 ? 0 : num}); - return false; - } - - } - - if (maxNum > redisNum) { - wx.showToast({ - title: '超出活动库存', - icon: 'none' - }); - // 可购买数量 - let num = redisNum - cartGoodsNum; - th.setData({goodsInputNum: num}); - return false; - } - - } else { - // 以下为立即购买 - // 是否开启个人限购 + // 以下小于等于库存 + if (t <= redisNum) { if (th.data.sele_g.viplimited > 0) { - if (t + gd_buy_num > th.data.sele_g.viplimited) { + if (t > num) { wx.showToast({ title: '超出活动限购数量', icon: 'none' }); - - let num = th.data.sele_g.viplimited - gd_buy_num; + if (num > redisNum) { th.setData({goodsInputNum: redisNum}); } else { th.setData({goodsInputNum: num}); } return false; - } - - - }; - + } + + } } + }; }; -- libgit2 0.21.4