From c4d1d430c72973811c707f485d43d7650c2b69a9 Mon Sep 17 00:00:00 2001 From: banche Date: Tue, 22 Mar 2022 19:02:28 +0800 Subject: [PATCH] 修改商品详情 --- packageA/pages/goodsInfo/goodsInfo.js | 547 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 1 file changed, 249 insertions(+), 298 deletions(-) diff --git a/packageA/pages/goodsInfo/goodsInfo.js b/packageA/pages/goodsInfo/goodsInfo.js index 5294c44..894dc15 100644 --- a/packageA/pages/goodsInfo/goodsInfo.js +++ b/packageA/pages/goodsInfo/goodsInfo.js @@ -447,7 +447,7 @@ Page({ sto_sele_name: e.pickup_name, sto_sele_id: e.pickup_id, sto_sele_distr: e.distr_type, - sto_sele_keyid:e.keyid, + sto_sele_keyid:e.keyid, }) } } @@ -562,6 +562,9 @@ Page({ // <---- 秒杀 + + + @@ -826,21 +829,7 @@ Page({ }); }, - //获取redis中的数量 - async getactLen(func) { - var r_num = 0, - prom_type = this.data.prom_type, - prom_id = this.data.prom_id; - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { - 1: 1 - }).then(res => { - var em = res; - if (em.data.code == 0) { - r_num = em.data.data; - } - }) - func(r_num); - }, + //------------加入购物车-------------- addCart: async function(t) { @@ -848,8 +837,7 @@ Page({ var ind = t.currentTarget.dataset.openSpecModal_ind; var action= t.currentTarget.dataset.action; if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; - // 活动ID - var prom_id = th.data.prom_id; + th.setData({ open_ind_store: ind }); @@ -859,127 +847,99 @@ Page({ return false; }; - // 秒杀活动 - if(this.data.prom_type == 1) { - - this.data.sele_g.viplimited = this.data.sele_g.buy_limit; - - // 每人最大限购数 - th.data.sele_g.viplimited = th.data.sele_g.buy_limit; - - //----获取用户活动购买数---- - // 已经付款的单数,已经成功购买的数量 - var gd_buy_num = 0; - await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+os.stoid+"&user_id="+getApp().globalData.user_id+"&card_id="+th.data.options.goods_id+"&prom_type="+th.data.options.prom_type+"&prom_id="+th.data.options.prom_id, { - }).then(res => { - gd_buy_num = !res.data.data.promcardbuynum ? 0 : res.data.data.promcardbuynum; - }); - - - // 检查redis库存量 - var redisNum = 0; - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { - if (res.data.code == 0) { - redisNum = !res.data.data ? 0 : res.data.data; - }; - }); - - - // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程 - // 没有库存,已抢光的情况下,走正常购买流程 - if(redisNum > 0 && !this.data.is_normal) { - // 输入的数量 - var t = th.data.goodsInputNum; - // 获取购物车同款数量 - var cartGoodsNum = 0; - - // 购物车 - if (action != "buy") { - await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+os.stoid+"&user_id="+oo.user_id+"&service_id="+th.data.data.id, - { }).then(res => { - if (res.data.data.pageData.length > 0) { - const tmpObj = res.data.data.pageData; - - tmpObj.forEach(v => { - cartGoodsNum += parseInt(v.goods_num); - }); - - } - - }); + + // 秒杀活动 + if(this.data.prom_type == 1) { + // 如果是秒杀活动下的单独购买,is_normal为1 + if(this.data.openSpecModal_flash_normal) this.data.is_normal = 1; + + if(!this.data.is_normal) {// 秒杀购买 + + // 获取redis当前可以购买的数量 + // 如果数量为0,设置和显示已抢光 + // 否则,进一步判断是否超出限购或超出库存 + await this.getactLen().then(async function(res) { + let curNum = th.data.goodsInputNum; + // res: redis可购买数量 + console.log('当前可以购买的数量:', res); + if(res <= 0) { + // 可购买数量<=0, 设置和显示已抢光 + th.setData({ + prom_r_null: 1, + }); + wx.showModal({ + title: '超出活动库存', + }); + return false; + } else { + // 可购买数量>0 + // 计算自己还可以购买的数量 + // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b + // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存 + // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购 + let actInfo = th.data.sele_g; + await th.get_buy_num2().then(function (data) { + let limited = actInfo.buy_limit; // 限购数量a + let promcardbuynum = data.data.data.promcardbuynum; + let buyedNum = promcardbuynum; // 自己已经购买的数量b + let canBuyNum = limited - buyedNum; // 自己还可购买的数量c - // 输入的数量 + 购物车同款商品的数量 - t = parseInt(t) + parseInt(cartGoodsNum); - } - - // 剩余购买数量 - let num = th.data.sele_g.viplimited - gd_buy_num; - num = num < 0 ? 0 : num; - - if (t > redisNum) { - wx.showToast({ + if(canBuyNum <= 0) { + canBuyNum = 0; + }; + + if(limited > res) { + if(curNum > res) { // t当前增减的数量 + wx.showModal({ title: '超出活动库存', - icon: 'none' - }); - - // 开启限购 - if (th.data.sele_g.viplimited > 0) { - - if (action != "buy") { - if (t > num) { - th.setData({goodsInputNum: num - cartGoodsNum < 0 ? 0 : num - cartGoodsNum}); - } - if (redisNum < num) { - th.setData({goodsInputNum: redisNum - cartGoodsNum < 0 ? 0 : redisNum - cartGoodsNum}); - } - } else { - if (num > redisNum) { - th.setData({goodsInputNum: redisNum}); - } else { - th.setData({goodsInputNum: num}); - } - } - - - - - } else { - th.setData({goodsInputNum: redisNum}); - } - - return false; - } - - // 以下小于等于库存 - if (t <= redisNum) { - if (th.data.sele_g.viplimited > 0) { - - if (t > num) { - wx.showToast({ - title: '超出活动限购数量', - icon: 'none' - }); - - if (num > redisNum) { - th.setData({goodsInputNum: redisNum}); - } else { - th.setData({goodsInputNum: num}); - } - return false; - } - - } - } + }); + th.setData({ + goodsInputNum: res, + }); + return false; + }; + }; - + if(limited <= res) { + if(curNum > limited) { + wx.showModal({ + title: '超出限购数量', + }); + th.setData({ + goodsInputNum: canBuyNum, + }); + return false; + }; + }; + + + }); + + + }; + }); + }; + }; + + + + + + + + + + + + - if(action=="buy"){ // 立即购买 + if(action=="buy"){ //--------------此时操作的数据------------ var newd = { id: th.data.data.id, @@ -1001,30 +961,14 @@ Page({ newd['prom_type'] = 0; newd['prom_price'] = this.data.data.shop_price; }; - - // 判断是否为0库存的情况 - var tmpRedisNum = 0; - // 检查redis库存量 - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { - if (res.data.code == 0) { - tmpRedisNum = res.data.data; - }; - }); - if(this.data.prom_type == 1 && tmpRedisNum == 0) { - newd['prom_type'] = 0; - newd['prom_price'] = this.data.data.shop_price; - }; // console.log('newd++++++++', newd); th.buyNow(newd); - } else { // 购物车 + } else { + - // 购买数量大于0的才能加入到购物车 - if (th.data.goodsInputNum <= 0) { - th.closeSpecModal(); - return false; - } - + + var newd = { service_id: th.data.data.id, service_sn:th.data.data.service_sn, @@ -1050,19 +994,7 @@ Page({ newd['money'] = th.data.prom_price; }; }; - - // 判断是否为0库存的情况 - var tmpRedisNum = 0; - // 检查redis库存量 - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { - if (res.data.code == 0) { - tmpRedisNum = res.data.data; - }; - }); - if(th.data.options.prom_type == 1 && tmpRedisNum == 0) { - newd['prom_type'] = 0; - newd['money'] = th.data.data.shop_price; - }; + //----先看会员在购物车中是否加入了该商品----- getApp().request.get("/api/weshop/cartService/page", { @@ -1159,142 +1091,121 @@ Page({ }, //------检查数量是不是超出限购------ - checkCartNum: function(t) { + checkCartNum: async function(t) { + var th = this; - if(this.data.prom_type != 1) { - this.setData({goodsInputNum: t}); - return false; + if(!th.data.def_pick_store) { + wx.showModal({title: '请选择门店',}); + return false; }; - var th = this; - - // if(this.data.prom_act.is_shop_buy && this.data.options.prom_type != 1) { - - if(t == 0) return false; - // th.setData({goodsInputNum:t}); + // 非秒杀活动 + if(this.data.prom_type != 1) { + this.setData({ + goodsInputNum: t, + }); + }; - // if(this.data.options.prom_type == 1 && !this.data.openSpecModal_flash_normal) { - - this.get_buy_num(this.data.sele_g, async function () { - th.data.sele_g.viplimited = th.data.sele_g.buy_limit; - - //--判断商品是否超出限购-- - // if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { - // if(!th.data.prom_act.is_shop_buy) { - - // if (th.data.sele_g.viplimited > 0) { - // var gd_buy_num = th.data.sele_g.buy_num; - - // if (t + 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({goodsInputNum: num}) - // return false; - // } - // }; - - - // 单独购买 - if(th.data.openSpecModal_flash_normal) th.data.is_normal = 1; - - // 秒杀:判断活动是否抢光 - if (th.data.sele_g.prom_type == 1 && !th.data.is_normal) { - var redis_num = 0; - //------判断活动是否抢光----- - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + - os.stoid + "/" + th.data.sele_g.prom_type + "/" + th.data.sele_g.prom_id, { - 1: 1 - }).then(res => { - redis_num = res.data.data; + // 秒杀活动 + if(this.data.prom_type == 1) { + // 如果是秒杀活动下的单独购买,is_normal为1 + if(this.data.openSpecModal_flash_normal) this.data.is_normal = 1; + + if(this.data.is_normal) {// 单独购买 + this.setData({ + goodsInputNum: t, + }); + } else {// 秒杀购买 + + // 获取redis当前可以购买的数量 + // 如果数量为0,设置和显示已抢光 + // 否则,进一步判断是否超出限购或超出库存 + await this.getactLen().then(async function(res) { + // res: redis可购买数量 + console.log('当前可以购买的数量:', res); + if(res <= 0) { + // 可购买数量<=0, 设置和显示已抢光 + th.setData({ + prom_r_null: 1, + }); + } else { + // 可购买数量>0 + // 计算自己还可以购买的数量 + // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b + // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存 + // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购 + let actInfo = th.data.sele_g; + await th.get_buy_num2().then(function (data) { + let limited = actInfo.buy_limit; // 限购数量a + let promcardbuynum = data.data.data.promcardbuynum; + let buyedNum = promcardbuynum; // 自己已经购买的数量b + let canBuyNum = limited - buyedNum; // 自己还可购买的数量c + + if(canBuyNum <= 0) { + canBuyNum = 0; + }; + + if(limited > res) { + if(t > res) { // t当前增减的数量 + wx.showModal({ + title: '超出活动库存', }); - - if (t > redis_num) { - wx.showToast({ - // title: '超出商品活动库存', - title: '超出活动库存', - icon: 'none', - }); - th.setData({goodsInputNum: redis_num}) - return false; - } + th.setData({ + goodsInputNum: res, + }); + return false; }; - - //--秒杀:判断商品是否超出活动限购-- - if (th.data.sele_g.viplimited > 0 && !th.data.is_normal && th.data.prom_type == 1) { - var gd_buy_num = th.data.promcardbuynum; - - // 如果限购数量>活动库存数量,增加数量时会先超过库存数量,此时应该提示“超出活动库存”; - // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” - if(th.data.sele_g.viplimited > th.data.sele_g.goods_num) { - - // 计算还可以购买的数量:库存量 - 已购数 - var num = th.data.sele_g.goods_num - gd_buy_num; - if(num < 0) num = 0; - if(t > num) { - wx.showToast({ - title: '超出活动库存', - icon: 'none', - }); - - th.setData({goodsInputNum: num}) - return false; - - }; - - } else { - if ((t + gd_buy_num> th.data.sele_g.viplimited) && (t<=th.data.sele_g.goods_num)) { - wx.showToast({ - title: '超出活动限购数量', - icon: 'none', - }); - - var num = th.data.sele_g.viplimited - gd_buy_num; - if (num <= 0) num = 1; - th.setData({goodsInputNum: num}) - return false; - }; - }; - - - + }; + + if(limited <= res) { + if(t>limited) { + wx.showModal({ + title: '超出限购数量', + }); + th.setData({ + goodsInputNum: canBuyNum, + }); + return false; }; - - //--秒杀:判断商品是否超出活动限购-- - // if (th.data.prom_buy_num != -1 && th.data.prom_buy_limit > 0 && !th.data.is_normal) { - // if (t + th.data.prom_buy_num > th.data.prom_buy_limit) { - // wx.showModal({ - // title: '超出商品活动限购', - // }); + }; + + th.setData({ + goodsInputNum: t, + }); + }); + }; + }); - // var num = th.data.prom_buy_limit - th.data.prom_buy_num; - // if (num < 0) num = 0; - // th.setData({goodsInputNum: num}) - // return false; - // }; - // }; + } + + + }; + + + + + + // var e = th.data.sele_g.goods_num; - var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4 - if (th.data.sales_rules == 2 && (p_type != 1 && p_type != 4 && p_type != 6 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1)) { - if (!th.data.def_pick_store) { - wx.showModal({title: '请选择门店',}); - return false; - } else { - // e = th.data.def_pick_store.CanOutQty; - } - } - - th.setData({goodsInputNum: t}); + // var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4 + // if (th.data.sales_rules == 2 && (p_type != 1 && p_type != 4 && p_type != 6 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1)) { + // if (!th.data.def_pick_store) { + // wx.showModal({title: '请选择门店',}); + // return false; + // } else { + // e = th.data.def_pick_store.CanOutQty; + // } + // } + + + // th.setData({goodsInputNum: t}); - }); + // }); }, @@ -1326,12 +1237,10 @@ Page({ return false; } - var ind = t.currentTarget.dataset.ind; - + var ind = t.currentTarget.dataset.ind; this.setData({ openSpecModal: !0, - openSpecModal_ind: ind, - goodsInputNum: 1, + openSpecModal_ind: ind, }); }, @@ -3288,19 +3197,18 @@ Page({ //获取redis中的数量 - async getactLen(func) { - var r_num = 0, - prom_type = this.data.prom_type, - prom_id = this.data.prom_id; - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { + async getactLen() { + let prom_type = this.data.options.prom_type; + let prom_id = this.data.options.prom_id; + return await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { 1: 1 }).then(res => { - var em = res; - if (em.data.code == 0) { - r_num = em.data.data; - } + if (res.data.code == 0) { + // 当前可以购买的数量 + let r_num = res.data.data; + return r_num; + }; }) - func(r_num); }, @@ -3539,7 +3447,7 @@ Page({ //----获取商品购买数---- if (th.data.prom_type == 1) { //----获取活动购买数---- - getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { + getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { data: { store_id: os.stoid, user_id: user_id, @@ -3567,6 +3475,49 @@ Page({ }, + get_buy_num2: async function () { + // var map = this.data.g_buy_num, + var th = this, + user_id = getApp().globalData.user_id; + // if (user_id == null) { + // // map.set(gd.goods_id, 0); + // th.setData({ + // // g_buy_num: map, + // prom_buy_num: 0, + // }); + // "function" == typeof func && func(); + // return false; + // } + + + //----获取商品购买数---- + + //----获取活动购买数---- + return await getApp().request.promiseGet("/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: tt.data.data.cardbuynum, + }); + } + } + }); + + + }, + + -- libgit2 0.21.4