diff --git a/packageB/pages/zuhegou/index/index.js b/packageB/pages/zuhegou/index/index.js index 004cc57..cc1ecde 100644 --- a/packageB/pages/zuhegou/index/index.js +++ b/packageB/pages/zuhegou/index/index.js @@ -531,6 +531,9 @@ Page({ this.data.sele_g = this.data.list[index]; this.data.sele_index=index; th.data.goodsInputNum = this.data.sele_g.num + 1; + if(this.data.sele_g.cart_num){ + th.data.s_cart_num = this.data.sele_g.cart_num + 1; + } th.add_cart_func(); }, @@ -566,6 +569,7 @@ Page({ th.data.sele_g = item; th.data.sele_index = index; th.data.goodsInputNum = check_num; + th.data.s_cart_num = this.data.sele_g.cart_num - 1; th.sub_updata_cart(); return false; } @@ -767,9 +771,11 @@ Page({ //-- 加入购物的函数 -- add_cart_func: function () { if (oo.user_id == null) { + this.data.changing=0; return getApp().my_warnning("还未登录!", 0, this); } if (!getApp().globalData.userInfo) { + this.data.changing=0; return getApp().my_warnning("还未登录!", 0, this); } @@ -782,31 +788,48 @@ Page({ e.get_buy_num(o, function (ee) { //---判断商品是否超出限购--- if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { - if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id) > th.data.sele_g.viplimited) { + if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id).gd_buynum > th.data.sele_g.viplimited) { wx.showModal({ title: '提示', content: '超出商品限购' }); + th.data.changing=0; return false; } + if(th.data.s_cart_num){ + if (th.data.s_cart_num + th.data.g_buy_num.get(th.data.sele_g.goods_id).gd_buynum > th.data.sele_g.viplimited) { + wx.showModal({ + title: '提示', + content: '超出商品限购' + }); + th.data.changing=0; + return false; + } + } + } //---判断商品是否超出活动限购--- if (th.data.sele_g.buyqty > 0) { - if (th.data.goodsInputNum > th.data.sele_g.buyqty) { + if (th.data.goodsInputNum+ th.data.g_buy_num.get(th.data.sele_g.goods_id).prom_buybum > th.data.sele_g.buyqty) { wx.showModal({ title: '提示', content: '超出商品活动限购' }); + th.data.changing=0; return false; } } - if (th.data.goodsInputNum <= 0) return s.my_warnning("商品数量不能为0", 0, th); + if (th.data.goodsInputNum <= 0){ + this.data.changing=0;return s.my_warnning("商品数量不能为0", 0, th); + } if (th.data.sto_sele_name == null || th.data.sto_sele_name == undefined) this.setData({ sto_sele_name: "" }); - if (th.data.sto_sele_name == "") return s.my_warnning("请选择门店", 0, th); + if (th.data.sto_sele_name == "") { + th.data.changing=0;return s.my_warnning("请选择门店", 0, th); + } //--------------此时操作的数据------------ var newd = { @@ -843,8 +866,12 @@ Page({ if (newd.goods_id == getApp().globalData.room_goods_id) newd.room_id = getApp().globalData.room_id; } - if (o.store_count <= 0) return getApp().my_warnning("库存已为空!", 0, th); - if (o.store_count < e.data.goodsInputNum) return getApp().my_warnning("库存不足!", 0, th); + if (o.store_count <= 0){ + th.data.changing=0;return getApp().my_warnning("库存已为空!", 0, th); + } + if (o.store_count < e.data.goodsInputNum){ + th.data.changing=0;return getApp().my_warnning("库存不足!", 0, th); + } th.add_cart_next(o, newd); //加入购物车下一步 }) @@ -881,11 +908,11 @@ Page({ th.data.adding = 0; return getApp().my_warnning("库存不足!", 0, th); } - if (th.data.goodsInputNum > o.buyqty && o.buyqty>0) { + if (th.data.goodsInputNum+ th.data.g_buy_num.get(th.data.sele_g.goods_id).prom_buybum > o.buyqty && o.buyqty>0) { th.data.adding = 0; return getApp().my_warnning("超出商品活动限购!", 0, th); } - if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id) > th.data.sele_g.viplimited + if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.sele_g.goods_id).prom_buybum > th.data.sele_g.viplimited && th.data.sele_g.viplimited > 0 ) { th.data.adding = 0; @@ -900,7 +927,9 @@ Page({ member_goods_price: newd.goods_price, store_id: os.stoid, }; - + if(th.data.s_cart_num){ + updata.goods_num=th.data.s_cart_num; + } //---是不是从收藏夹出来的--- if (th.data.c_guide_id) { updata['guide_id'] = th.data.c_guide_id; @@ -915,7 +944,7 @@ Page({ data: updata, success: function (t) { th.setData({ - [txt1]: updata.goods_num, + [txt1]: th.data.goodsInputNum, [txt2]: true, [txt]: true, [txt3]: newd.goods_price, @@ -925,8 +954,6 @@ Page({ th.re_sum_price();//重新统计数量和总金额 } }); - - } else { getApp().request.post("/api/weshop/cart/save", { @@ -1287,7 +1314,6 @@ Page({ } else { item = th.data.only_pk[index]; //当没有门店分类的时候 } - } else { var index = th.data.sec_pick_index; item = th.data.sec_sto.s_arr[index]; @@ -1437,25 +1463,36 @@ Page({ if (map && map.has(gd.goods_id)) { "function" == typeof func && func(); } else { + var res1=null; //----获取商品购买数---- - getApp().request.get("/api/weshop/ordergoods/getUserBuyGoodsNum", { + getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { data: { store_id: os.stoid, user_id: user_id, - goods_id: gd.goods_id + goods_id: gd.goods_id, + prom_type: gd.prom_type, + prom_id: gd.prom_id }, - success: function (t) { - if (t.data.code == 0) { - var g_buy_num = t.data.data.goodsbuynum; - if (!map) map = new Map(); - map.set(gd.goods_id, g_buy_num); - th.setData({ - g_buy_num: map - }); - "function" == typeof func && func(); - } + }).then(res2=>{ + var g_buy_num=0; + var promgoodsbuynum=0; + if (res2.data.code == 0) { + var buy_num_data = res2.data.data; + if (buy_num_data.promgoodsbuynum) promgoodsbuynum = buy_num_data.promgoodsbuynum; + g_buy_num = buy_num_data.goodsbuynum; } - }); + + if (!map) map = new Map(); + var ob={ + gd_buynum:g_buy_num, + prom_buybum:promgoodsbuynum, + } + map.set(gd.goods_id, ob); + th.setData({ + g_buy_num: map + }); + "function" == typeof func && func(); + }) } }, @@ -1477,6 +1514,11 @@ Page({ goods_price: cur_price, store_id: os.stoid, }; + + if(th.data.s_cart_num){ + updata.goods_num=th.data.s_cart_num; + } + //---是不是从收藏夹出来的--- if (th.data.c_guide_id) { updata['guide_id'] = th.data.c_guide_id; @@ -1496,7 +1538,6 @@ Page({ [txt2]: true, [txt]: true, }); - th.data.adding = 0; th.data.sele_store = 1; th.re_sum_price();//重新统计数量和总金额 @@ -1525,6 +1566,7 @@ Page({ var txt2 = "list[" + index + "].showNum"; var txt3 = "list[" + index + "].cart_id"; var txt4 = "list[" + index + "].current_price"; + var txt5 = "list[" + index + "].cart_num"; //----先看会员在购物车中是否加入了该商品----- getApp().request.get("/api/weshop/cart/page", { @@ -1537,39 +1579,89 @@ Page({ success: function (re) { if (re.data.data.total > 0) { var item = re.data.data.pageData[0]; + th.get_buy_num(th.data.sele_g,function () { + //当前的价格要更新进去 + var cur_price = th.data.sele_g.shop_price; + if (th.data.card_field && th.data.sele_g[th.data.card_field]) { + cur_price = th.data.sele_g[th.data.card_field]; + } - //当前的价格要更新进去 - var cur_price = th.data.sele_g.shop_price; - if (th.data.card_field && th.data.sele_g[th.data.card_field]) { - cur_price = th.data.sele_g[th.data.card_field]; - } + var prom_buybum=0; + var gd_buynum=0; + //加入也要控制一下限购 + var check_obj=th.data.g_buy_num.get(th.data.sele_g.goods_id); + if(check_obj.gd_buynum && check_obj.gd_buynum>0) gd_buynum=check_obj.gd_buynum; + if(check_obj.prom_buybum && check_obj.prom_buybum>0) prom_buybum=check_obj.prom_buybum; + + if(check_obj){ + if(check_obj.prom_buybum && check_obj.prom_buybum>th.data.sele_g.buyqty && + th.data.sele_g.buyqty>0 + ){ + wx.showToast({ + title: "您的已购数量超出活动的限购", + icon: 'none', + duration: 2000 + }); + return false; + } + if(check_obj.gd_buynum && check_obj.gd_buynum>th.data.sele_g.viplimited && + th.data.sele_g.viplimited>0 + ){ + wx.showToast({ + title: "您的已购数量超出商品的限购", + icon: 'none', + duration: 2000 + }); + return false; + } + } - th.setData({ - [txt1]: item.goods_num, - [txt2]: true, - [txt]: true, - [txt3]: item.id, - [txt4]: cur_price, - }); + item.cbuy=-1; + var cbuy=th.data.sele_g.viplimited>0?th.data.sele_g.viplimited-gd_buynum:-1; + if(cbuy>-1) item.cbuy=cbuy; + var cbuy2=th.data.sele_g.buyqty>0?th.data.sele_g.buyqty-prom_buybum:-1; + if(cbuy2>-1){ + if(item.cbuy==-1 || item.cbuy>cbuy2) item.cbuy=cbuy2; + } - var updata = { - id: item.id, - prom_type: 7, - goods_price: cur_price, - prom_id: th.data.act.id - }; - if (getApp().globalData.guide_id) { - updata['guide_id'] = getApp().globalData.guide_id; - updata['guide_type'] = 0; - } + var num=item.goods_num; + if(item.cbuy>-1 && item.cbuy-1){ + th.setData({ + [txt5]: item.cbuy, + }); } - }); - th.re_sum_price(); + var updata = { + id: item.id, + prom_type: 7, + goods_price: cur_price, + prom_id: th.data.act.id + }; + if (getApp().globalData.guide_id) { + updata['guide_id'] = getApp().globalData.guide_id; + updata['guide_type'] = 0; + } + + getApp().request.put("/api/weshop/cart/update", { + data: updata, + success: function (t) { + } + }); + th.re_sum_price(); + }) + } else { func(); } @@ -1627,7 +1719,7 @@ Page({ } //看一下剩下的数量有没有满足组合购的要求,以及要不要倍增 - if (this.data.act.is_bz && no_in_arr.length >= this.data.act.zhbuyqty) { + if (this.data.act.is_bz && no_in_arr.length > this.data.act.zhbuyqty) { //看一下是几倍 var be = parseInt(no_in_arr.length / this.data.act.zhbuyqty); aprice += be * aprice; diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 51f182b..7e212fd 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -1240,7 +1240,11 @@ Page({ }, }).then(res => { var buy_num_data = res.data.data; - if (buy_num_data.promgoodsbuynum) promgoodsbuynum = buy_num_data.promgoodsbuynum; + if (buy_num_data.promgoodsbuynum) { + promgoodsbuynum = buy_num_data.promgoodsbuynum; + var txt="requestData[" + pitem + "].goods[" + item + "].zh_b_num"; + th.setData({[txt]:promgoodsbuynum}); + } goodsbuynum = buy_num_data.goodsbuynum; }) diff --git a/pages/cart/cart/zh_calculate.js b/pages/cart/cart/zh_calculate.js index 8c2c01c..6eabebb 100644 --- a/pages/cart/cart/zh_calculate.js +++ b/pages/cart/cart/zh_calculate.js @@ -51,7 +51,7 @@ module.exports = { } }, - //把组合购的商品价格计算出来 + //把组合购的商品价格计算出来,同时每个会员都有购买组合商品的上限!zh_b_num是已经购买了多少件 calculate_zh: function(car, a, th) { var car_item = car[a]; var tfeel = 0, @@ -81,6 +81,7 @@ module.exports = { var need_to_buy = 0; var all_zhqty = 0; //所有商品要求起购数之和 var no_in_arr = []; //剩余的未加入组合购 + var out_arr=[]; //超出活动限购的商品放入 var title =""; //提示语; //var goods = bitem.goods; @@ -109,7 +110,36 @@ module.exports = { for (var i in goods) { var item = goods[i]; - item.num = get_num(item).goods_num; + item.goods_price=get_num(item).goods_price; + item.offline_price=get_num(item).offline_price; + var cart_num=get_num(item).goods_num; + var zh_b_num=get_num2(item).zh_b_num; + + //-- 当商品有购买的时候,以及有限购的时候 -- + if(zh_b_num>0 && item.buyqty>0){ + + var cbuy=item.buyqty-zh_b_num; + //当可买的数量为0 + if(cbuy<=0){ + item.num=0; + out_arr.push({ + price: item.goods_price,offline_price:item.offline_price,goods_id:item.goods_id,num:cart_num + }) + }else{ + if(cbuy>=cart_num) item.num =cart_num; + else{ + item.num =cbuy; + out_arr.push({ + price: item.goods_price,offline_price:item.offline_price,goods_id:item.goods_id,num:cart_num-cbuy + }) + } + } + + }else{ + item.num =cart_num; + } + + item.goods_price=get_num(item).goods_price; item.offline_price=get_num(item).offline_price; @@ -166,8 +196,6 @@ module.exports = { no_in_arr.pop(); } } - - //算一下剩余的钱 if (no_in_arr.length) { for (var ii in no_in_arr) { @@ -188,6 +216,31 @@ module.exports = { } } } + + //超量的部分也要计算一下 + if(out_arr.length){ + for (var m in out_arr) { + var item = out_arr[m]; + var gitem=get_num2(item); + if(gitem) { + if (!gitem.need_downlow_num) { + gitem.need_downlow_num = item.num; + } + else { + gitem.need_downlow_num+=item.num; + } + aprice += item.price*item.num; + if (item.offline_price) { + offline_price += (item.goods_price - item.offline_price)*item.num; + offline_num += item.num; + } + + } + } + } + + + all_price = aprice; //-- 设置还需要购买多少件,享受活动,前段显示 -- @@ -254,7 +307,6 @@ module.exports = { console.log('nyf111'); console.log(car_item); - var res = { tfeel: tfeel, offline_price: offline_price,