diff --git a/packageB/pages/zuhegou/index/index.js b/packageB/pages/zuhegou/index/index.js index cc1ecde..82834e8 100644 --- a/packageB/pages/zuhegou/index/index.js +++ b/packageB/pages/zuhegou/index/index.js @@ -472,34 +472,61 @@ Page({ var txt2 = "list[" + index + "].showNum"; th.data.sele_g = this.data.list[index]; - wx.showModal({ title: '温馨提示', - content: '确定将该商品移出购物车?', + content: "确定取消该商品参与活动?", success (res) { if (res.confirm) { console.log('用户点击确定'); + if(th.data.sele_g.cart_num){ - var url = '/api/weshop/cart/del/' + os.stoid + '/' + th.data.sele_g.cart_id; - getApp().request.delete(url, { - success:function (res) { - - if(res.data.code==0) { - title = '移除购物车成功'; - th.setData({ - [txt1]: 1, - [txt2]: false, - [txt]: false, - }); - wx.showToast({ - title: title, - icon: 'success', - }); - - th.re_sum_price(); - } + var updata = { + id: th.data.sele_g.cart_id, + goods_num: th.data.sele_g.cart_num - th.data.sele_g.num, + store_id: os.stoid } - }); + getApp().request.put("/api/weshop/cart/update", { + data: updata, + success:function (rs) { + if(rs.data.code==0) { + title = '取消成功'; + th.setData({ + [txt1]: 0, + [txt2]: false, + [txt]: false, + }); + wx.showToast({ + title: title, + icon: 'success', + }); + th.re_sum_price(); + } + } + }) + + }else{ + var url = '/api/weshop/cart/del/' + os.stoid + '/' + th.data.sele_g.cart_id; + getApp().request.delete(url, { + success:function (res) { + + if(res.data.code==0) { + title = '取消成功'; + th.setData({ + [txt1]: 0, + [txt2]: false, + [txt]: false, + }); + wx.showToast({ + title: title, + icon: 'success', + }); + + th.re_sum_price(); + } + } + }); + } + } else if (res.cancel) { console.log('用户点击取消') self.setData({ @@ -551,6 +578,7 @@ Page({ var index = e.currentTarget.dataset.index; var item = this.data.list[index]; let num = item.num; + th.data.s_cart_num = this.data.sele_g.cart_num - 1; if (num >= 2) { var check_num = num - 1; @@ -569,7 +597,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; } @@ -580,27 +608,54 @@ Page({ wx.showModal({ title: '温馨提示', - content: '确定将该商品移出购物车?', + content: '确定取消该商品参与活动?', success (res) { if (res.confirm) { - var url = '/api/weshop/cart/del/' + os.stoid + '/' + item.cart_id; - getApp().request.delete(url, { - success:function (res) { - if(res.data.code==0) { - var title = '移除购物车成功'; - th.setData({ - [txt1]: 1, - [txt2]: false, - [txt]: false, - }); - wx.showToast({ - title: title, - icon: 'success', - }); - th.re_sum_price();//重新统计数量和总金额 - } + + if(th.data.s_cart_num){ + var updata = { + id: th.data.sele_g.cart_id, + goods_num:h.data.s_cart_num , + store_id: os.stoid } - }); + getApp().request.put("/api/weshop/cart/update", { + data: updata, + success:function (rs) { + if(rs.data.code==0) { + var title = '取消成功'; + th.setData({ + [txt1]: 0, + [txt2]: false, + [txt]: false, + }); + wx.showToast({ + title: title, + icon: 'success', + }); + th.re_sum_price(); + } + } + }) + }else { + var url = '/api/weshop/cart/del/' + os.stoid + '/' + item.cart_id; + getApp().request.delete(url, { + success: function (res) { + if (res.data.code == 0) { + var title = '移除购物车成功'; + th.setData({ + [txt1]: 1, + [txt2]: false, + [txt]: false, + }); + wx.showToast({ + title: title, + icon: 'success', + }); + th.re_sum_price();//重新统计数量和总金额 + } + } + }); + } } else if (res.cancel) { console.log('用户点击取消') @@ -844,6 +899,10 @@ Page({ goods_sn: o.goods_sn, }; + if(th.data.s_cart_num){ + newd.goods_num=th.data.s_cart_num; + } + //---是不是从收藏夹出来的--- if (th.data.c_guide_id) { newd['guide_id'] = th.data.c_guide_id; @@ -951,6 +1010,12 @@ Page({ }); th.data.adding = 0; th.data.sele_store = 1; + + if(th.data.s_cart_num){ + var txt_temp = "list[" + index + "].cart_num"; + th.setData({[txt_temp]:th.data.s_cart_num}) + } + th.re_sum_price();//重新统计数量和总金额 } }); @@ -1470,8 +1535,8 @@ Page({ store_id: os.stoid, user_id: user_id, goods_id: gd.goods_id, - prom_type: gd.prom_type, - prom_id: gd.prom_id + prom_type: 7, + prom_id: th.data.act.id }, }).then(res2=>{ var g_buy_num=0; @@ -1540,6 +1605,11 @@ Page({ }); th.data.adding = 0; th.data.sele_store = 1; + if(th.data.s_cart_num){ + var txt_temp = "list[" + index + "].cart_num"; + th.setData({[txt_temp]:th.data.s_cart_num}) + } + th.re_sum_price();//重新统计数量和总金额 } }); @@ -1594,7 +1664,7 @@ Page({ 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 && + if(check_obj.prom_buybum && check_obj.prom_buybum>=th.data.sele_g.buyqty && th.data.sele_g.buyqty>0 ){ wx.showToast({ @@ -1604,7 +1674,7 @@ Page({ }); return false; } - if(check_obj.gd_buynum && check_obj.gd_buynum>th.data.sele_g.viplimited && + if(check_obj.gd_buynum && check_obj.gd_buynum>=th.data.sele_g.viplimited && th.data.sele_g.viplimited>0 ){ wx.showToast({ @@ -1616,12 +1686,12 @@ Page({ } } - 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; + item.cbuy='no'; + var cbuy=th.data.sele_g.viplimited>0?th.data.sele_g.viplimited-gd_buynum:'no'; + if(cbuy!='no') item.cbuy=cbuy; + var cbuy2=th.data.sele_g.buyqty>0?th.data.sele_g.buyqty-prom_buybum:'no'; + if(cbuy2!='no'){ + if(item.cbuy=='no' || item.cbuy>cbuy2) item.cbuy=cbuy2; } var num=item.goods_num; @@ -1637,17 +1707,12 @@ Page({ [txt5]: item.goods_num, }); - if(item.cbuy>-1){ - th.setData({ - [txt5]: item.cbuy, - }); - } - var updata = { id: item.id, prom_type: 7, goods_price: cur_price, - prom_id: th.data.act.id + prom_id: th.data.act.id, + store_id: os.stoid, }; if (getApp().globalData.guide_id) { updata['guide_id'] = getApp().globalData.guide_id; diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index 7e212fd..1bf18f6 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -198,6 +198,7 @@ Page({ get_cart: function() { var th = this; var rd = Math.random().toString(36).substr(2, 15); + var user_id=getApp().globalData.userInfo.user_id; getApp().request.get("/api/weshop/cart/list", { data: { user_id: app.globalData.user_id, @@ -249,6 +250,40 @@ Page({ //商品已经下架 continue; } + var goodsbuynum=0,promgoodsbuynum=0,limit=0; + + //--要获得商品,该用户买了多少件,同步应用-- + await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { + data: { + store_id: oo.stoid, + user_id: user_id, + goods_id: item.goods_id, + prom_type: item.prom_type, + prom_id: item.prom_id + }, + }).then(res => { + var buy_num_data = res.data.data; + if (buy_num_data.promgoodsbuynum) { + promgoodsbuynum = buy_num_data.promgoodsbuynum; + } + goodsbuynum = buy_num_data.goodsbuynum; + }) + limit=good.viplimited; + //判断商品的限购 + if(item.goods_num+goodsbuynum>limit && limit>0){ + var cbuy=limit-goodsbuynum; + if(cbuy<=0){ + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; + a.delete(url, {}); + continue; + } + //-- 购物车更新 -- + var updata1={id: item.id,goods_num:cbuy }; + getApp().request.put("/api/weshop/cart/update", { + data: updata1, + }) + item.goods_num=cbuy; + } //如果秒杀活动都去掉了,或者结束了,那么这个商品也没有必要留着 if (item.prom_type == 1) { @@ -266,6 +301,22 @@ Page({ //商品已经下架 continue; } + + //判断秒杀的限购 + if(item.goods_num+promgoodsbuynum>prom.buy_limit && prom.buy_limit>0){ + var cbuy=prom.buy_limit-promgoodsbuynum; + if(cbuy<=0){ + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id; + a.delete(url, {}); + continue; + } + //-- 购物车更新 -- + var updata1={id: item.id,goods_num:cbuy }; + getApp().request.put("/api/weshop/cart/update", { + data: updata1, + }) + item.goods_num=cbuy; + } } //--判断优惠活动有没有过期-- else if (item.prom_type == 3) { @@ -330,6 +381,25 @@ Page({ getApp().request.delete(url, {}); continue; } + item.zh_b_num=promgoodsbuynum; + + var url1 = "/api/weshop/prom/zhbuyGoods/page"; + var req_data = { + page: 1, + pageSize: 2000, + store_id: os.stoid, + zh_id: item.prom_id, + goods_id:item.goods_id + } + await getApp().request.promiseGet(url1, { + data: req_data + }).then(res => { + if (ut.ajax_ok(res)) { + gdlist = res.data.data.pageData[0]; + item.buyqty=gdlist.buyqty; + } + }) + } else if(item.prom_type == 0) { //如果有优惠活动,要更新活动 @@ -348,6 +418,7 @@ Page({ }) } + all_num += item.goods_num; item.original_img = oo.imghost + item.original_img; item.selected = 0; diff --git a/pages/cart/cart/cart.wxml b/pages/cart/cart/cart.wxml index 50880fc..2b64fb4 100644 --- a/pages/cart/cart/cart.wxml +++ b/pages/cart/cart/cart.wxml @@ -88,12 +88,14 @@ 物流 - + - 还需购买{{items.zhqty-items.goods_num}}件 + + 活动剩余可购{{items.buyqty-items.zh_b_num>0?items.buyqty-items.zh_b_num:0}}件 + 还需购买{{items.zhqty-items.goods_num}}件 - 需购买{{items.zhqty}}件 + 需购买{{items.zhqty}}件 @@ -106,7 +108,7 @@ {{items.goods_color}}{{items.goods_color?"/":''}}{{items.goods_spec}} - 规格1 + 规格1{{items.buyqty}}--{{items.zh_b_num}} {{items.goods_num}}件 diff --git a/pages/cart/cart/zh_calculate.js b/pages/cart/cart/zh_calculate.js index 6eabebb..c160205 100644 --- a/pages/cart/cart/zh_calculate.js +++ b/pages/cart/cart/zh_calculate.js @@ -115,6 +115,7 @@ module.exports = { var cart_num=get_num(item).goods_num; var zh_b_num=get_num2(item).zh_b_num; + item.cart_num =cart_num; //-- 当商品有购买的时候,以及有限购的时候 -- if(zh_b_num>0 && item.buyqty>0){ @@ -139,13 +140,14 @@ module.exports = { item.num =cart_num; } - item.goods_price=get_num(item).goods_price; item.offline_price=get_num(item).offline_price; - + if(item.cart_num){ + all_price += item.cart_num * item.goods_price; + } if (item.num) { all_num += item.num; - all_price += item.num * item.goods_price; + //当有起购数的控制的时候 if (item.zhqty) { all_zhqty += item.zhqty; diff --git a/pages/cart/cart2/cart2.js b/pages/cart/cart2/cart2.js index 2a28349..8a327e2 100644 --- a/pages/cart/cart2/cart2.js +++ b/pages/cart/cart2/cart2.js @@ -940,8 +940,8 @@ Page({ //计算价格 th.calculatePrice2(); - //获取优惠券 - th.get_buy_now_quan(); + //获取优惠券,如果有券的钱,就调用 + if(th.data.ckeck_quan_price>0) th.get_buy_now_quan(); } }); @@ -1259,7 +1259,7 @@ Page({ o_price_no_zh += item[j].goods_price * item[j].goods_num; } //组合购的商品,且没有订单优惠的叠加,is_orderyh就是优惠叠加 - if(zh_prom_goods[item[j].prom_id] && !zh_prom_goods[item[j].prom_id].act.is_orderyh ) + if(zh_prom_goods && zh_prom_goods[item[j].prom_id] && !zh_prom_goods[item[j].prom_id].act.is_orderyh ) { o_price_no_zh += item[j].goods_price * item[j].goods_num; } @@ -1273,7 +1273,7 @@ Page({ o_price_no_zh-=c_arr[i].cut_price; } //如果有组合购优惠的钱,就要减价 - if (c_arr[i].zh_cut_price > 0){ + if (c_arr[i].zh_cut_price>0 || c_arr[i].zh_cut_price<0){ o_price -= c_arr[i].zh_cut_price; if(o_price_no_zh>0){ //找到那些可以订单优惠叠加的 diff --git a/pages/cart/cart2/cart2.wxml b/pages/cart/cart2/cart2.wxml index 227ee14..c20f022 100644 --- a/pages/cart/cart2/cart2.wxml +++ b/pages/cart/cart2/cart2.wxml @@ -428,7 +428,7 @@ - ¥ {{filters.toFix(formData.cut_price,2)}}元 - + 组合购优惠 - ¥ {{filters.toFix(formData.zh_cut_price,2)}}元