Commit 8b9fa55269eefdf172345336dd5c1a5846640413
1 parent
a857a0be
fix;服务卡项购物车超限购
Showing
1 changed file
with
40 additions
and
77 deletions
packageA/pages/goodsInfo/goodsInfo.js
@@ -859,16 +859,16 @@ Page({ | @@ -859,16 +859,16 @@ Page({ | ||
859 | return false; | 859 | return false; |
860 | }; | 860 | }; |
861 | 861 | ||
862 | - | 862 | + // 秒杀活动 |
863 | if(this.data.prom_type == 1) { | 863 | if(this.data.prom_type == 1) { |
864 | 864 | ||
865 | this.data.sele_g.viplimited = this.data.sele_g.buy_limit; | 865 | this.data.sele_g.viplimited = this.data.sele_g.buy_limit; |
866 | 866 | ||
867 | - // 每人限购数 | 867 | + // 每人最大限购数 |
868 | th.data.sele_g.viplimited = th.data.sele_g.buy_limit; | 868 | th.data.sele_g.viplimited = th.data.sele_g.buy_limit; |
869 | 869 | ||
870 | //----获取用户活动购买数---- | 870 | //----获取用户活动购买数---- |
871 | - // 已经付款的单数 | 871 | + // 已经付款的单数,已经成功购买的数量 |
872 | var gd_buy_num = 0; | 872 | var gd_buy_num = 0; |
873 | 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, { | 873 | 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, { |
874 | }).then(res => { | 874 | }).then(res => { |
@@ -884,51 +884,51 @@ Page({ | @@ -884,51 +884,51 @@ Page({ | ||
884 | }; | 884 | }; |
885 | }); | 885 | }); |
886 | 886 | ||
887 | - // 获取购物车同款数量 判断是否超库存 | ||
888 | - var cartGoodsNum = 0; | ||
889 | - 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, | ||
890 | - { }).then(res => { | ||
891 | - if (res.data.data.pageData.length > 0) { | ||
892 | - const tmpObj = res.data.data.pageData[0]; | ||
893 | - cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num; | ||
894 | - } | ||
895 | - | ||
896 | - }); | ||
897 | - | ||
898 | - | ||
899 | 887 | ||
900 | // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程 | 888 | // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程 |
901 | - // 没有库存,已抢光的情况下,走正常购买流程 | 889 | + // 没有库存,已抢光的情况下,走正常购买流程 |
902 | if(redisNum > 0 && !this.data.is_normal) { | 890 | if(redisNum > 0 && !this.data.is_normal) { |
903 | // 输入的数量 | 891 | // 输入的数量 |
904 | var t = th.data.goodsInputNum; | 892 | var t = th.data.goodsInputNum; |
893 | + // 获取购物车同款数量 | ||
894 | + var cartGoodsNum = 0; | ||
895 | + | ||
896 | + // 购物车 | ||
897 | + if (action != "buy") { | ||
898 | + 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, | ||
899 | + { }).then(res => { | ||
900 | + if (res.data.data.pageData.length > 0) { | ||
901 | + const tmpObj = res.data.data.pageData[0]; | ||
902 | + cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num; | ||
903 | + } | ||
904 | + | ||
905 | + }); | ||
906 | + | ||
907 | + // 输入的数量 + 购物车同款商品的数量 | ||
908 | + t = parseInt(t) + parseInt(cartGoodsNum); | ||
909 | + } | ||
910 | + | ||
911 | + // 剩余购买数量 | ||
912 | + let num = th.data.sele_g.viplimited - gd_buy_num; | ||
913 | + num = num < 0 ? 0 : num; | ||
905 | 914 | ||
906 | if (t > redisNum) { | 915 | if (t > redisNum) { |
907 | wx.showToast({ | 916 | wx.showToast({ |
908 | - title: '超出活动库存' + redisNum, | 917 | + title: '超出活动库存', |
909 | icon: 'none' | 918 | icon: 'none' |
910 | }); | 919 | }); |
911 | 920 | ||
912 | // 开启限购 | 921 | // 开启限购 |
913 | if (th.data.sele_g.viplimited > 0) { | 922 | if (th.data.sele_g.viplimited > 0) { |
914 | 923 | ||
915 | - let num = th.data.sele_g.viplimited - gd_buy_num; | ||
916 | - if (action !="buy") { | ||
917 | - // 购物车 | ||
918 | - if (num > redisNum) { | ||
919 | - th.setData({goodsInputNum: redisNum}); | ||
920 | - } else { | ||
921 | - th.setData({goodsInputNum: num}); | ||
922 | - } | ||
923 | - } else { | ||
924 | - // 立即购买 | ||
925 | - if (num > redisNum) { | ||
926 | - th.setData({goodsInputNum: redisNum}); | ||
927 | - } else { | ||
928 | - th.setData({goodsInputNum: num}); | ||
929 | - } | 924 | + if (t > num) { |
925 | + th.setData({goodsInputNum: num}); | ||
930 | } | 926 | } |
931 | 927 | ||
928 | + if (redisNum < num) { | ||
929 | + th.setData({goodsInputNum: redisNum}); | ||
930 | + } | ||
931 | + | ||
932 | 932 | ||
933 | } else { | 933 | } else { |
934 | th.setData({goodsInputNum: redisNum}); | 934 | th.setData({goodsInputNum: redisNum}); |
@@ -937,64 +937,27 @@ Page({ | @@ -937,64 +937,27 @@ Page({ | ||
937 | return false; | 937 | return false; |
938 | } | 938 | } |
939 | 939 | ||
940 | - | ||
941 | - | ||
942 | - // 跳过<立即购买> 购物车 | ||
943 | - if (action !="buy") { | ||
944 | - | ||
945 | - // 输入的数量 + 购物车同款商品的数量 | ||
946 | - var maxNum = parseInt(t) + parseInt(cartGoodsNum); | ||
947 | - // 是否开启个人限购 | ||
948 | - if (th.data.sele_g.viplimited > 0) { | ||
949 | - if (maxNum + gd_buy_num > th.data.sele_g.buy_limit) { | ||
950 | - wx.showToast({ | ||
951 | - title: '超出活动限购数量', | ||
952 | - icon: 'none' | ||
953 | - }); | ||
954 | - | ||
955 | - // 可购买数量 | ||
956 | - let num = th.data.sele_g.viplimited - gd_buy_num - cartGoodsNum; | ||
957 | - th.setData({goodsInputNum: num < 0 ? 0 : num}); | ||
958 | - return false; | ||
959 | - } | ||
960 | - | ||
961 | - } | ||
962 | - | ||
963 | - if (maxNum > redisNum) { | ||
964 | - wx.showToast({ | ||
965 | - title: '超出活动库存', | ||
966 | - icon: 'none' | ||
967 | - }); | ||
968 | - // 可购买数量 | ||
969 | - let num = redisNum - cartGoodsNum; | ||
970 | - th.setData({goodsInputNum: num}); | ||
971 | - return false; | ||
972 | - } | ||
973 | - | ||
974 | - } else { | ||
975 | - // 以下为立即购买 | ||
976 | - // 是否开启个人限购 | 940 | + // 以下小于等于库存 |
941 | + if (t <= redisNum) { | ||
977 | if (th.data.sele_g.viplimited > 0) { | 942 | if (th.data.sele_g.viplimited > 0) { |
978 | 943 | ||
979 | - if (t + gd_buy_num > th.data.sele_g.viplimited) { | 944 | + if (t > num) { |
980 | wx.showToast({ | 945 | wx.showToast({ |
981 | title: '超出活动限购数量', | 946 | title: '超出活动限购数量', |
982 | icon: 'none' | 947 | icon: 'none' |
983 | }); | 948 | }); |
984 | - | ||
985 | - let num = th.data.sele_g.viplimited - gd_buy_num; | 949 | + |
986 | if (num > redisNum) { | 950 | if (num > redisNum) { |
987 | th.setData({goodsInputNum: redisNum}); | 951 | th.setData({goodsInputNum: redisNum}); |
988 | } else { | 952 | } else { |
989 | th.setData({goodsInputNum: num}); | 953 | th.setData({goodsInputNum: num}); |
990 | } | 954 | } |
991 | return false; | 955 | return false; |
992 | - } | ||
993 | - | ||
994 | - | ||
995 | - }; | ||
996 | - | 956 | + } |
957 | + | ||
958 | + } | ||
997 | } | 959 | } |
960 | + | ||
998 | 961 | ||
999 | }; | 962 | }; |
1000 | }; | 963 | }; |