Commit da959847c64e5401f189766c4da0fda20b857781
1 parent
5cfde18d
fix:购物车库存限制
Showing
1 changed file
with
56 additions
and
46 deletions
packageA/pages/goodsInfo/goodsInfo.js
| ... | ... | @@ -843,12 +843,16 @@ Page({ |
| 843 | 843 | }, |
| 844 | 844 | |
| 845 | 845 | //------------加入购物车-------------- |
| 846 | - addCart: function(t) { | |
| 846 | + addCart: async function(t) { | |
| 847 | 847 | var th = this; |
| 848 | 848 | var ind = t.currentTarget.dataset.openSpecModal_ind; |
| 849 | 849 | var action= t.currentTarget.dataset.action; |
| 850 | 850 | if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; |
| 851 | - | |
| 851 | + // 活动ID | |
| 852 | + var prom_id = th.data.prom_id; | |
| 853 | + | |
| 854 | + var redisNum = 0; | |
| 855 | + | |
| 852 | 856 | th.setData({ |
| 853 | 857 | open_ind_store: ind |
| 854 | 858 | }); |
| ... | ... | @@ -859,69 +863,79 @@ Page({ |
| 859 | 863 | }; |
| 860 | 864 | |
| 861 | 865 | |
| 862 | - | |
| 863 | - | |
| 864 | - //000000 | |
| 865 | - //如果是秒杀的话,要看redis够不够 | |
| 866 | - // if (this.data.prom_type == 1) { | |
| 867 | - | |
| 868 | - // if (this.data.openSpecModal_flash_normal) { | |
| 869 | - // this.data.is_normal=1; //是普通购买 | |
| 870 | - // return false; | |
| 871 | - // } | |
| 872 | - | |
| 873 | - | |
| 874 | - // this.getactLen(function (num) { | |
| 875 | - // if (num < th.data.goodsInputNum) { | |
| 876 | - // getApp().my_warnning("活动库存不足!", 0, th); | |
| 877 | - // return false; | |
| 878 | - // } else { | |
| 879 | - // // th.add_cart_func(t); | |
| 880 | - // } | |
| 881 | - // }); | |
| 882 | - // } else { | |
| 883 | - // // th.add_cart_func(t); | |
| 884 | - // } | |
| 885 | - //000000 | |
| 886 | - | |
| 887 | 866 | // if(!this.data.openSpecModal_ind) { |
| 888 | 867 | if(this.data.prom_type == 1) { |
| 889 | 868 | this.data.sele_g.viplimited = this.data.sele_g.buy_limit; |
| 890 | 869 | |
| 891 | - if(this.data.sele_g.viplimited > 0 && !this.data.is_normal) { | |
| 870 | + if(!this.data.is_normal) { | |
| 871 | + // 输入的数量 | |
| 892 | 872 | var t = th.data.goodsInputNum; |
| 873 | + | |
| 874 | + // 检查redis库存量 | |
| 875 | + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | |
| 876 | + os.stoid + "/1/" + prom_id, | |
| 877 | + {} | |
| 878 | + ).then(res => { | |
| 879 | + if (res.data.code == 0) { | |
| 880 | + redisNum = res.data.data; | |
| 881 | + }; | |
| 882 | + }); | |
| 883 | + | |
| 884 | + if (t > redisNum) { | |
| 885 | + wx.showModal({ | |
| 886 | + title: '超出活动库存', | |
| 887 | + }); | |
| 888 | + return false; | |
| 889 | + } | |
| 890 | + | |
| 891 | + // 获取购物车同类数量 判断是否超库存 | |
| 892 | + var cartGoodsNum = 0; | |
| 893 | + await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+os.stoid+"&user_id="+oo.user_id+"&service_id="+th.data.data.id+"&pick_id="+th.data.sto_sele_id, | |
| 894 | + { }).then(res => { | |
| 895 | + if (res.data.data.pageData.length > 0) { | |
| 896 | + const tmpObj = res.data.data.pageData[0]; | |
| 897 | + cartGoodsNum = tmpObj.goods_num; | |
| 898 | + } | |
| 899 | + | |
| 900 | + }); | |
| 901 | + | |
| 902 | + if (cartGoodsNum >= redisNum) { | |
| 903 | + wx.showModal({ | |
| 904 | + title: '超出活动库存', | |
| 905 | + }); | |
| 906 | + return false; | |
| 907 | + } | |
| 908 | + | |
| 909 | + // 每人限购数 | |
| 893 | 910 | th.data.sele_g.viplimited = th.data.sele_g.buy_limit; |
| 911 | + | |
| 912 | + // 是否开启个人限购 | |
| 894 | 913 | if (th.data.sele_g.viplimited > 0) { |
| 895 | - var gd_buy_num = th.data.sele_g.buy_num; | |
| 896 | - | |
| 914 | + // 已经付款的单数 | |
| 915 | + var gd_buy_num = th.data.sele_g.buy_num; | |
| 916 | + | |
| 897 | 917 | if (t + gd_buy_num > th.data.sele_g.viplimited) { |
| 898 | 918 | wx.showModal({ |
| 899 | - title: '超出活动库存', | |
| 919 | + title: '超出活动限购数量', | |
| 900 | 920 | }); |
| 901 | 921 | |
| 902 | 922 | let num = th.data.sele_g.viplimited - gd_buy_num; |
| 903 | 923 | if (num <= 0) num = 1; |
| 904 | 924 | th.setData({goodsInputNum: num}); |
| 905 | 925 | return false; |
| 906 | - } | |
| 926 | + } | |
| 927 | + | |
| 928 | + | |
| 907 | 929 | }; |
| 908 | 930 | }; |
| 909 | 931 | }; |
| 910 | 932 | |
| 911 | 933 | |
| 912 | - | |
| 913 | 934 | // }; |
| 914 | 935 | |
| 915 | - | |
| 916 | - | |
| 917 | - | |
| 918 | - | |
| 919 | - | |
| 920 | - | |
| 921 | - | |
| 922 | 936 | |
| 923 | 937 | |
| 924 | - if(action=="buy"){ | |
| 938 | + if(action=="buy"){ // 直接购买 | |
| 925 | 939 | //--------------此时操作的数据------------ |
| 926 | 940 | var newd = { |
| 927 | 941 | id: th.data.data.id, |
| ... | ... | @@ -946,10 +960,7 @@ Page({ |
| 946 | 960 | |
| 947 | 961 | // console.log('newd++++++++', newd); |
| 948 | 962 | th.buyNow(newd); |
| 949 | - } else { | |
| 950 | - | |
| 951 | - | |
| 952 | - | |
| 963 | + } else { // 购物车 | |
| 953 | 964 | |
| 954 | 965 | var newd = { |
| 955 | 966 | service_id: th.data.data.id, |
| ... | ... | @@ -976,7 +987,6 @@ Page({ |
| 976 | 987 | newd['money'] = th.data.prom_price; |
| 977 | 988 | }; |
| 978 | 989 | }; |
| 979 | - | |
| 980 | 990 | |
| 981 | 991 | //----先看会员在购物车中是否加入了该商品----- |
| 982 | 992 | getApp().request.get("/api/weshop/cartService/page", { | ... | ... |