diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index 6f9e7bd..328caf6 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -897,7 +897,7 @@ Page({ canBuyNum = 0; }; - if(limited > res) { + if(canBuyNum > res) { if(curNum > res) { // t当前增减的数量 wx.showModal({ title: '超出活动库存', @@ -909,8 +909,8 @@ Page({ }; }; - if(limited <= res) { - if(curNum > limited) { + if(canBuyNum <= res) { + if(curNum > canBuyNum) { wx.showModal({ title: '超出限购数量', }); @@ -996,13 +996,66 @@ Page({ store_id: os.stoid, user_id: oo.user_id, service_id: th.data.data.id, - pick_id: th.data.sto_sele_id, }, success: function(re) { - - //-------如果购物车中有相关的数据--------- + //-------如果购物车中有相关的数据--------- if (re.data.data.total > 0) { - var item = re.data.data.pageData[0]; + var item = null; + // 多门店问题 + var cartGoodsNum = 0; + const tmpObj = re.data.data.pageData; + for (let i = 0; i < tmpObj.length; i++) { + if (th.data.sto_sele_id != tmpObj[i].pick_id) { + cartGoodsNum += parseInt(tmpObj[i].goods_num); + } else { + item = tmpObj[i]; + } + } + // 当前门店同类商品还没加入到购物车 但是有其他门店的同类商品 + if (th.data.prom_type == 1 && !th.data.is_normal && !item) { + + // 秒杀购物车购买 修正数量 + var snum = limitNum - boughtNum; + if (snum <= 0) { + wx.showModal({ + title: '超出限购数量', + }); + return false; + } + + var cSnum = snum- cartGoodsNum <= 0 ? 0 : snum- cartGoodsNum; + var cRedisNums = redisNums- cartGoodsNum <= 0 ? 0 : redisNums- cartGoodsNum; + + if (newd['goods_num'] >= redisNums){ + if (redisNums > snum) { + newd['goods_num'] = cSnum; + } else { + newd['goods_num'] = cRedisNums; + } + } else { + if (newd['goods_num'] > snum) newd['goods_num'] = cSnum; + } + + if (newd['goods_num'] <= 0) { + getApp().my_warnning('加入购物车成功', 1, th, 450); + th.closeSpecModal(); + return false; + } + getApp().request.post("/api/weshop/cartService/save", { + data: newd, + success: function(t) { + getApp().my_warnning('加入购物车成功', 1, th, 450); + var c_num = th.data.cartGoodsNum + th.data.goodsInputNum; + th.setData({ + cartGoodsNum: c_num + }); + th.closeSpecModal(); + } + }); + return false; + } + + // 以下为当前门店同类商品已经加入到购物车 var totalNum = th.data.goodsInputNum + item.goods_num; // 秒杀购物车购买 修正数量 @@ -1016,13 +1069,13 @@ Page({ } if (totalNum >= redisNums){ if (redisNums > snum) { - totalNum = snum; + totalNum = snum- cartGoodsNum; } else { - totalNum = redisNums; + totalNum = redisNums- cartGoodsNum; } } else { if (totalNum > snum) - totalNum = snum; + totalNum = snum- cartGoodsNum; } } @@ -1061,7 +1114,6 @@ Page({ } }); } else { - getApp().request.post("/api/weshop/cartService/save", { data: newd, success: function(t) { @@ -3575,6 +3627,17 @@ Page({ //-- 秒杀的普通购买 -- openSpecModel_Nor: function () { + + // 是否授权登陆 + var user_info = getApp().globalData.userInfo; + if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) { + wx.navigateTo({ + url: '/pages/togoin/togoin', + }) + return false; + } + + this.data.g_buy_num = new Map(); var th = this; this.setData({open_ind_store: 5, goodsInputNum: 1});//拼团直接给4