From 8834c259ac3de5c95169f31537706ea39b71bfeb Mon Sep 17 00:00:00 2001 From: taiwan Date: Tue, 15 Mar 2022 17:07:11 +0800 Subject: [PATCH] 服务卡秒杀修改 --- packageA/pages/goodsInfo/goodsInfo.js | 69 +++++++++------------------------------------------------------------ pages/cart/cart/cart.js | 146 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 149 insertions(+), 66 deletions(-) diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index ccc3613..fdd62fb 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -949,7 +949,7 @@ Page({ pick_id: th.data.sto_sele_id, user_id:oo.user_id, store_id:os.stoid, - money:th.data.data.shop_price + money:th.data.data.shop_price, }; if(getApp().globalData.guide_id) { newd['guide_id'] = getApp().globalData.guide_id; @@ -957,8 +957,11 @@ Page({ }; // 秒杀:单独购买的情况下,加入购物车显示的是零售价,否则显示秒杀活动价 if(th.data.options.prom_type == 1) { + newd['prom_type'] = th.data.options.prom_type; + newd['prom_id'] = th.data.options.prom_id; if(th.data.openSpecModal_flash_normal) { newd['money'] = th.data.data.shop_price; + newd['is_pd_normal'] = 1; } else { newd['money'] = th.data.prom_price; }; @@ -987,8 +990,11 @@ Page({ // 秒杀:单独购买的情况下,加入购物车显示的是零售价,否则显示秒杀活动价 if(th.data.options.prom_type == 1) { + // updata['prom_type'] = th.data.options.prom_type; + // updata['prom_id'] = th.data.options.prom_id; if(th.data.openSpecModal_flash_normal) { updata['money'] = th.data.data.shop_price; + updata['is_pd_normal'] = 1; } else { updata['money'] = th.data.prom_price; }; @@ -1367,7 +1373,7 @@ Page({ var url="/packageA/pages/goodsInfo/goodsInfo?goods_id=" + th.data.gid; - if(getApp().globalData.user_id){ + if(getApp().globalData.user_id) { url+="&first_leader="+getApp().globalData.user_id; } @@ -3436,63 +3442,6 @@ Page({ "function" == typeof func && func(); }; - // getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { - // data: { - // store_id: os.stoid, - // user_id: user_id, - // card_id: gd.goods_id, - // prom_type: th.data.options.prom_type, - // prom_id: th.data.options.prom_id, - // }, - // success: function (t) { - // if (t.data.code == 0) { - // // var g_buy_num = t.data.data.goodsbuynum; - - // //如果是秒杀的时候 - // // if (th.data.prom_type == 0 && gd.prom_type == 1) { - // // gd.prom_type = 0; - // // } - // // //如果全场优惠,商品做了秒杀 - // // if (th.data.prom_type == 3 && gd.prom_type == 1) { - // // gd.prom_type = 0; - // // } - // // //如果全场阶梯优惠,商品做了秒杀 - // // if (th.data.prom_type == 10 && gd.prom_type == 1) { - // // gd.prom_type = 0; - // // } - - - // if (th.data.prom_type == 1) { - // //----获取活动购买数---- - // getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { - // data: { - // store_id: os.stoid, - // user_id: user_id, - // card_id: th.data.options.goods_id, - // prom_type: th.data.options.prom_type, - // prom_id: th.data.options.prom_id - // }, - // //-----获取----- - // success: function (tt) { - // if (tt.data.code == 0) { - // // map.set(gd.goods_id, g_buy_num); - // th.setData({ - // // g_buy_num: map, - // promcardbuynum: tt.data.data.promcardbuynum, - // cardbuynum: t.data.data.cardbuynum, - // }); - // "function" == typeof func && func(); - // } - // } - // }); - // } else { - // "function" == typeof func && func(); - // }; - // } - // }, - - // }); - // } }, @@ -4059,7 +4008,7 @@ Page({ getApp().goto("/pages/cart/cart2/cart2?state=1"); } }); - } + }, }) return false; } diff --git a/pages/cart/cart/cart.js b/pages/cart/cart/cart.js index b79d639..aec62f8 100644 --- a/pages/cart/cart/cart.js +++ b/pages/cart/cart/cart.js @@ -1082,6 +1082,15 @@ Page({ id: e.id, store_id: oo.stoid }; + if(a.prom_type) { + s.prom_type = a.prom_type; + }; + if(a.prom_id) { + s.prom_id = a.prom_id; + }; + if(a.is_pd_normal) { + s.is_pd_normal = a.is_pd_normal; + }; th.postCardList_ser(s, t.currentTarget.dataset.item, t.currentTarget.dataset.pitems); } }, @@ -1098,9 +1107,19 @@ Page({ var e = { goods_num: a.goods_num + 1, id: a.id, - goods_id: a.goods_id, - store_id: oo.stoid + goods_id: a.service_id, + store_id: oo.stoid, + card_id: a.service_id, }; + if(a.prom_type) { + e.prom_type = a.prom_type; + }; + if(a.prom_id) { + e.prom_id = a.prom_id; + }; + if(a.is_pd_normal) { + e.is_pd_normal = a.is_pd_normal; + }; this.postCardList_ser(e, t.currentTarget.dataset.item, t.currentTarget.dataset.pitems); }, @@ -1987,7 +2006,7 @@ Page({ }, //----------------------更新购物数量,加减,调用接口--------------------- - postCardList_ser: function (t, item, pitem) { + postCardList_ser: async function (t, item, pitem) { var e = this, th = e; var user_id = getApp().globalData.user_id; @@ -1995,9 +2014,112 @@ Page({ e.setData({ [txt]: t.goods_num }); - e.doCheckAll(); - e.update_cart_ser(t, pitem, item); + // if(t.prom_type == 1) { + + // } else { + + + // }; + if(t.prom_type == 1) { + await e.checkCartNum(t, item, pitem); + } + + await e.doCheckAll(); + await e.update_cart_ser(t, pitem, item); + + }, + + + // 检查购物车数量 + async checkCartNum(t, item, pitem) { + var th = this; + if(t.is_pd_normal) return false; + if (t.prom_type == 1) { + var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num"; + var redis_num = 0; + //------判断活动是否抢光----- + // await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + + // t.store_id + "/" + t.prom_type + "/" + t.prom_id, { + // 1: 1 + // }).then(res => { + // redis_num = res.data.data; + // if(redis_num == 0) { + // wx.showModal({ + // title: '来晚了,已被抢光~', + // }); + // return false; + // }; + // if(t.goods_num > redis_num) { + // wx.showModal({ + // title: '超出商品活动限购数量2', + // // title: '来晚了,已被抢光~', + // }); + // // th.setData({goodsInputNum: redis_num}) + // return false; + // }; + // }); + + + + //----获取活动购买数---- + await getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { + data: { + store_id: t.store_id, + user_id: getApp().globalData.user_id, + card_id: t.goods_id, + prom_type: t.prom_type, + prom_id: t.prom_id + }, + //-----获取----- + success: function (tt) { + if (tt.data.code == 0) { + th.setData({ + promcardbuynum: tt.data.data.promcardbuynum, + cardbuynum: tt.data.data.cardbuynum, + }); + }; + }, + + }); + + + + await getApp().request.get("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, { + success: function (res) { + if(res.data.code == 0) { + th.data.sele_g = res.data.data; + th.data.sele_g.viplimited = res.data.data.buy_limit; + //--秒杀:判断商品是否超出活动限购-- + if (th.data.sele_g.viplimited > 0) { + var gd_buy_num = th.data.promcardbuynum; + + if (t.goods_num + gd_buy_num> th.data.sele_g.viplimited) { + wx.showModal({ + title: '超出活动限购数量', + }); + + var num = th.data.sele_g.viplimited - gd_buy_num; + if (num <= 0) num = 1; + + th.setData({ + [txt]: num, + gdnum: num, + }); + t.goods_num = num; + th.doCheckAll(); + th.update_cart_ser(t, pitem, item); + // return false; + } + }; + + }; + }, + }); + + + }; + }, @@ -2117,6 +2239,10 @@ Page({ //--更新购物车--- update_cart_ser: function (t, pitem, item) { var e = this; + // if(t.prom_type == 1) { + // t.goods_num = e.data.gdnum; + // } + console.log('t===>', t); getApp().request.put("/api/weshop/cartService/update", { data: t, success: async function (ee) { @@ -2876,6 +3002,14 @@ Page({ getApp().goto(good_url); } }) - } + }, + + + + + + + + }); \ No newline at end of file -- libgit2 0.21.4