diff --git a/packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo.js b/packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo.js index 1568e5a..dac59c7 100644 --- a/packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo.js +++ b/packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo.js @@ -2195,6 +2195,9 @@ Page({ this.get_buy_num(this.data.sele_g, async function () { + + var is_show_bs=0; + var l_num=-1; //--判断商品是否超出限购-- if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { @@ -2205,10 +2208,11 @@ Page({ // title: '超出商品限购', // }); getApp().my_warnning('超出商品限购', 0, th); - var num = th.data.sele_g.viplimited - gd_buy_num; - if (num < 0) num = 0; - th.setData({ goodsInputNum: num }) - return false; + l_num = th.data.sele_g.viplimited - gd_buy_num; + if (l_num < 0) l_num = 0; + //th.setData({ goodsInputNum: num }) + //return false; + is_show_bs=1; } } @@ -2263,22 +2267,41 @@ Page({ } } + //-- 限购数量也要进行计算一下 -- + if(l_num>-1){ + if(e>l_num) e=l_num; + } + + //提示了一个,就不要提示第二个 + var is_show_bs=0; //--- 促销活动也不控制起订量, 这里很重要的一个控制,起订量的 ---- if(th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1){ - if(tmo_num && (t-mo_num)%steep!=0){ - wx.showToast({ - title: '购买数必须是起订量的倍数', - icon: 'none', - }); + if(!is_show_bs) { + wx.showToast({ + title: '购买数必须是起订量的倍数', + icon: 'none', + }); + } t=mo_num+ parseInt((t-mo_num)/steep)*steep+steep; + is_show_bs=1; } } if (!e) e = 0; //库存不足,不增加 if (e < t) { - wx.showModal({ title: '库存不足', }); + if(!is_show_bs) wx.showModal({ title: '库存不足', }); if (e < 0) e = 0; if(th.data.is_normal == 1){ diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index aaf24d4..e403f56 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -1559,9 +1559,9 @@ Page({ valueToNum: function (t) { if (!this.data.is_load) return false; //控制住,避免事件响应冲突,只有input有输入的时候,才刷新 - if (this.data.btn_click) { - return false; - } + // if (this.data.btn_click) { + // return false; + // } this.data.btn_click = 1; var a = t.currentTarget.dataset.item; @@ -2601,55 +2601,7 @@ Page({ //----------------------更新购物数量,加减,调用接口--------------------- postCardList: function (t, item, pitem) { - var e = this, - th = e, - user_id = getApp().globalData.user_id; - - function normal_check(store_count, goodsinfo, wareIds,cx_arr) { - - - // getApp().my_warnning('购买数量超出商品库存', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - //-- 要判断是不是起订量不购 -- - if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){ - var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length); - var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1); - if(mo_num>1 && t.goods_num1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0 ){ - - wx.showToast({ - title: '购买数量必须是起订量的倍数', - icon: 'none', - }); - t.goods_num =mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep+steep; - } - } - - - //--- 看一下是不是线下库存 --- - if (th.data.sales_rules >= 2 && !goodsinfo.whsle_id) { - th.check_down_line(t, pitem, item, wareIds); - } else { - if (t.goods_num > store_count) { - wx.showToast({ - title: '购买数量超出商品库存', - icon: 'none', - }); - e.setData({ - [txt]: store_count - }); - e.doCheckAll(); - t.goods_num = store_count; - } - e.update_cart(t, pitem, item); - } - } + var e = this,th = e,user_id = getApp().globalData.user_id; // console.log('update'); // console.log('9995959595959',t); @@ -2666,7 +2618,9 @@ Page({ var promgoodsbuynum = 0; var goodsbuynum = 0; - //--要获得商品,该用户买了多少件,同步应用-- + var is_showing=0; + + //--要获得商品,该用户买了多少件,同步应用,用于限购的计算-- await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { data: { store_id: oo.stoid, @@ -2686,279 +2640,280 @@ Page({ } goodsbuynum = buy_num_data.goodsbuynum; - }) //--> by ty // var buyed_mum2 = t.goods_num + goodsbuynum; var buyed_mum2 = t.goods_num; //<-- + // 判断当前预购买的数量是否超过可购买的数量,限购还要考虑到商品的库存 + if (limit > 0) { - // 判断当前预购买的数量是否超过可购买的数量 - if (buyed_mum2 > (limit - goodsbuynum) && limit > 0) { - wx.showToast({ - title: '购买数量超出商品限购', - icon: 'none', - }); //getApp().my_warnning('购买数量超出商品限购', 0, th); var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - //--> by ty - var cbuy = limit - goodsbuynum; - // var cbuy = limit - buyed_mum2 + 1; - //<-- - - e.setData({ - // [txt]: cbuy > 0 ? cbuy : 0, - [txt]: cbuy > 0 ? cbuy : limit, - }); - e.doCheckAll(); - - t.goods_num = cbuy > 0 ? cbuy : limit; - - if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){ - - //-- 判断商品是不是 -- - var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id); - - var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length); - var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1); - - if(mo_num>1 && t.goods_num1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0 ){ - - wx.showToast({ - title: '购买数量必须是起订量的倍数', - icon: 'none', - }); + limit = limit - goodsbuynum; + if(limit<0) limit=0; - t.goods_num=mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep - } + if(buyed_mum2>limit){ + wx.showToast({ + title: '购买数量超出商品限购', + icon: 'none', + }); + is_showing=1; } - // t.goods_num = cbuy > 0 ? cbuy : 0, - e.update_cart(t, pitem, item); - return false; - } + // e.setData({ + // // [txt]: cbuy > 0 ? cbuy : 0, + // [txt]: cbuy > 0 ? cbuy : limit, + // }); + //e.doCheckAll(); + // t.goods_num = cbuy > 0 ? cbuy : limit; + // + // if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){ + // + // //-- 判断商品是不是 -- + // var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id); + // var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length); + // var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1); + // + // if(mo_num>1 && t.goods_num1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0 ){ + // + // wx.showToast({ + // title: '购买数量必须是起订量的倍数', + // icon: 'none', + // }); + // + // t.goods_num=mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep + // } + // } + // // t.goods_num = cbuy > 0 ? cbuy : 0, + // e.update_cart(t, pitem, item); + // return false; + } + else limit=100000; switch (goodsinfo.prom_type) { case 1: - //-- 读取秒杀 -- - rq.get("/api/ms/flash_sale/getFlashSaleOne/" + oo.stoid + "/" + goodsinfo.prom_id, { - isShowLoading: 0, - success: function (res_d) { - if (res_d.data.code == 0 && res_d.data.data) { - if (t.goods_num > store_count) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出商品库存' - // }); + //-- 读取秒杀 -- + var res_d= await getApp().promiseGet("/api/ms/flash_sale/getFlashSaleOne/" + oo.stoid + "/" + goodsinfo.prom_id, {}); + if (res_d.data.code == 0 && res_d.data.data) { + + var cbuy=limit; + if (t.goods_num > store_count && !is_showing) { wx.showToast({ title: '购买数量超出商品库存', icon: 'none', }); - // getApp().my_warnning('购买数量超出商品库存', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: store_count - }); - e.doCheckAll(); - - t.goods_num = store_count; - e.update_cart(t, pitem, item); - - return false; + is_showing=1; } + //一直都要给一个最小值,和库存比较 + if(cbuy>store_count) cbuy=store_count; var false_data = res_d.data.data; //--判断库存-- - if (t.goods_num > false_data.goods_num - false_data.buy_num) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出活动库存' - // }); + if (t.goods_num > false_data.goods_num - false_data.buy_num && !is_showing) { wx.showToast({ title: '购买数量超出活动库存', icon: 'none', }); - // getApp().my_warnning('购买数量超出活动库存', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: false_data.goods_num - false_data.buy_num - }); - e.doCheckAll(); - - t.goods_num = false_data.goods_num - false_data.buy_num; - e.update_cart(t, pitem, item); - - return false; + is_showing=1; } + //一直都要给一个最小值,和活动库存比较 + if(cbuy>false_data.goods_num - false_data.buy_num) cbuy=false_data.goods_num - false_data.buy_num; //--判断redis数量是否已经超出-- - if (t.goods_num > false_data.redisnum) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出商品库存' - // }); + if (t.goods_num > false_data.redisnum && !is_showing) { wx.showToast({ title: '购买数量超出商品库存', icon: 'none', }); - //getApp().my_warnning('购买数量超出商品库存', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: false_data.redisnum - }); - e.doCheckAll(); - - t.goods_num = false_data.redisnum; - e.update_cart(t, pitem, item); - return false; + is_showing=1; } + //一直都要给一个最小值,和活动库存比较 + if(cbuy>false_data.redisnum) cbuy=false_data.redisnum; + //--活动的限购是不是要判断-- - if (t.goods_num + promgoodsbuynum > false_data.buy_limit && false_data.buy_limit > 0) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出秒杀限购' - // }); - wx.showToast({ - title: '购买数量超出秒杀限购', - icon: 'none', - }); - // getApp().my_warnning('购买数量超出秒杀限购', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: false_data.buy_limit - }); - e.doCheckAll(); - t.goods_num = (false_data.buy_limit - promgoodsbuynum) ? false_data.buy_limit - promgoodsbuynum : 0; - e.update_cart(t, pitem, item); - return false; + if(false_data.buy_limit > 0) { + + if(t.goods_num + promgoodsbuynum > false_data.buy_limit && !is_showing){ + wx.showToast({ + title: '购买数量超出秒杀限购', + icon: 'none', + }); + } + + var act_limit=false_data.buy_limit-promgoodsbuynum; + if(!act_limit) act_limit=0; + + if(cbuy>act_limit) cbuy=act_limit; + } + + if(t.goods_num>cbuy) t.goods_num=cbuy; + e.update_cart(t, pitem, item); - } else { - normal_check(store_count, goodsinfo, wareIds); - } - } - }) - break; + } else { + e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算 + } + break; case 2: - getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + goodsinfo.goods_id + "/" + goodsinfo.prom_id, {}).then(res => { + //-- 读取团购 -- + var res= await getApp().promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + goodsinfo.goods_id + "/" + goodsinfo.prom_id, {}); if (res.data.code == 0 && res.data.data) { - if (t.goods_num > store_count) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出商品库存' - // }); + + var cbuy=limit; + if (t.goods_num > store_count && !is_showing) { wx.showToast({ title: '购买数量超出商品库存', icon: 'none', }); - // getApp().my_warnning('购买数量超出商品库存', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: store_count - }); - e.doCheckAll(); - - t.goods_num = store_count; - e.update_cart(t, pitem, item); - - return false; + is_showing=1; } + //一直都要给一个最小值,和库存比较 + if(cbuy>store_count) cbuy=store_count; var gr_data = res.data.data; //--判断库存-- - if (t.goods_num > gr_data.goods_num - gr_data.buy_num) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出活动库存' - // }); + if (t.goods_num > gr_data.goods_num - gr_data.buy_num && !is_showing) { wx.showToast({ title: '购买数量超出活动库存', icon: 'none', }); - // getApp().my_warnning('购买数量超出活动库存', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: gr_data.goods_num - gr_data.buy_num - }); - e.doCheckAll(); - - t.goods_num = gr_data.goods_num - gr_data.buy_num; - e.update_cart(t, pitem, item); - - return false; + is_showing=1; } + //一直都要给一个最小值,和库存比较 + if(cbuy>gr_data.goods_num - gr_data.buy_num ) cbuy=gr_data.goods_num - gr_data.buy_num ; //--判断redis数量是否已经超出-- - if (t.goods_num > gr_data.redisnum) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出商品库存' - // }); + if (t.goods_num > gr_data.redisnum && !is_showing) { wx.showToast({ title: '购买数量超出商品库存', icon: 'none', }); - // getApp().my_warnning('购买数量超出商品库存', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: gr_data.redisnum - }); - e.doCheckAll(); - - t.goods_num = gr_data.redisnum; - e.update_cart(t, pitem, item); - return false; + is_showing=1; } + if(cbuy>gr_data.redisnum ) cbuy=gr_data.redisnum; //--活动的限购是不是要判断-- - if (t.goods_num + promgoodsbuynum > gr_data.buy_limit && gr_data.buy_limit > 0) { - // wx.showModal({ - // title: '提示', - // content: '购买数量超出团购限购' - // }); - wx.showToast({ - title: '购买数量超出团购限购', - icon: 'none', - }); - // getApp().my_warnning('购买数量超出团购限购', 0, th); - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; - e.setData({ - [txt]: gr_data.buy_limit - }); - e.doCheckAll(); + if (gr_data.buy_limit > 0) { + if(t.goods_num + promgoodsbuynum > gr_data.buy_limit && !is_showing){ + wx.showToast({ + title: '购买数量超出团购限购', + icon: 'none', + }); + is_showing=1; + } + + var act_limit=gr_data.buy_limit-promgoodsbuynum; + if(!act_limit) act_limit=0; + + if(cbuy>act_limit) cbuy=act_limit; - t.goods_num = (gr_data.buy_limit - promgoodsbuynum) ? gr_data.buy_limit - promgoodsbuynum : 0; - e.update_cart(t, pitem, item); - return false; } + + if(t.goods_num>cbuy) t.goods_num=cbuy; + e.update_cart(t, pitem, item); } else { - normal_check(store_count, goodsinfo, wareIds); + e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算 } - }) - break; + break; default: - var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id); - normal_check(store_count, goodsinfo, wareIds,cx_arr); + e.normal_check(t, item, pitem,store_count,limit, goodsinfo, wareIds); //普通商品的调用和计算 break } } }); }, + //-- 这个函数在计算的时候,要包含限购的那一部分 -- + async normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds){ + + var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id); + + var th=this; + // getApp().my_warnning('购买数量超出商品库存', 0, th); + var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; + + //--- 看一下是不是线下库存 --- + if (th.data.sales_rules >= 2 && !goodsinfo.whsle_id) { + + //th.check_down_line(t, pitem, item, wareIds,limit); + var ob = {}; + await th.check_down_line_next(t, pitem, item, erpwareid, function (res) { + ob = res; + }); + + + } else { + + var is_showing=0; + var cbuy=limit; + if (t.goods_num > limit) { + wx.showToast({ + title: '购买数量超出商品限购', + icon: 'none', + }); + is_showing=1; + } + + if (t.goods_num > store_count) { + if(!is_showing){ + wx.showToast({ + title: '购买数量超出商品库存', + icon: 'none', + }); + is_showing=1; + } + } + if(cbuy>store_count) cbuy=store_count; + + if(t.goods_num>cbuy) t.goods_num=cbuy; + + if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){ + var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length); + var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1); + + if(mo_num>1 && t.goods_num1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0){ + if(!is_showing) { + wx.showToast({ + title: '购买数量必须是起订量的倍数', + icon: 'none', + }); + } + if(t.goods_num= 2 && this_obj.selected) { var goods_id = this_obj.goods_id; - var num = 0; for (let i = 0; i < this.data.requestData.length; i++) { @@ -3257,17 +3206,15 @@ Page({ return false; } - - } } - - this.update_cart(t, pitem, item); }, + + //---检验线下库存的数量的子函数--- async check_down_line_next(t, pitem, item, erpwareid, func) { diff --git a/pages/goods/goodsInfo/goodsInfo.js b/pages/goods/goodsInfo/goodsInfo.js index aaf1f4f..f182c32 100644 --- a/pages/goods/goodsInfo/goodsInfo.js +++ b/pages/goods/goodsInfo/goodsInfo.js @@ -2444,11 +2444,14 @@ Page({ //------检查数量是不是超出限购------ checkCartNum: function (t) { var th = this; + var mo_num=getApp().get_limit_qty(th.data.sele_g,th.data.is_act); var steep=getApp().get_limit_qty(th.data.sele_g,th.data.is_act,1); - this.get_buy_num(this.data.sele_g, async function () { + var is_show_bs=0; + var l_num=-1; + //--判断商品是否超出限购-- if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { @@ -2459,13 +2462,16 @@ Page({ title: '超出商品限购', icon: 'none', }); + + is_show_bs=1; + // s.my_warnning('超出商品限购', 0, th); - var num = th.data.sele_g.viplimited - gd_buy_num; - if (num < 0) num = 0; - th.setData({ - goodsInputNum: num - }) - return false; + l_num = th.data.sele_g.viplimited - gd_buy_num; + if (l_num < 0) l_num = 0; + // th.setData({ + // goodsInputNum: num + // }) + // return false; } } @@ -2533,25 +2539,47 @@ Page({ } } + //-- 限购数量也要进行计算一下 -- + if(l_num>-1){ + if(e>l_num) e=l_num; + } + //--- 促销活动也不控制起订量, 这里很重要的一个控制,起订量的 ---- if([0,3,5,7,10].indexOf(p_type)>-1 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1){ - if(tmo_num && (t-mo_num)%steep!=0){ - wx.showToast({ - title: '购买数必须是起订量的倍数', - icon: 'none', - }); + + if(!is_show_bs){ + wx.showToast({ + title: '购买数必须是起订量的倍数', + icon: 'none', + }); + } + t=mo_num+ parseInt((t-mo_num)/steep)*steep+steep; + is_show_bs=1; } } if (!e) e = 0; //库存不足,不增加 if (e < t) { - wx.showToast({ - title: '库存不足', - icon: 'none', - }); + if(!is_show_bs){ + wx.showToast({ + title: '库存不足', + icon: 'none', + }); + } + // wx.showModal({title: '库存不足',}); if (e < 0) e = 0;