Commit 4ae8afccaf4f05e28d7ff59e3868f8323a64faa2
1 parent
0e636299
fix修改限购库存
Showing
2 changed files
with
252 additions
and
266 deletions
packageA/pages/goodsInfo/goodsInfo.js
| @@ -447,7 +447,7 @@ Page({ | @@ -447,7 +447,7 @@ Page({ | ||
| 447 | sto_sele_name: e.pickup_name, | 447 | sto_sele_name: e.pickup_name, |
| 448 | sto_sele_id: e.pickup_id, | 448 | sto_sele_id: e.pickup_id, |
| 449 | sto_sele_distr: e.distr_type, | 449 | sto_sele_distr: e.distr_type, |
| 450 | - sto_sele_keyid:e.keyid, | 450 | + sto_sele_keyid:e.keyid, |
| 451 | }) | 451 | }) |
| 452 | } | 452 | } |
| 453 | } | 453 | } |
| @@ -562,6 +562,9 @@ Page({ | @@ -562,6 +562,9 @@ Page({ | ||
| 562 | // <---- 秒杀 | 562 | // <---- 秒杀 |
| 563 | 563 | ||
| 564 | 564 | ||
| 565 | + | ||
| 566 | + | ||
| 567 | + | ||
| 565 | 568 | ||
| 566 | 569 | ||
| 567 | 570 | ||
| @@ -826,21 +829,7 @@ Page({ | @@ -826,21 +829,7 @@ Page({ | ||
| 826 | }); | 829 | }); |
| 827 | }, | 830 | }, |
| 828 | 831 | ||
| 829 | - //获取redis中的数量 | ||
| 830 | - async getactLen(func) { | ||
| 831 | - var r_num = 0, | ||
| 832 | - prom_type = this.data.prom_type, | ||
| 833 | - prom_id = this.data.prom_id; | ||
| 834 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { | ||
| 835 | - 1: 1 | ||
| 836 | - }).then(res => { | ||
| 837 | - var em = res; | ||
| 838 | - if (em.data.code == 0) { | ||
| 839 | - r_num = em.data.data; | ||
| 840 | - } | ||
| 841 | - }) | ||
| 842 | - func(r_num); | ||
| 843 | - }, | 832 | + |
| 844 | 833 | ||
| 845 | //------------加入购物车-------------- | 834 | //------------加入购物车-------------- |
| 846 | addCart: async function(t) { | 835 | addCart: async function(t) { |
| @@ -848,11 +837,7 @@ Page({ | @@ -848,11 +837,7 @@ Page({ | ||
| 848 | var ind = t.currentTarget.dataset.openSpecModal_ind; | 837 | var ind = t.currentTarget.dataset.openSpecModal_ind; |
| 849 | var action= t.currentTarget.dataset.action; | 838 | var action= t.currentTarget.dataset.action; |
| 850 | if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; | 839 | if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; |
| 851 | - // 活动ID | ||
| 852 | - var prom_id = th.data.prom_id; | ||
| 853 | - | ||
| 854 | - var redisNum = 0; | ||
| 855 | - | 840 | + |
| 856 | th.setData({ | 841 | th.setData({ |
| 857 | open_ind_store: ind | 842 | open_ind_store: ind |
| 858 | }); | 843 | }); |
| @@ -863,102 +848,98 @@ Page({ | @@ -863,102 +848,98 @@ Page({ | ||
| 863 | }; | 848 | }; |
| 864 | 849 | ||
| 865 | 850 | ||
| 866 | - // if(!this.data.openSpecModal_ind) { | ||
| 867 | - if(this.data.prom_type == 1) { | ||
| 868 | - | ||
| 869 | - this.data.sele_g.viplimited = this.data.sele_g.buy_limit; | ||
| 870 | - | ||
| 871 | - // 检查redis库存量 | ||
| 872 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { | ||
| 873 | - if (res.data.code == 0) { | ||
| 874 | - redisNum = res.data.data; | ||
| 875 | - }; | ||
| 876 | - }); | ||
| 877 | - | ||
| 878 | - // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程 | ||
| 879 | - // 没有库存,已抢光的情况下,走正常购买流程 | ||
| 880 | - if(redisNum > 0 && !this.data.is_normal) { | ||
| 881 | - // 输入的数量 | ||
| 882 | - var t = th.data.goodsInputNum; | ||
| 883 | - | ||
| 884 | - if (t > redisNum) { | ||
| 885 | - wx.showModal({ | 851 | + // 秒杀活动 |
| 852 | + if(this.data.prom_type == 1) { | ||
| 853 | + // 如果是秒杀活动下的单独购买,is_normal为1 | ||
| 854 | + if(this.data.openSpecModal_flash_normal) this.data.is_normal = 1; | ||
| 855 | + | ||
| 856 | + if(!this.data.is_normal) {// 秒杀购买 | ||
| 857 | + | ||
| 858 | + // 获取redis当前可以购买的数量 | ||
| 859 | + // 如果数量为0,设置和显示已抢光 | ||
| 860 | + // 否则,进一步判断是否超出限购或超出库存 | ||
| 861 | + await this.getactLen().then(async function(res) { | ||
| 862 | + let curNum = th.data.goodsInputNum; | ||
| 863 | + // res: redis可购买数量 | ||
| 864 | + console.log('当前可以购买的数量:', res); | ||
| 865 | + if(res <= 0) { | ||
| 866 | + // 可购买数量<=0, 设置和显示已抢光 | ||
| 867 | + th.setData({ | ||
| 868 | + prom_r_null: 1, | ||
| 869 | + }); | ||
| 870 | + wx.showModal({ | ||
| 871 | + title: '超出活动库存', | ||
| 872 | + }); | ||
| 873 | + return false; | ||
| 874 | + } else { | ||
| 875 | + // 可购买数量>0 | ||
| 876 | + // 计算自己还可以购买的数量 | ||
| 877 | + // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b | ||
| 878 | + // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存 | ||
| 879 | + // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购 | ||
| 880 | + let actInfo = th.data.sele_g; | ||
| 881 | + await th.get_buy_num2().then(function (data) { | ||
| 882 | + let limited = actInfo.buy_limit; // 限购数量a | ||
| 883 | + let promcardbuynum = data.data.data.promcardbuynum; | ||
| 884 | + let buyedNum = promcardbuynum; // 自己已经购买的数量b | ||
| 885 | + let canBuyNum = limited - buyedNum; // 自己还可购买的数量c | ||
| 886 | + | ||
| 887 | + if(canBuyNum <= 0) { | ||
| 888 | + canBuyNum = 0; | ||
| 889 | + }; | ||
| 890 | + | ||
| 891 | + if(limited > res) { | ||
| 892 | + if(curNum > res) { // t当前增减的数量 | ||
| 893 | + wx.showModal({ | ||
| 886 | title: '超出活动库存', | 894 | title: '超出活动库存', |
| 887 | - }); | ||
| 888 | - th.setData({goodsInputNum: redisNum}); | ||
| 889 | - return false; | ||
| 890 | - } | ||
| 891 | - | ||
| 892 | - // 获取购物车同款数量 判断是否超库存 | ||
| 893 | - var cartGoodsNum = 0; | ||
| 894 | - 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, | ||
| 895 | - { }).then(res => { | ||
| 896 | - if (res.data.data.pageData.length > 0) { | ||
| 897 | - const tmpObj = res.data.data.pageData[0]; | ||
| 898 | - cartGoodsNum = tmpObj.goods_num; | ||
| 899 | - } | ||
| 900 | - | ||
| 901 | - }); | ||
| 902 | - | ||
| 903 | - // 跳过<立即购买> 购物车 | ||
| 904 | - if (action !="buy") { | ||
| 905 | - | ||
| 906 | - // 输入的数量 + 购物车同款商品的数量 | ||
| 907 | - var maxNum = parseInt(t) + parseInt(cartGoodsNum); | ||
| 908 | - | ||
| 909 | - // 是否开启个人限购 | ||
| 910 | - if (th.data.sele_g.viplimited > 0) { | ||
| 911 | - | ||
| 912 | - if (maxNum + th.data.sele_g.buy_num > th.data.sele_g.buy_limit) { | ||
| 913 | - wx.showModal({ | ||
| 914 | - title: '超出活动限购数量', | ||
| 915 | - }); | ||
| 916 | - return false; | ||
| 917 | - } | ||
| 918 | - | ||
| 919 | - } | ||
| 920 | - | ||
| 921 | - if (maxNum > redisNum) { | 895 | + }); |
| 896 | + th.setData({ | ||
| 897 | + goodsInputNum: res, | ||
| 898 | + }); | ||
| 899 | + return false; | ||
| 900 | + }; | ||
| 901 | + }; | ||
| 902 | + | ||
| 903 | + if(limited <= res) { | ||
| 904 | + if(curNum > limited) { | ||
| 922 | wx.showModal({ | 905 | wx.showModal({ |
| 923 | - title: '超出活动库存', | 906 | + title: '超出限购数量', |
| 907 | + }); | ||
| 908 | + th.setData({ | ||
| 909 | + goodsInputNum: canBuyNum, | ||
| 924 | }); | 910 | }); |
| 925 | return false; | 911 | return false; |
| 926 | - } | ||
| 927 | - | ||
| 928 | - } else { | ||
| 929 | - // 以下为立即购买 | ||
| 930 | - // 每人限购数 | ||
| 931 | - th.data.sele_g.viplimited = th.data.sele_g.buy_limit; | ||
| 932 | - // 已经付款的单数 | ||
| 933 | - var gd_buy_num = th.data.sele_g.buy_num; | ||
| 934 | - | ||
| 935 | - // 是否开启个人限购 | ||
| 936 | - if (th.data.sele_g.viplimited > 0) { | ||
| 937 | - | ||
| 938 | - if (t + gd_buy_num > th.data.sele_g.viplimited) { | ||
| 939 | - wx.showModal({ | ||
| 940 | - title: '超出活动限购数量', | ||
| 941 | - }); | ||
| 942 | - | ||
| 943 | - let num = th.data.sele_g.viplimited - gd_buy_num; | ||
| 944 | - if (num <= 0) num = 1; | ||
| 945 | - th.setData({goodsInputNum: num}); | ||
| 946 | - return false; | ||
| 947 | - } | ||
| 948 | - | ||
| 949 | - | ||
| 950 | }; | 912 | }; |
| 951 | - } | ||
| 952 | - | 913 | + }; |
| 914 | + | ||
| 915 | + | ||
| 916 | + }); | ||
| 917 | + | ||
| 918 | + | ||
| 919 | + | ||
| 953 | }; | 920 | }; |
| 921 | + }); | ||
| 922 | + | ||
| 954 | }; | 923 | }; |
| 955 | 924 | ||
| 956 | 925 | ||
| 957 | - // }; | 926 | + }; |
| 927 | + | ||
| 928 | + | ||
| 929 | + | ||
| 930 | + | ||
| 931 | + | ||
| 932 | + | ||
| 933 | + | ||
| 934 | + | ||
| 935 | + | ||
| 936 | + | ||
| 937 | + | ||
| 938 | + | ||
| 958 | 939 | ||
| 959 | 940 | ||
| 960 | 941 | ||
| 961 | - if(action=="buy"){ // 立即购买 | 942 | + if(action=="buy"){ |
| 962 | //--------------此时操作的数据------------ | 943 | //--------------此时操作的数据------------ |
| 963 | var newd = { | 944 | var newd = { |
| 964 | id: th.data.data.id, | 945 | id: th.data.data.id, |
| @@ -980,23 +961,13 @@ Page({ | @@ -980,23 +961,13 @@ Page({ | ||
| 980 | newd['prom_type'] = 0; | 961 | newd['prom_type'] = 0; |
| 981 | newd['prom_price'] = this.data.data.shop_price; | 962 | newd['prom_price'] = this.data.data.shop_price; |
| 982 | }; | 963 | }; |
| 983 | - | ||
| 984 | - // 判断是否为0库存的情况 | ||
| 985 | - var tmpRedisNum = 0; | ||
| 986 | - // 检查redis库存量 | ||
| 987 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { | ||
| 988 | - if (res.data.code == 0) { | ||
| 989 | - tmpRedisNum = res.data.data; | ||
| 990 | - }; | ||
| 991 | - }); | ||
| 992 | - if(this.data.prom_type == 1 && tmpRedisNum == 0) { | ||
| 993 | - newd['prom_type'] = 0; | ||
| 994 | - newd['prom_price'] = this.data.data.shop_price; | ||
| 995 | - }; | ||
| 996 | 964 | ||
| 997 | // console.log('newd++++++++', newd); | 965 | // console.log('newd++++++++', newd); |
| 998 | th.buyNow(newd); | 966 | th.buyNow(newd); |
| 999 | - } else { // 购物车 | 967 | + } else { |
| 968 | + | ||
| 969 | + | ||
| 970 | + | ||
| 1000 | 971 | ||
| 1001 | var newd = { | 972 | var newd = { |
| 1002 | service_id: th.data.data.id, | 973 | service_id: th.data.data.id, |
| @@ -1023,19 +994,7 @@ Page({ | @@ -1023,19 +994,7 @@ Page({ | ||
| 1023 | newd['money'] = th.data.prom_price; | 994 | newd['money'] = th.data.prom_price; |
| 1024 | }; | 995 | }; |
| 1025 | }; | 996 | }; |
| 1026 | - | ||
| 1027 | - // 判断是否为0库存的情况 | ||
| 1028 | - var tmpRedisNum = 0; | ||
| 1029 | - // 检查redis库存量 | ||
| 1030 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { | ||
| 1031 | - if (res.data.code == 0) { | ||
| 1032 | - tmpRedisNum = res.data.data; | ||
| 1033 | - }; | ||
| 1034 | - }); | ||
| 1035 | - if(th.data.options.prom_type == 1 && tmpRedisNum == 0) { | ||
| 1036 | - newd['prom_type'] = 0; | ||
| 1037 | - newd['money'] = th.data.data.shop_price; | ||
| 1038 | - }; | 997 | + |
| 1039 | 998 | ||
| 1040 | //----先看会员在购物车中是否加入了该商品----- | 999 | //----先看会员在购物车中是否加入了该商品----- |
| 1041 | getApp().request.get("/api/weshop/cartService/page", { | 1000 | getApp().request.get("/api/weshop/cartService/page", { |
| @@ -1132,140 +1091,121 @@ Page({ | @@ -1132,140 +1091,121 @@ Page({ | ||
| 1132 | }, | 1091 | }, |
| 1133 | 1092 | ||
| 1134 | //------检查数量是不是超出限购------ | 1093 | //------检查数量是不是超出限购------ |
| 1135 | - checkCartNum: function(t) { | 1094 | + checkCartNum: async function(t) { |
| 1095 | + var th = this; | ||
| 1136 | 1096 | ||
| 1137 | - if(this.data.prom_type != 1) { | ||
| 1138 | - this.setData({goodsInputNum: t}); | ||
| 1139 | - return false; | 1097 | + if(!th.data.def_pick_store) { |
| 1098 | + wx.showModal({title: '请选择门店',}); | ||
| 1099 | + return false; | ||
| 1140 | }; | 1100 | }; |
| 1141 | 1101 | ||
| 1142 | - var th = this; | ||
| 1143 | - | ||
| 1144 | - // if(this.data.prom_act.is_shop_buy && this.data.options.prom_type != 1) { | ||
| 1145 | - | ||
| 1146 | - if(t == 0) return false; | ||
| 1147 | - // th.setData({goodsInputNum:t}); | 1102 | + // 非秒杀活动 |
| 1103 | + if(this.data.prom_type != 1) { | ||
| 1104 | + this.setData({ | ||
| 1105 | + goodsInputNum: t, | ||
| 1106 | + }); | ||
| 1107 | + }; | ||
| 1148 | 1108 | ||
| 1149 | - // if(this.data.options.prom_type == 1 && !this.data.openSpecModal_flash_normal) { | ||
| 1150 | - | ||
| 1151 | - this.get_buy_num(this.data.sele_g, async function () { | ||
| 1152 | - th.data.sele_g.viplimited = th.data.sele_g.buy_limit; | ||
| 1153 | - | ||
| 1154 | - //--判断商品是否超出限购-- | ||
| 1155 | - // if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { | ||
| 1156 | - // if(!th.data.prom_act.is_shop_buy) { | ||
| 1157 | - | ||
| 1158 | - // if (th.data.sele_g.viplimited > 0) { | ||
| 1159 | - // var gd_buy_num = th.data.sele_g.buy_num; | ||
| 1160 | - | ||
| 1161 | - // if (t + gd_buy_num> th.data.sele_g.viplimited) { | ||
| 1162 | - // wx.showModal({ | ||
| 1163 | - // title: '超出商品限购', | ||
| 1164 | - // }); | ||
| 1165 | - | ||
| 1166 | - // var num = th.data.sele_g.viplimited - gd_buy_num; | ||
| 1167 | - // if (num <= 0) num = 1; | ||
| 1168 | - // th.setData({goodsInputNum: num}) | ||
| 1169 | - // return false; | ||
| 1170 | - // } | ||
| 1171 | - // }; | ||
| 1172 | - | ||
| 1173 | - | ||
| 1174 | - // 单独购买 | ||
| 1175 | - if(th.data.openSpecModal_flash_normal) th.data.is_normal = 1; | ||
| 1176 | - | ||
| 1177 | - // 秒杀:判断活动是否抢光 | ||
| 1178 | - if (th.data.sele_g.prom_type == 1 && !th.data.is_normal) { | ||
| 1179 | - var redis_num = 0; | ||
| 1180 | - //------判断活动是否抢光----- | ||
| 1181 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | ||
| 1182 | - os.stoid + "/" + th.data.sele_g.prom_type + "/" + th.data.sele_g.prom_id, { | ||
| 1183 | - 1: 1 | ||
| 1184 | - }).then(res => { | ||
| 1185 | - redis_num = res.data.data; | 1109 | + // 秒杀活动 |
| 1110 | + if(this.data.prom_type == 1) { | ||
| 1111 | + // 如果是秒杀活动下的单独购买,is_normal为1 | ||
| 1112 | + if(this.data.openSpecModal_flash_normal) this.data.is_normal = 1; | ||
| 1113 | + | ||
| 1114 | + if(this.data.is_normal) {// 单独购买 | ||
| 1115 | + this.setData({ | ||
| 1116 | + goodsInputNum: t, | ||
| 1117 | + }); | ||
| 1118 | + } else {// 秒杀购买 | ||
| 1119 | + | ||
| 1120 | + // 获取redis当前可以购买的数量 | ||
| 1121 | + // 如果数量为0,设置和显示已抢光 | ||
| 1122 | + // 否则,进一步判断是否超出限购或超出库存 | ||
| 1123 | + await this.getactLen().then(async function(res) { | ||
| 1124 | + // res: redis可购买数量 | ||
| 1125 | + console.log('当前可以购买的数量:', res); | ||
| 1126 | + if(res <= 0) { | ||
| 1127 | + // 可购买数量<=0, 设置和显示已抢光 | ||
| 1128 | + th.setData({ | ||
| 1129 | + prom_r_null: 1, | ||
| 1130 | + }); | ||
| 1131 | + } else { | ||
| 1132 | + // 可购买数量>0 | ||
| 1133 | + // 计算自己还可以购买的数量 | ||
| 1134 | + // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b | ||
| 1135 | + // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存 | ||
| 1136 | + // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购 | ||
| 1137 | + let actInfo = th.data.sele_g; | ||
| 1138 | + await th.get_buy_num2().then(function (data) { | ||
| 1139 | + let limited = actInfo.buy_limit; // 限购数量a | ||
| 1140 | + let promcardbuynum = data.data.data.promcardbuynum; | ||
| 1141 | + let buyedNum = promcardbuynum; // 自己已经购买的数量b | ||
| 1142 | + let canBuyNum = limited - buyedNum; // 自己还可购买的数量c | ||
| 1143 | + | ||
| 1144 | + if(canBuyNum <= 0) { | ||
| 1145 | + canBuyNum = 0; | ||
| 1146 | + }; | ||
| 1147 | + | ||
| 1148 | + if(limited > res) { | ||
| 1149 | + if(t > res) { // t当前增减的数量 | ||
| 1150 | + wx.showModal({ | ||
| 1151 | + title: '超出活动库存', | ||
| 1186 | }); | 1152 | }); |
| 1187 | - | ||
| 1188 | - if (t > redis_num) { | ||
| 1189 | - wx.showModal({ | ||
| 1190 | - // title: '超出商品活动库存', | ||
| 1191 | - title: '超出活动库存', | ||
| 1192 | - }); | ||
| 1193 | - th.setData({goodsInputNum: redis_num}) | ||
| 1194 | - return false; | ||
| 1195 | - } | 1153 | + th.setData({ |
| 1154 | + goodsInputNum: res, | ||
| 1155 | + }); | ||
| 1156 | + return false; | ||
| 1196 | }; | 1157 | }; |
| 1197 | - | ||
| 1198 | - //--秒杀:判断商品是否超出活动限购-- | ||
| 1199 | - if (th.data.sele_g.viplimited > 0 && !th.data.is_normal && th.data.prom_type == 1) { | ||
| 1200 | - var gd_buy_num = th.data.promcardbuynum; | ||
| 1201 | - | ||
| 1202 | - // 如果限购数量>活动库存数量,增加数量时会先超过库存数量,此时应该提示“超出活动库存”; | ||
| 1203 | - // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” | ||
| 1204 | - if(th.data.sele_g.viplimited > th.data.sele_g.goods_num) { | ||
| 1205 | - | ||
| 1206 | - // 计算还可以购买的数量:库存量 - 已购数 | ||
| 1207 | - var num = th.data.sele_g.goods_num - gd_buy_num; | ||
| 1208 | - if(num < 0) num = 0; | ||
| 1209 | - if(t > num) { | ||
| 1210 | - wx.showModal({ | ||
| 1211 | - title: '超出活动库存', | ||
| 1212 | - }); | ||
| 1213 | - | ||
| 1214 | - th.setData({goodsInputNum: num}) | ||
| 1215 | - return false; | ||
| 1216 | - | ||
| 1217 | - }; | ||
| 1218 | - | ||
| 1219 | - } else { | ||
| 1220 | - if ((t + gd_buy_num> th.data.sele_g.viplimited) && (t<=th.data.sele_g.goods_num)) { | ||
| 1221 | - wx.showModal({ | ||
| 1222 | - title: '超出活动限购数量', | ||
| 1223 | - }); | ||
| 1224 | - | ||
| 1225 | - var num = th.data.sele_g.viplimited - gd_buy_num; | ||
| 1226 | - if (num <= 0) num = 1; | ||
| 1227 | - th.setData({goodsInputNum: num}) | ||
| 1228 | - return false; | ||
| 1229 | - }; | ||
| 1230 | - }; | ||
| 1231 | - | ||
| 1232 | - | ||
| 1233 | - | 1158 | + }; |
| 1159 | + | ||
| 1160 | + if(limited <= res) { | ||
| 1161 | + if(t>limited) { | ||
| 1162 | + wx.showModal({ | ||
| 1163 | + title: '超出限购数量', | ||
| 1164 | + }); | ||
| 1165 | + th.setData({ | ||
| 1166 | + goodsInputNum: canBuyNum, | ||
| 1167 | + }); | ||
| 1168 | + return false; | ||
| 1234 | }; | 1169 | }; |
| 1235 | - | ||
| 1236 | - //--秒杀:判断商品是否超出活动限购-- | ||
| 1237 | - // if (th.data.prom_buy_num != -1 && th.data.prom_buy_limit > 0 && !th.data.is_normal) { | ||
| 1238 | - // if (t + th.data.prom_buy_num > th.data.prom_buy_limit) { | ||
| 1239 | - // wx.showModal({ | ||
| 1240 | - // title: '超出商品活动限购', | ||
| 1241 | - // }); | 1170 | + }; |
| 1171 | + | ||
| 1172 | + th.setData({ | ||
| 1173 | + goodsInputNum: t, | ||
| 1174 | + }); | ||
| 1175 | + }); | ||
| 1176 | + }; | ||
| 1177 | + }); | ||
| 1242 | 1178 | ||
| 1243 | - // var num = th.data.prom_buy_limit - th.data.prom_buy_num; | ||
| 1244 | - // if (num < 0) num = 0; | ||
| 1245 | - // th.setData({goodsInputNum: num}) | ||
| 1246 | - // return false; | ||
| 1247 | - // }; | ||
| 1248 | - // }; | 1179 | + } |
| 1180 | + | ||
| 1181 | + | ||
| 1182 | + }; | ||
| 1183 | + | ||
| 1184 | + | ||
| 1185 | + | ||
| 1186 | + | ||
| 1187 | + | ||
| 1188 | + | ||
| 1249 | 1189 | ||
| 1250 | 1190 | ||
| 1251 | 1191 | ||
| 1252 | 1192 | ||
| 1253 | 1193 | ||
| 1254 | // var e = th.data.sele_g.goods_num; | 1194 | // var e = th.data.sele_g.goods_num; |
| 1255 | - var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4 | ||
| 1256 | - 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)) { | ||
| 1257 | - if (!th.data.def_pick_store) { | ||
| 1258 | - wx.showModal({title: '请选择门店',}); | ||
| 1259 | - return false; | ||
| 1260 | - } else { | ||
| 1261 | - // e = th.data.def_pick_store.CanOutQty; | ||
| 1262 | - } | ||
| 1263 | - } | 1195 | + // var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4 |
| 1196 | + // 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)) { | ||
| 1197 | + // if (!th.data.def_pick_store) { | ||
| 1198 | + // wx.showModal({title: '请选择门店',}); | ||
| 1199 | + // return false; | ||
| 1200 | + // } else { | ||
| 1201 | + // e = th.data.def_pick_store.CanOutQty; | ||
| 1202 | + // } | ||
| 1203 | + // } | ||
| 1264 | 1204 | ||
| 1265 | 1205 | ||
| 1266 | - th.setData({goodsInputNum: t}); | 1206 | + // th.setData({goodsInputNum: t}); |
| 1267 | 1207 | ||
| 1268 | - }); | 1208 | + // }); |
| 1269 | 1209 | ||
| 1270 | 1210 | ||
| 1271 | }, | 1211 | }, |
| @@ -3257,19 +3197,18 @@ Page({ | @@ -3257,19 +3197,18 @@ Page({ | ||
| 3257 | 3197 | ||
| 3258 | 3198 | ||
| 3259 | //获取redis中的数量 | 3199 | //获取redis中的数量 |
| 3260 | - async getactLen(func) { | ||
| 3261 | - var r_num = 0, | ||
| 3262 | - prom_type = this.data.prom_type, | ||
| 3263 | - prom_id = this.data.prom_id; | ||
| 3264 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { | 3200 | + async getactLen() { |
| 3201 | + let prom_type = this.data.options.prom_type; | ||
| 3202 | + let prom_id = this.data.options.prom_id; | ||
| 3203 | + return await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { | ||
| 3265 | 1: 1 | 3204 | 1: 1 |
| 3266 | }).then(res => { | 3205 | }).then(res => { |
| 3267 | - var em = res; | ||
| 3268 | - if (em.data.code == 0) { | ||
| 3269 | - r_num = em.data.data; | ||
| 3270 | - } | 3206 | + if (res.data.code == 0) { |
| 3207 | + // 当前可以购买的数量 | ||
| 3208 | + let r_num = res.data.data; | ||
| 3209 | + return r_num; | ||
| 3210 | + }; | ||
| 3271 | }) | 3211 | }) |
| 3272 | - func(r_num); | ||
| 3273 | }, | 3212 | }, |
| 3274 | 3213 | ||
| 3275 | 3214 | ||
| @@ -3508,7 +3447,7 @@ Page({ | @@ -3508,7 +3447,7 @@ Page({ | ||
| 3508 | //----获取商品购买数---- | 3447 | //----获取商品购买数---- |
| 3509 | if (th.data.prom_type == 1) { | 3448 | if (th.data.prom_type == 1) { |
| 3510 | //----获取活动购买数---- | 3449 | //----获取活动购买数---- |
| 3511 | - getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { | 3450 | + getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { |
| 3512 | data: { | 3451 | data: { |
| 3513 | store_id: os.stoid, | 3452 | store_id: os.stoid, |
| 3514 | user_id: user_id, | 3453 | user_id: user_id, |
| @@ -3536,6 +3475,49 @@ Page({ | @@ -3536,6 +3475,49 @@ Page({ | ||
| 3536 | }, | 3475 | }, |
| 3537 | 3476 | ||
| 3538 | 3477 | ||
| 3478 | + get_buy_num2: async function () { | ||
| 3479 | + // var map = this.data.g_buy_num, | ||
| 3480 | + var th = this, | ||
| 3481 | + user_id = getApp().globalData.user_id; | ||
| 3482 | + // if (user_id == null) { | ||
| 3483 | + // // map.set(gd.goods_id, 0); | ||
| 3484 | + // th.setData({ | ||
| 3485 | + // // g_buy_num: map, | ||
| 3486 | + // prom_buy_num: 0, | ||
| 3487 | + // }); | ||
| 3488 | + // "function" == typeof func && func(); | ||
| 3489 | + // return false; | ||
| 3490 | + // } | ||
| 3491 | + | ||
| 3492 | + | ||
| 3493 | + //----获取商品购买数---- | ||
| 3494 | + | ||
| 3495 | + //----获取活动购买数---- | ||
| 3496 | + return await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { | ||
| 3497 | + data: { | ||
| 3498 | + store_id: os.stoid, | ||
| 3499 | + user_id: user_id, | ||
| 3500 | + card_id: th.data.options.goods_id, | ||
| 3501 | + prom_type: th.data.options.prom_type, | ||
| 3502 | + prom_id: th.data.options.prom_id | ||
| 3503 | + }, | ||
| 3504 | + //-----获取----- | ||
| 3505 | + success: function (tt) { | ||
| 3506 | + if (tt.data.code == 0) { | ||
| 3507 | + // map.set(gd.goods_id, g_buy_num); | ||
| 3508 | + th.setData({ | ||
| 3509 | + // g_buy_num: map, | ||
| 3510 | + promcardbuynum: tt.data.data.promcardbuynum, | ||
| 3511 | + cardbuynum: tt.data.data.cardbuynum, | ||
| 3512 | + }); | ||
| 3513 | + } | ||
| 3514 | + } | ||
| 3515 | + }); | ||
| 3516 | + | ||
| 3517 | + | ||
| 3518 | + }, | ||
| 3519 | + | ||
| 3520 | + | ||
| 3539 | 3521 | ||
| 3540 | 3522 | ||
| 3541 | 3523 |
pages/cart/cart/cart.js
| @@ -2075,22 +2075,26 @@ Page({ | @@ -2075,22 +2075,26 @@ Page({ | ||
| 2075 | 2075 | ||
| 2076 | 2076 | ||
| 2077 | if(t.goods_num > redis_num) { | 2077 | if(t.goods_num > redis_num) { |
| 2078 | - wx.showToast({ | ||
| 2079 | - title: '超出活动库存', | ||
| 2080 | - icon: 'none', | ||
| 2081 | - }); | ||
| 2082 | - | 2078 | + // 开启限购 |
| 2083 | if (buylimit > 0) { | 2079 | if (buylimit > 0) { |
| 2080 | + wx.showToast({ | ||
| 2081 | + title: '超出活动限购', | ||
| 2082 | + icon: 'none', | ||
| 2083 | + }); | ||
| 2084 | let num = buylimit - gd_buy_num; | 2084 | let num = buylimit - gd_buy_num; |
| 2085 | if (num > redis_num) { | 2085 | if (num > redis_num) { |
| 2086 | th.setData({[txt]: redis_num}); | 2086 | th.setData({[txt]: redis_num}); |
| 2087 | } else { | 2087 | } else { |
| 2088 | + wx.showToast({ | ||
| 2089 | + title: '超出活动库存', | ||
| 2090 | + icon: 'none', | ||
| 2091 | + }); | ||
| 2088 | th.setData({[txt]: num}); | 2092 | th.setData({[txt]: num}); |
| 2089 | } | 2093 | } |
| 2090 | } else { | 2094 | } else { |
| 2091 | th.setData({[txt]: redis_num}); | 2095 | th.setData({[txt]: redis_num}); |
| 2092 | } | 2096 | } |
| 2093 | - | 2097 | + |
| 2094 | await e.doCheckAll(); | 2098 | await e.doCheckAll(); |
| 2095 | return false; | 2099 | return false; |
| 2096 | }; | 2100 | }; |