diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index bc32976..030cc2a 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -1150,9 +1150,10 @@ Page({ var e = { goods_num: a.goods_num - 1, id: a.id, - goods_id: a.goods_id, + goods_id: a.service_id, store_id: oo.stoid }; + this.postCardList_ser(e, t.currentTarget.dataset.item, t.currentTarget.dataset.pitems); } }, @@ -2025,13 +2026,36 @@ Page({ e.setData({ [txt]: t.goods_num }); - - + + + if(t.prom_type == 1) { var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num"; var redis_num = 0; - //------判断活动是否抢光----- + // 获取其他门店,同类商品的数量 + var cartGoodsNum = 0; + await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+t.store_id+"&user_id="+getApp().globalData.user_id+"&service_id="+t.goods_id, + { }).then(res => { + if (res.data.data.pageData.length > 0) { + const tmpObj = res.data.data.pageData; + tmpObj.forEach(v => { + if (t.id != v.id) { + cartGoodsNum += parseInt(v.goods_num); + } + + }); + } + }); + // 当前商品数量包括其他门店 + var totalNum = 0 + if (cartGoodsNum > 0) { + totalNum = t.goods_num + cartGoodsNum; + } else { + totalNum = t.goods_num; + } + + //获取当前商品活动库存 await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + t.store_id + "/" + t.prom_type + "/" + t.prom_id, { 1: 1 @@ -2050,19 +2074,19 @@ Page({ return false; }; + // 限购数量 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 ? 0 : res.data.data.buy_limit; }; }); - //----获取用户活动购买数---- + //用户已经成功付款购买的数量 var gd_buy_num = 0; await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+t.store_id+"&user_id="+getApp().globalData.user_id+"&card_id="+t.card_id+"&prom_type="+t.prom_type+"&prom_id="+t.prom_id, { }).then(tt => { @@ -2075,22 +2099,23 @@ Page({ }; }); + // 剩余购买数 + let num = buylimit - gd_buy_num; - if(t.goods_num > redis_num) { + if(totalNum > redis_num) { wx.showToast({ title: '超出活动库存', icon: 'none', }); // 开启限购 if (buylimit > 0) { - let num = buylimit - gd_buy_num; if (num > redis_num) { - th.setData({[txt]: redis_num}); + th.setData({[txt]: redis_num-cartGoodsNum}); } else { - th.setData({[txt]: num}); + th.setData({[txt]: num - cartGoodsNum}); } } else { - th.setData({[txt]: redis_num}); + th.setData({[txt]: redis_num - cartGoodsNum}); } await e.doCheckAll(); @@ -2102,15 +2127,14 @@ Page({ if (buylimit > 0) { // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” - if(t.goods_num + gd_buy_num > buylimit) { + if(totalNum > num) { // 计算还可以购买的数量:库存量 - 已购数 wx.showToast({ title: '超出活动限购', icon: 'none', }); - let num = buylimit - gd_buy_num; if (num <= 0) num = 1; - th.setData({[txt]: num}); + th.setData({[txt]: num - cartGoodsNum}); await e.doCheckAll(); return false; }; @@ -2334,7 +2358,6 @@ Page({ update_cart_ser: function (t, pitem, item) { var e = this; - console.log('t===>', t); getApp().request.put("/api/weshop/cartService/update", { data: t, success: async function (ee) {