From 87358ad0950ef022dec32f76c9a8b17a30925982 Mon Sep 17 00:00:00 2001 From: yvan.ni Date: Thu, 15 Dec 2022 16:08:51 +0800 Subject: [PATCH] 搭配购商品 的优化 --- components/cart_collect_temp/cart_collect_temp.js | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- packageA/pages/prom_list/prom_list.js | 383 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------- packageA/pages/prom_list/prom_list.wxml | 16 ++++++++-------- packageA/pages/prom_list/prom_list.wxss | 3 ++- pages/cart/cart2/cart2.js | 4 ++-- pages/cart/cart2/cart2.wxml | 4 ++-- 6 files changed, 394 insertions(+), 108 deletions(-) diff --git a/components/cart_collect_temp/cart_collect_temp.js b/components/cart_collect_temp/cart_collect_temp.js index 8b9d265..a1558a6 100644 --- a/components/cart_collect_temp/cart_collect_temp.js +++ b/components/cart_collect_temp/cart_collect_temp.js @@ -1,3 +1,5 @@ +var regeneratorRuntime = require('../../utils/runtime.js'); +var os = getApp().globalData.setting Component({ properties: { // 这里定义了数据列表属性,列表显示数据 @@ -14,6 +16,15 @@ Component({ cart_index: { type: Number, value: 0 + }, + + sales_rules: { + type: Number, + value: 1 + }, + pick:{ + type: Number, + value: 1 } }, @@ -22,7 +33,8 @@ Component({ imgUrl: getApp().globalData.setting.imghost, }, methods: { - select_coll(e) { + async select_coll(e) { + var th=this; var index = e.currentTarget.dataset.index; var itr = this.properties.all_collocation_list[index]; var ob = { @@ -35,6 +47,23 @@ Component({ ob.cart_index =this.properties.cart_index; } + + if(th.data.sales_rules>1){ + var isok = 1; + await th.check_store_num(itr.goods_id, th.data.pick, 1, function (res){ + isok = res; + }) + if(!isok){ + wx.showToast({ + title: itr.goods_name+"商品库存不足", + icon: 'none', + duration: 2000 + }) + return false; + } + } + + var txt = "all_collocation_list[" + index + "].selected" this.setData({[txt]: ob.selected}) @@ -53,5 +82,66 @@ Component({ }, + //---确认线下门店的数量足不足--- + async check_store_num(goods_id, pick, goods_num, func) { + var lock = 0, pick_no, plist, erpwareid; + + var lock_rq={ store_id: os.stoid, wareId: goods_id, storageId: pick, pageSize: 1000 }; + if(this.data.sales_rules==3){ + lock_rq.appoint_pick_keyid=this.data.appoint_pick_keyid; + delete lock_rq.storageId + } + //先读取门店的lock + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", { + data: lock_rq + }).then(res => { + if (res.data.code == 0 && res.data.data.total > 0) { + for (var i in res.data.data.pageData) + lock += res.data.data.pageData[i].outQty; + } + }) + + if(this.data.sales_rules==2) { + //先获取门店的编号 + await getApp().request.promiseGet("/api/weshop/pickup/get/" + os.stoid + "/" + pick, { + }).then(res => { + if (res.data.code == 0) { + pick_no = res.data.data.pickup_no; + } + }) + } + + //先获取商品的线下库存 + await getApp().request.promiseGet("/api/weshop/goods/get/" + os.stoid + "/" + goods_id, { + }).then(res => { + if (res.data.code == 0) { + erpwareid = res.data.data.erpwareid; + } + }) + + + var sto_rq={ storageNos: pick_no, wareIds: encodeURIComponent(erpwareid), storeId: os.stoid, pageSize: 2000 }; + if(this.data.sales_rules==3){ + sto_rq.storageIds=this.data.appoint_pick_keyid; + delete sto_rq.storageNos + } + + //读取线下的门店库存 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", { + data: sto_rq + }).then(res => { + if (res.data.code == 0 && res.data.data.total > 0) { + plist = res.data.data.pageData[0]; + } + }) + + var isok = 1; + if (!plist || goods_num > plist.CanOutQty - lock) { + isok = 0; + } + func(isok); + }, + + } }) \ No newline at end of file diff --git a/packageA/pages/prom_list/prom_list.js b/packageA/pages/prom_list/prom_list.js index 5070e58..cbbc34a 100644 --- a/packageA/pages/prom_list/prom_list.js +++ b/packageA/pages/prom_list/prom_list.js @@ -273,17 +273,26 @@ Page({ //调用接口判断订单优惠, getApp().request.promiseGet("/api/weshop/goods/getGoodsPromList/" + os.stoid + "/" + ee.data.gid + "/2"+"/"+user_id, {}).then(res => { if (res.data.code == 0) { - var r_data = res.data.data; - - - th.data.is_coupon = r_data.collocationPromList.is_coupon; - - + + var r_data = res.data.data; + + th.data.is_coupon = r_data.collocationPromList.is_coupon; + th.loop_promise(0, r_data.collocationList, function () { - // 设置搭配购是否使用优惠卷 + + var set_data=JSON.parse(JSON.stringify(r_data.collocationList)); + + //如果是线上的时候,过滤掉线上库存未0的商品 + if(th.data.sales_rules==1){ + set_data=set_data.filter(function (e){ + return e.store_count>0; + }) + } + + //设置搭配购是否使用优惠卷 ee.setData({ collocationGoods: r_data.collocationPromList, - collocationList: r_data.collocationList, + collocationList: set_data, }) }) } @@ -297,7 +306,7 @@ Page({ //--等待某个值只运行---,这里有可能因为导航的时间太久,而不能计算门店库存 getApp().waitfor2(that, "wait_for_user_store", "fir_def_store", function () { - debugger + if (th.data.fir_def_store && th.data.fir_def_store.pickup_id) { var lock = 0,plist = null; @@ -386,6 +395,8 @@ Page({ //------------加入购物车-------------- addCart: function(t) { var th = this; + if(this.data.lding) return false; + th.setData({lding:1}) th.add_cart_func(t); }, @@ -393,6 +404,7 @@ Page({ add_cart_func: function(t) { var i = getApp().request; if (oo.user_id == null) { + th.setData({lding:0}) return s.my_warnning("还未登录!", 0, this); } var e = this, @@ -401,7 +413,7 @@ Page({ o = this.data.data; a = o.goods_id; //----------添加到购物车时,要判断限购数量,-------- - e.get_buy_num(o, function(ee) { + e.get_buy_num(o, async function(ee) { //---判断商品是否超出限购--- if (th.data.g_buy_num != null && th.data.data.viplimited > 0) { if (th.data.goodsInputNum + th.data.g_buy_num.get(th.data.data.goods_id) > th.data.data.viplimited) { @@ -409,6 +421,7 @@ Page({ title: '提示', content: '超出商品限购' }); + th.setData({lding:0}) return false; } } @@ -419,16 +432,23 @@ Page({ title: '提示', content: '超出商品活动限购' }); + th.setData({lding:0}) return false; } } - if (th.data.goodsInputNum <= 0) return s.my_warnning("商品数量不能为0", 0, th); + if (th.data.goodsInputNum <= 0){ + th.setData({lding: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.setData({lding:0}) + return s.my_warnning("请选择门店", 0, th); + } //--------------此时操作的数据------------ var newd = { @@ -478,12 +498,13 @@ Page({ //-----如果是秒杀,团购,积分购,拼团----- if (th.data.data.prom_type != 5) { + th.setData({lding:0}) return s.my_warnning("商品不是搭配活动!", 0, th); }else{ //---如果是线下门店销售的时候--- if(th.data.sales_rules>=2){ - var pick=th.get_pick_from_list(th.data.sto_sele_id) + var pick=th.get_pick_from_list(th.data.sto_sele_id) var dw_rq={storageNos:pick.pickup_no,wareIds:encodeURIComponent(th.data.data.erpwareid),storeId:os.stoid,pageSize:2000}; if(th.data.sales_rules == 3){ @@ -499,6 +520,7 @@ Page({ if(res.data.data.pageData.length>0){ var CanOutQty=res.data.data.pageData[0].CanOutQty; if(CanOutQtynow){ - var card_price=o[getApp().globalData.userInfo['card_field']]; - //如果会员有等级价 - if(getApp().globalData.userInfo['card_field']!=undefined && getApp().globalData.userInfo['card_field']!=null - && getApp().globalData.userInfo['card_field']!="" && card_price>0){ - newd.goods_price=card_price; - } - } - } - } + add_cart_next(e, t, a, o, newd, CanOutQty) { + var th = this; + //---如果商品不是积分购和拼团,要判断一个是否要进行等级价的判断------ + if (o.prom_type != 1 && o.prom_type != 6) { + var conf = th.data.bconfig; + if (conf.switch_list && getApp().globalData.userInfo['card_field']) { + var s_list = JSON.parse(conf.switch_list); + var now = ut.gettimestamp(); + var str = getApp().globalData.userInfo['card_expiredate'].replace(/-/g, '/'); + var end = new Date(str); + end = Date.parse(end) / 1000; + + //--如果后台有开启等级价的功能,而且会员的等级没有过期的情况下-- + if (parseInt(s_list.rank_switch) == 2 && end > now) { + var card_price = o[getApp().globalData.userInfo['card_field']]; + //如果会员有等级价 + if (getApp().globalData.userInfo['card_field'] != undefined && getApp().globalData.userInfo['card_field'] != null + && getApp().globalData.userInfo['card_field'] != "" && card_price > 0) { + newd.goods_price = card_price; + } + } + } + } - newd['pick_name'] = th.data.sto_sele_name; - newd['pick_dis'] = th.data.sto_sele_distr; - newd["collocation_goods"]=th.data.sele_collocation; + newd['pick_name'] = th.data.sto_sele_name; + newd['pick_dis'] = th.data.sto_sele_distr; - newd["is_coupon"] = th.data.is_coupon; + this.check_sele_collocation(function (collocationGoods) { + var is_ok = 1; + if (th.data.sales_rules > 1) { - th.buyNow(newd); + for (let j = 0; j < collocationGoods.length; j++) { + var item = collocationGoods[j]; + if (item.CanOutQty<=0) { + is_ok=0; + wx.showToast({ + title: item.goods_name+ "库存不足", + icon: 'none', + duration: 2000 + }) - }, + break; + } + } + } + + if(!is_ok){ + th.setData({lding:0}) + return false; + } + + newd["collocation_goods"] = collocationGoods; + newd["is_coupon"] = th.data.is_coupon; + th.buyNow(newd); + }) + + }, //----------立即购买----------- buyNow: function(e) { @@ -849,7 +903,6 @@ Page({ e.his_cate_num=his_cate_num; - debugger //如果有开启距离的功能,没有设置默认门店,要用最近的门店作为默认门店 if(dd.lat && !th.data.def_pick_store && th.data.bconfig && th.data.bconfig.is_sort_storage){ @@ -1509,44 +1562,59 @@ Page({ }else{ - var lock_rq={store_id:os.stoid,wareId:goodsinfo.goods_id,storageId:item.pickup_id,pageSize:1000}; - //-- 指定门店销售的时候 -- - if(th.data.sales_rules == 3){ - lock_rq.appoint_pick_keyid = encodeURIComponent(th.data.appoint_pick_keyid); - delete lock_rq.storageId - } - - //先读取门店的lock - await getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{ - data:lock_rq - }).then(res=>{ - if(res.data.code==0 && res.data.data.total>0){ - for(var i in res.data.data.pageData ) - lock+=res.data.data.pageData[i].outQty; - } - }) + // var lock_rq={store_id:os.stoid,wareId:goodsinfo.goods_id,storageId:item.pickup_id,pageSize:1000}; + // //-- 指定门店销售的时候 -- + // if(th.data.sales_rules == 3){ + // lock_rq.appoint_pick_keyid = encodeURIComponent(th.data.appoint_pick_keyid); + // delete lock_rq.storageId + // } + // + // //先读取门店的lock + // await getApp().request.promiseGet("/api/weshop/order/ware/lock/page",{ + // data:lock_rq + // }).then(res=>{ + // if(res.data.code==0 && res.data.data.total>0){ + // for(var i in res.data.data.pageData ) + // lock+=res.data.data.pageData[i].outQty; + // } + // }) + // + // var dw_rq={storageNos:item.pickup_no,wareIds:encodeURIComponent(erpwareid),storeId:os.stoid,pageSize:2000}; + // if(th.data.sales_rules == 3){ + // dw_rq.storageIds = encodeURIComponent(th.data.appoint_pick_keyid) + // delete dw_rq.storageNos + // } + // + // //读取线下的门店库存 + // await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{ + // data:dw_rq + // }).then(res=>{ + // if(res.data.code==0 && res.data.data.total>0){ + // plist=res.data.data.pageData[0]; + // } + // }) + // + // if(plist && plist.CanOutQty-lock>0){ + // item.CanOutQty=plist.CanOutQty-lock; + // func(); + // return false; + // } + // getApp().my_warnning(item.pickup_name+"库存不足!", 0, th); + + this.check_CanOutQty(goodsinfo, item, function (CanOutQty) { + // let str = item.pickup_name + '库存不足!'; + if (!CanOutQty) { + wx.showToast({ + title: item.pickup_name + '库存不足!', + icon: 'none', + }); + return false; + } + item.CanOutQty = CanOutQty; + func(); - var dw_rq={storageNos:item.pickup_no,wareIds:encodeURIComponent(erpwareid),storeId:os.stoid,pageSize:2000}; - if(th.data.sales_rules == 3){ - dw_rq.storageIds = encodeURIComponent(th.data.appoint_pick_keyid) - delete dw_rq.storageNos - } + }); - //读取线下的门店库存 - await getApp().request.promiseGet("/api/weshop/goods/getWareStorages",{ - data:dw_rq - }).then(res=>{ - if(res.data.code==0 && res.data.data.total>0){ - plist=res.data.data.pageData[0]; - } - }) - - if(plist && plist.CanOutQty-lock>0){ - item.CanOutQty=plist.CanOutQty-lock; - func(); - return false; - } - getApp().my_warnning(item.pickup_name+"库存不足!", 0, th); } }, @@ -1787,20 +1855,90 @@ Page({ }, //递归获取商品 - loop_promise:function(x,arr,func){ + loop_promise: function(x,arr,func){ var th=this; - getApp().request.promiseGet("/api/weshop/goods/get/" + o.stoid + "/" + arr[x].goods_id, {}).then(res => { - arr[x].goods_spec=res.data.data.goods_spec; - arr[x].goods_color=res.data.data.goods_color; - arr[x].original_img=res.data.data.original_img; - arr[x].shop_price=res.data.data.shop_price; - if(x==arr.length-1){ - func(arr); //循环再最后 - }else{ - ++x; - th.loop_promise(x,arr,func); - } + var g_data=null; + getApp().request.promiseGet("/api/weshop/goods/get/" + o.stoid + "/" + arr[x].goods_id, {}).then(res => { + if(res.data.code==0 && res.data.data){ + g_data=res.data.data; + if(g_data){ + arr[x].goods_spec=g_data.goods_spec; + arr[x].goods_color=g_data.goods_color; + arr[x].original_img=g_data.original_img; + arr[x].shop_price=g_data.shop_price; + arr[x].store_count=g_data.store_count; + } + } + + if(x==arr.length-1){ + func(arr); //循环再最后 + }else{ + ++x; + th.loop_promise(x,arr,func); + } }) + + }, + + + //线下的时候判断库存 + async check_sele_collocation(func){ + var th=this; + var pick =this.get_pick_from_list(th.data.sto_sele_id); + var collocationGoods= this.data.sele_collocation; + if(this.data.sales_rules>1){ + for (let j = 0; j < collocationGoods.length; j++) { + + var goodsinfo=collocationGoods[j]; + var sales_rules = this.data.sales_rules; + var lock_rq = { + store_id: os.stoid, + wareId: goodsinfo.goods_id, + pageSize: 1000 + }; + + if (sales_rules == 2) { + lock_rq.storageId =pick.pickup_id + } else { + lock_rq.appoint_pick_keyid = encodeURIComponent(this.data.appoint_pick_keyid) + } + + var lock = 0;var CanOutQty = 0;var plist = null; + //先读取门店的lock + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", { + data: lock_rq + }).then(res => { + if (res.data.code == 0 && res.data.data.total > 0) { + for (var i in res.data.data.pageData) + lock += res.data.data.pageData[i].outQty; + } + }) + + var sto_req = { + wareIds: encodeURIComponent(goodsinfo.erpwareid), + storeId: os.stoid + } + if (sales_rules == 2) { + sto_req.storageNos = item.pickup_no + } else { + sto_req.storageIds = encodeURIComponent(this.data.appoint_pick_keyid) + } + + //读取线下的门店库存 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", { + data: sto_req + }).then(res => { + if (res.data.code == 0 && res.data.data.total > 0) { + plist = res.data.data.pageData[0]; + } + }) + if (plist && plist.CanOutQty - lock > 0) { + CanOutQty = plist.CanOutQty - lock; + } + collocationGoods[j].CanOutQty=CanOutQty; + } + } + func(collocationGoods); }, //图片失败,默认图片 @@ -1884,7 +2022,64 @@ Page({ choice_sort_store: 0 }); }, - + + //统一一下获取线下库存的函数 + async check_CanOutQty(goodsinfo, item, func,pickup_id) { + + var sales_rules = this.data.sales_rules; + + var lock_rq = { + store_id: os.stoid, + wareId: goodsinfo.goods_id, + pageSize: 1000 + }; + + if (sales_rules == 2) { + lock_rq.storageId =item?item.pickup_id:pickup_id + } else { + lock_rq.appoint_pick_keyid = encodeURIComponent(this.data.appoint_pick_keyid) + } + + var lock = 0; + var CanOutQty = 0; + var plist = null; + //先读取门店的lock + await getApp().request.promiseGet("/api/weshop/order/ware/lock/page", { + data: lock_rq + }).then(res => { + if (res.data.code == 0 && res.data.data.total > 0) { + for (var i in res.data.data.pageData) + lock += res.data.data.pageData[i].outQty; + } + }) + + var sto_req = { + wareIds: encodeURIComponent(goodsinfo.erpwareid), + storeId: os.stoid + } + if (sales_rules == 2) { + sto_req.storageNos = item.pickup_no + } else { + sto_req.storageIds = encodeURIComponent(this.data.appoint_pick_keyid) + } + + + //读取线下的门店库存 + await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", { + data: sto_req + }).then(res => { + if (res.data.code == 0 && res.data.data.total > 0) { + plist = res.data.data.pageData[0]; + } + }) + + if (plist && plist.CanOutQty - lock > 0) { + CanOutQty = plist.CanOutQty - lock; + } + + if (func) func(CanOutQty); + + }, }); diff --git a/packageA/pages/prom_list/prom_list.wxml b/packageA/pages/prom_list/prom_list.wxml index f9394a1..15db11f 100644 --- a/packageA/pages/prom_list/prom_list.wxml +++ b/packageA/pages/prom_list/prom_list.wxml @@ -143,17 +143,17 @@ - 库存不足1 + 库存不足 - 库存不足2 + 库存不足 - 库存不足3 + 库存不足 @@ -164,26 +164,26 @@ - 库存不足4 + 库存不足 立即购买 + class="spec-cart-btn spec-buy {{lding?'graying':''}} " data-action="buy">立即购买 - 库存不足5 + 库存不足 - 立即购买 + 立即购买 立即购买 + class="spec-cart-btn spec-buy {{lding?'graying':''}} " data-action="buy">立即购买 diff --git a/packageA/pages/prom_list/prom_list.wxss b/packageA/pages/prom_list/prom_list.wxss index 123ef64..30ba685 100644 --- a/packageA/pages/prom_list/prom_list.wxss +++ b/packageA/pages/prom_list/prom_list.wxss @@ -360,4 +360,5 @@ width: 58%; background-color: #adadad; } .no_store{color:#d60021; font-size: 26rpx;} -.gray{color: #ccc;} \ No newline at end of file +.gray{color: #ccc;} +.graying{ background-color: gainsboro } \ No newline at end of file diff --git a/pages/cart/cart2/cart2.js b/pages/cart/cart2/cart2.js index 86991cb..80f61ba 100644 --- a/pages/cart/cart2/cart2.js +++ b/pages/cart/cart2/cart2.js @@ -3911,13 +3911,13 @@ Page({ await getApp().request.promiseGet("/api/weshop/goods/getWareStorages", { data: sto_rq }).then(res => { - if (res.data.code == 0) { + if (res.data.code == 0 && res.data.data.total > 0) { plist = res.data.data.pageData[0]; } }) var isok = 1; - if (goods_num > plist.CanOutQty - lock) { + if (!plist || goods_num > plist.CanOutQty - lock) { isok = 0; } func(isok); diff --git a/pages/cart/cart2/cart2.wxml b/pages/cart/cart2/cart2.wxml index 1d17591..e5bf56f 100644 --- a/pages/cart/cart2/cart2.wxml +++ b/pages/cart/cart2/cart2.wxml @@ -109,7 +109,7 @@ - @@ -377,7 +377,7 @@ - + -- libgit2 0.21.4