diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index 894dc15..f044674 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -847,6 +847,12 @@ Page({ return false; }; + // 库存 + var redisNums = 0; + // 限购数 + var limitNum = 0; + // 已购买数量 + var boughtNum = 0; // 秒杀活动 if(this.data.prom_type == 1) { @@ -859,6 +865,7 @@ Page({ // 如果数量为0,设置和显示已抢光 // 否则,进一步判断是否超出限购或超出库存 await this.getactLen().then(async function(res) { + redisNums = res; let curNum = th.data.goodsInputNum; // res: redis可购买数量 console.log('当前可以购买的数量:', res); @@ -883,7 +890,9 @@ Page({ let promcardbuynum = data.data.data.promcardbuynum; let buyedNum = promcardbuynum; // 自己已经购买的数量b let canBuyNum = limited - buyedNum; // 自己还可购买的数量c - + limitNum = limited; + boughtNum = buyedNum; + if(canBuyNum <= 0) { canBuyNum = 0; }; @@ -925,18 +934,6 @@ Page({ }; - - - - - - - - - - - - if(action=="buy"){ @@ -965,9 +962,6 @@ Page({ // console.log('newd++++++++', newd); th.buyNow(newd); } else { - - - var newd = { service_id: th.data.data.id, @@ -1008,10 +1002,26 @@ Page({ //-------如果购物车中有相关的数据--------- if (re.data.data.total > 0) { - var item = re.data.data.pageData[0]; + var item = re.data.data.pageData[0]; + var totalNum = th.data.goodsInputNum + item.goods_num; + if (th.data.prom_type == 1 && !th.data.is_normal) { + var snum = limitNum - boughtNum; + + if (totalNum >= redisNums){ + if (redisNums > snum) { + totalNum = snum; + } else { + totalNum = redisNums; + } + } else { + if (totalNum > snum) + totalNum = snum; + } + } + var updata = { id: item.id, - goods_num: th.data.goodsInputNum + item.goods_num, + goods_num: totalNum, money: th.data.data.shop_price, store_id: os.stoid, }; @@ -1038,7 +1048,7 @@ Page({ getApp().my_warnning('加入购物车成功', 1, th, 450); var c_num = th.data.cartGoodsNum + th.data.goodsInputNum; th.setData({ - cartGoodsNum: c_num + cartGoodsNum: totalNum }); th.closeSpecModal(); }