Commit 06ae20d20ca691fc4ef0ff807cff986ee3348170
1 parent
724d1a39
限购
Showing
1 changed file
with
307 additions
and
246 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,9 +562,6 @@ Page({ | @@ -562,9 +562,6 @@ Page({ | ||
562 | // <---- 秒杀 | 562 | // <---- 秒杀 |
563 | 563 | ||
564 | 564 | ||
565 | - | ||
566 | - | ||
567 | - | ||
568 | 565 | ||
569 | 566 | ||
570 | 567 | ||
@@ -829,7 +826,21 @@ Page({ | @@ -829,7 +826,21 @@ Page({ | ||
829 | }); | 826 | }); |
830 | }, | 827 | }, |
831 | 828 | ||
832 | - | 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 | + }, | ||
833 | 844 | ||
834 | //------------加入购物车-------------- | 845 | //------------加入购物车-------------- |
835 | addCart: async function(t) { | 846 | addCart: async function(t) { |
@@ -837,7 +848,8 @@ Page({ | @@ -837,7 +848,8 @@ Page({ | ||
837 | var ind = t.currentTarget.dataset.openSpecModal_ind; | 848 | var ind = t.currentTarget.dataset.openSpecModal_ind; |
838 | var action= t.currentTarget.dataset.action; | 849 | var action= t.currentTarget.dataset.action; |
839 | if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; | 850 | if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; |
840 | - | 851 | + // 活动ID |
852 | + var prom_id = th.data.prom_id; | ||
841 | th.setData({ | 853 | th.setData({ |
842 | open_ind_store: ind | 854 | open_ind_store: ind |
843 | }); | 855 | }); |
@@ -848,98 +860,144 @@ Page({ | @@ -848,98 +860,144 @@ Page({ | ||
848 | }; | 860 | }; |
849 | 861 | ||
850 | 862 | ||
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({ | 863 | + if(this.data.prom_type == 1) { |
864 | + | ||
865 | + this.data.sele_g.viplimited = this.data.sele_g.buy_limit; | ||
866 | + | ||
867 | + // 每人限购数 | ||
868 | + th.data.sele_g.viplimited = th.data.sele_g.buy_limit; | ||
869 | + | ||
870 | + // 已经付款的单数 | ||
871 | + var gd_buy_num = !th.data.sele_g.buy_num ? 0 : th.data.sele_g.buy_num; | ||
872 | + | ||
873 | + // 检查redis库存量 | ||
874 | + var redisNum = 0; | ||
875 | + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { | ||
876 | + if (res.data.code == 0) { | ||
877 | + redisNum = !res.data.data ? 0 : res.data.data; | ||
878 | + }; | ||
879 | + }); | ||
880 | + | ||
881 | + // 获取购物车同款数量 判断是否超库存 | ||
882 | + var cartGoodsNum = 0; | ||
883 | + 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, | ||
884 | + { }).then(res => { | ||
885 | + if (res.data.data.pageData.length > 0) { | ||
886 | + const tmpObj = res.data.data.pageData[0]; | ||
887 | + cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num; | ||
888 | + } | ||
889 | + | ||
890 | + }); | ||
891 | + | ||
892 | + // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程 | ||
893 | + // 没有库存,已抢光的情况下,走正常购买流程 | ||
894 | + if(redisNum > 0 && !this.data.is_normal) { | ||
895 | + // 输入的数量 | ||
896 | + var t = th.data.goodsInputNum; | ||
897 | + | ||
898 | + if (t > redisNum) { | ||
899 | + wx.showToast({ | ||
894 | title: '超出活动库存', | 900 | title: '超出活动库存', |
895 | - }); | ||
896 | - th.setData({ | ||
897 | - goodsInputNum: res, | ||
898 | - }); | ||
899 | - return false; | ||
900 | - }; | ||
901 | - }; | 901 | + icon: 'none' |
902 | + }); | ||
903 | + | ||
904 | + // 开启限购 | ||
905 | + if (th.data.sele_g.viplimited > 0) { | ||
906 | + | ||
907 | + let num = th.data.sele_g.viplimited - gd_buy_num; | ||
908 | + if (action !="buy") { | ||
909 | + // 购物车 | ||
910 | + if (num > redisNum) { | ||
911 | + th.setData({goodsInputNum: redisNum - cartGoodsNum < 0 ? 0 : redisNum - cartGoodsNum}); | ||
912 | + } else { | ||
913 | + th.setData({goodsInputNum: num - cartGoodsNum < 0 ? 0 : num - cartGoodsNum}); | ||
914 | + } | ||
915 | + } else { | ||
916 | + // 立即购买 | ||
917 | + if (num > redisNum) { | ||
918 | + th.setData({goodsInputNum: redisNum}); | ||
919 | + } else { | ||
920 | + th.setData({goodsInputNum: num}); | ||
921 | + } | ||
922 | + } | ||
923 | + | ||
924 | + | ||
925 | + } else { | ||
926 | + th.setData({goodsInputNum: redisNum}); | ||
927 | + } | ||
928 | + | ||
929 | + return false; | ||
930 | + } | ||
931 | + | ||
902 | 932 | ||
903 | - if(limited <= res) { | ||
904 | - if(curNum > limited) { | ||
905 | - wx.showModal({ | ||
906 | - title: '超出限购数量', | ||
907 | - }); | ||
908 | - th.setData({ | ||
909 | - goodsInputNum: canBuyNum, | 933 | + |
934 | + // 跳过<立即购买> 购物车 | ||
935 | + if (action !="buy") { | ||
936 | + | ||
937 | + // 输入的数量 + 购物车同款商品的数量 | ||
938 | + var maxNum = parseInt(t) + parseInt(cartGoodsNum); | ||
939 | + | ||
940 | + // 是否开启个人限购 | ||
941 | + if (th.data.sele_g.viplimited > 0) { | ||
942 | + | ||
943 | + if (maxNum + gd_buy_num > th.data.sele_g.buy_limit) { | ||
944 | + wx.showToast({ | ||
945 | + title: '超出活动限购数量', | ||
946 | + icon: 'none' | ||
947 | + }); | ||
948 | + | ||
949 | + // 可购买数量 | ||
950 | + let num = th.data.sele_g.viplimited - gd_buy_num - cartGoodsNum; | ||
951 | + th.setData({goodsInputNum: num}); | ||
952 | + return false; | ||
953 | + } | ||
954 | + | ||
955 | + } | ||
956 | + | ||
957 | + if (maxNum > redisNum) { | ||
958 | + wx.showToast({ | ||
959 | + title: '超出活动库存', | ||
960 | + icon: 'none' | ||
910 | }); | 961 | }); |
962 | + // 可购买数量 | ||
963 | + let num = redisNum - cartGoodsNum; | ||
964 | + th.setData({goodsInputNum: num}); | ||
911 | return false; | 965 | return false; |
966 | + } | ||
967 | + | ||
968 | + } else { | ||
969 | + // 以下为立即购买 | ||
970 | + // 是否开启个人限购 | ||
971 | + if (th.data.sele_g.viplimited > 0) { | ||
972 | + | ||
973 | + if (t + gd_buy_num > th.data.sele_g.viplimited) { | ||
974 | + wx.showToast({ | ||
975 | + title: '超出活动限购数量', | ||
976 | + icon: 'none' | ||
977 | + }); | ||
978 | + | ||
979 | + let num = th.data.sele_g.viplimited - gd_buy_num; | ||
980 | + if (num > redisNum) { | ||
981 | + th.setData({goodsInputNum: redisNum}); | ||
982 | + } else { | ||
983 | + th.setData({goodsInputNum: num}); | ||
984 | + } | ||
985 | + return false; | ||
986 | + } | ||
987 | + | ||
988 | + | ||
912 | }; | 989 | }; |
913 | - }; | ||
914 | - | ||
915 | - | ||
916 | - }); | ||
917 | - | ||
918 | - | ||
919 | - | 990 | + |
991 | + } | ||
992 | + | ||
920 | }; | 993 | }; |
921 | - }); | ||
922 | - | ||
923 | }; | 994 | }; |
924 | 995 | ||
925 | 996 | ||
926 | - }; | ||
927 | - | ||
928 | - | ||
929 | - | ||
930 | - | ||
931 | - | ||
932 | - | ||
933 | - | ||
934 | - | ||
935 | - | ||
936 | - | ||
937 | - | ||
938 | - | ||
939 | 997 | ||
940 | 998 | ||
941 | 999 | ||
942 | - if(action=="buy"){ | 1000 | + if(action=="buy"){ // 立即购买 |
943 | //--------------此时操作的数据------------ | 1001 | //--------------此时操作的数据------------ |
944 | var newd = { | 1002 | var newd = { |
945 | id: th.data.data.id, | 1003 | id: th.data.data.id, |
@@ -961,13 +1019,23 @@ Page({ | @@ -961,13 +1019,23 @@ Page({ | ||
961 | newd['prom_type'] = 0; | 1019 | newd['prom_type'] = 0; |
962 | newd['prom_price'] = this.data.data.shop_price; | 1020 | newd['prom_price'] = this.data.data.shop_price; |
963 | }; | 1021 | }; |
1022 | + | ||
1023 | + // 判断是否为0库存的情况 | ||
1024 | + var tmpRedisNum = 0; | ||
1025 | + // 检查redis库存量 | ||
1026 | + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { | ||
1027 | + if (res.data.code == 0) { | ||
1028 | + tmpRedisNum = res.data.data; | ||
1029 | + }; | ||
1030 | + }); | ||
1031 | + if(this.data.prom_type == 1 && tmpRedisNum == 0) { | ||
1032 | + newd['prom_type'] = 0; | ||
1033 | + newd['prom_price'] = this.data.data.shop_price; | ||
1034 | + }; | ||
964 | 1035 | ||
965 | // console.log('newd++++++++', newd); | 1036 | // console.log('newd++++++++', newd); |
966 | th.buyNow(newd); | 1037 | th.buyNow(newd); |
967 | - } else { | ||
968 | - | ||
969 | - | ||
970 | - | 1038 | + } else { // 购物车 |
971 | 1039 | ||
972 | var newd = { | 1040 | var newd = { |
973 | service_id: th.data.data.id, | 1041 | service_id: th.data.data.id, |
@@ -994,7 +1062,19 @@ Page({ | @@ -994,7 +1062,19 @@ Page({ | ||
994 | newd['money'] = th.data.prom_price; | 1062 | newd['money'] = th.data.prom_price; |
995 | }; | 1063 | }; |
996 | }; | 1064 | }; |
997 | - | 1065 | + |
1066 | + // 判断是否为0库存的情况 | ||
1067 | + var tmpRedisNum = 0; | ||
1068 | + // 检查redis库存量 | ||
1069 | + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => { | ||
1070 | + if (res.data.code == 0) { | ||
1071 | + tmpRedisNum = res.data.data; | ||
1072 | + }; | ||
1073 | + }); | ||
1074 | + if(th.data.options.prom_type == 1 && tmpRedisNum == 0) { | ||
1075 | + newd['prom_type'] = 0; | ||
1076 | + newd['money'] = th.data.data.shop_price; | ||
1077 | + }; | ||
998 | 1078 | ||
999 | //----先看会员在购物车中是否加入了该商品----- | 1079 | //----先看会员在购物车中是否加入了该商品----- |
1000 | getApp().request.get("/api/weshop/cartService/page", { | 1080 | getApp().request.get("/api/weshop/cartService/page", { |
@@ -1091,121 +1171,142 @@ Page({ | @@ -1091,121 +1171,142 @@ Page({ | ||
1091 | }, | 1171 | }, |
1092 | 1172 | ||
1093 | //------检查数量是不是超出限购------ | 1173 | //------检查数量是不是超出限购------ |
1094 | - checkCartNum: async function(t) { | ||
1095 | - var th = this; | 1174 | + checkCartNum: function(t) { |
1096 | 1175 | ||
1097 | - if(!th.data.def_pick_store) { | ||
1098 | - wx.showModal({title: '请选择门店',}); | ||
1099 | - return false; | ||
1100 | - }; | ||
1101 | - | ||
1102 | - // 非秒杀活动 | ||
1103 | if(this.data.prom_type != 1) { | 1176 | if(this.data.prom_type != 1) { |
1104 | - this.setData({ | ||
1105 | - goodsInputNum: t, | ||
1106 | - }); | 1177 | + this.setData({goodsInputNum: t}); |
1178 | + return false; | ||
1107 | }; | 1179 | }; |
1108 | 1180 | ||
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: '超出活动库存', | ||
1152 | - }); | ||
1153 | - th.setData({ | ||
1154 | - goodsInputNum: res, | ||
1155 | - }); | ||
1156 | - return false; | ||
1157 | - }; | ||
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; | ||
1169 | - }; | ||
1170 | - }; | ||
1171 | - | ||
1172 | - th.setData({ | ||
1173 | - goodsInputNum: t, | ||
1174 | - }); | ||
1175 | - }); | ||
1176 | - }; | ||
1177 | - }); | ||
1178 | - | ||
1179 | - } | ||
1180 | - | ||
1181 | - | ||
1182 | - }; | 1181 | + var th = this; |
1183 | 1182 | ||
1183 | + // if(this.data.prom_act.is_shop_buy && this.data.options.prom_type != 1) { | ||
1184 | + | ||
1185 | + if(t == 0) return false; | ||
1186 | + // th.setData({goodsInputNum:t}); | ||
1184 | 1187 | ||
1185 | - | 1188 | + // if(this.data.options.prom_type == 1 && !this.data.openSpecModal_flash_normal) { |
1189 | + | ||
1190 | + this.get_buy_num(this.data.sele_g, async function () { | ||
1191 | + th.data.sele_g.viplimited = th.data.sele_g.buy_limit; | ||
1192 | + | ||
1193 | + //--判断商品是否超出限购-- | ||
1194 | + // if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { | ||
1195 | + // if(!th.data.prom_act.is_shop_buy) { | ||
1196 | + | ||
1197 | + // if (th.data.sele_g.viplimited > 0) { | ||
1198 | + // var gd_buy_num = th.data.sele_g.buy_num; | ||
1199 | + | ||
1200 | + // if (t + gd_buy_num> th.data.sele_g.viplimited) { | ||
1201 | + // wx.showModal({ | ||
1202 | + // title: '超出商品限购', | ||
1203 | + // }); | ||
1204 | + | ||
1205 | + // var num = th.data.sele_g.viplimited - gd_buy_num; | ||
1206 | + // if (num <= 0) num = 1; | ||
1207 | + // th.setData({goodsInputNum: num}) | ||
1208 | + // return false; | ||
1209 | + // } | ||
1210 | + // }; | ||
1211 | + | ||
1212 | + | ||
1213 | + // 单独购买 | ||
1214 | + if(th.data.openSpecModal_flash_normal) th.data.is_normal = 1; | ||
1215 | + | ||
1216 | + // 秒杀:判断活动是否抢光 | ||
1217 | + if (th.data.sele_g.prom_type == 1 && !th.data.is_normal) { | ||
1218 | + var redis_num = 0; | ||
1219 | + //------判断活动是否抢光----- | ||
1220 | + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | ||
1221 | + os.stoid + "/" + th.data.sele_g.prom_type + "/" + th.data.sele_g.prom_id, { | ||
1222 | + 1: 1 | ||
1223 | + }).then(res => { | ||
1224 | + redis_num = res.data.data; | ||
1225 | + }); | ||
1226 | + | ||
1227 | + if (t > redis_num) { | ||
1228 | + wx.showToast({ | ||
1229 | + // title: '超出商品活动库存', | ||
1230 | + title: '超出活动库存', | ||
1231 | + icon: 'none', | ||
1232 | + }); | ||
1233 | + th.setData({goodsInputNum: redis_num}) | ||
1234 | + return false; | ||
1235 | + } | ||
1236 | + }; | ||
1186 | 1237 | ||
1238 | + //--秒杀:判断商品是否超出活动限购-- | ||
1239 | + if (th.data.sele_g.viplimited > 0 && !th.data.is_normal && th.data.prom_type == 1) { | ||
1240 | + var gd_buy_num = th.data.promcardbuynum; | ||
1241 | + | ||
1242 | + // 如果限购数量>活动库存数量,增加数量时会先超过库存数量,此时应该提示“超出活动库存”; | ||
1243 | + // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” | ||
1244 | + if(th.data.sele_g.viplimited > th.data.sele_g.goods_num) { | ||
1245 | + | ||
1246 | + // 计算还可以购买的数量:库存量 - 已购数 | ||
1247 | + var num = th.data.sele_g.goods_num - gd_buy_num; | ||
1248 | + if(num < 0) num = 0; | ||
1249 | + if(t > num) { | ||
1250 | + wx.showToast({ | ||
1251 | + title: '超出活动库存', | ||
1252 | + icon: 'none', | ||
1253 | + }); | ||
1254 | + | ||
1255 | + th.setData({goodsInputNum: num}) | ||
1256 | + return false; | ||
1257 | + | ||
1258 | + }; | ||
1259 | + | ||
1260 | + } else { | ||
1261 | + if ((t + gd_buy_num> th.data.sele_g.viplimited) && (t<=th.data.sele_g.goods_num)) { | ||
1262 | + wx.showToast({ | ||
1263 | + title: '超出活动限购数量', | ||
1264 | + icon: 'none', | ||
1265 | + }); | ||
1266 | + | ||
1267 | + var num = th.data.sele_g.viplimited - gd_buy_num; | ||
1268 | + if (num <= 0) num = 1; | ||
1269 | + th.setData({goodsInputNum: num}) | ||
1270 | + return false; | ||
1271 | + }; | ||
1272 | + }; | ||
1273 | + | ||
1274 | + | ||
1275 | + | ||
1276 | + }; | ||
1187 | 1277 | ||
1188 | - | 1278 | + //--秒杀:判断商品是否超出活动限购-- |
1279 | + // if (th.data.prom_buy_num != -1 && th.data.prom_buy_limit > 0 && !th.data.is_normal) { | ||
1280 | + // if (t + th.data.prom_buy_num > th.data.prom_buy_limit) { | ||
1281 | + // wx.showModal({ | ||
1282 | + // title: '超出商品活动限购', | ||
1283 | + // }); | ||
1284 | + | ||
1285 | + // var num = th.data.prom_buy_limit - th.data.prom_buy_num; | ||
1286 | + // if (num < 0) num = 0; | ||
1287 | + // th.setData({goodsInputNum: num}) | ||
1288 | + // return false; | ||
1289 | + // }; | ||
1290 | + // }; | ||
1189 | 1291 | ||
1190 | 1292 | ||
1191 | 1293 | ||
1192 | 1294 | ||
1193 | 1295 | ||
1194 | // var e = th.data.sele_g.goods_num; | 1296 | // var e = th.data.sele_g.goods_num; |
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 | - // } | ||
1204 | - | ||
1205 | - | ||
1206 | - // th.setData({goodsInputNum: t}); | 1297 | + var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4 |
1298 | + 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)) { | ||
1299 | + if (!th.data.def_pick_store) { | ||
1300 | + wx.showModal({title: '请选择门店',}); | ||
1301 | + return false; | ||
1302 | + } else { | ||
1303 | + // e = th.data.def_pick_store.CanOutQty; | ||
1304 | + } | ||
1305 | + } | ||
1306 | + | ||
1307 | + th.setData({goodsInputNum: t}); | ||
1207 | 1308 | ||
1208 | - // }); | 1309 | + }); |
1209 | 1310 | ||
1210 | 1311 | ||
1211 | }, | 1312 | }, |
@@ -1237,10 +1338,12 @@ Page({ | @@ -1237,10 +1338,12 @@ Page({ | ||
1237 | return false; | 1338 | return false; |
1238 | } | 1339 | } |
1239 | 1340 | ||
1240 | - var ind = t.currentTarget.dataset.ind; | 1341 | + var ind = t.currentTarget.dataset.ind; |
1342 | + | ||
1241 | this.setData({ | 1343 | this.setData({ |
1242 | openSpecModal: !0, | 1344 | openSpecModal: !0, |
1243 | - openSpecModal_ind: ind, | 1345 | + openSpecModal_ind: ind, |
1346 | + goodsInputNum: 1, | ||
1244 | }); | 1347 | }); |
1245 | 1348 | ||
1246 | }, | 1349 | }, |
@@ -3197,18 +3300,19 @@ Page({ | @@ -3197,18 +3300,19 @@ Page({ | ||
3197 | 3300 | ||
3198 | 3301 | ||
3199 | //获取redis中的数量 | 3302 | //获取redis中的数量 |
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, { | 3303 | + async getactLen(func) { |
3304 | + var r_num = 0, | ||
3305 | + prom_type = this.data.prom_type, | ||
3306 | + prom_id = this.data.prom_id; | ||
3307 | + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, { | ||
3204 | 1: 1 | 3308 | 1: 1 |
3205 | }).then(res => { | 3309 | }).then(res => { |
3206 | - if (res.data.code == 0) { | ||
3207 | - // 当前可以购买的数量 | ||
3208 | - let r_num = res.data.data; | ||
3209 | - return r_num; | ||
3210 | - }; | 3310 | + var em = res; |
3311 | + if (em.data.code == 0) { | ||
3312 | + r_num = em.data.data; | ||
3313 | + } | ||
3211 | }) | 3314 | }) |
3315 | + func(r_num); | ||
3212 | }, | 3316 | }, |
3213 | 3317 | ||
3214 | 3318 | ||
@@ -3447,7 +3551,7 @@ Page({ | @@ -3447,7 +3551,7 @@ Page({ | ||
3447 | //----获取商品购买数---- | 3551 | //----获取商品购买数---- |
3448 | if (th.data.prom_type == 1) { | 3552 | if (th.data.prom_type == 1) { |
3449 | //----获取活动购买数---- | 3553 | //----获取活动购买数---- |
3450 | - getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { | 3554 | + getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", { |
3451 | data: { | 3555 | data: { |
3452 | store_id: os.stoid, | 3556 | store_id: os.stoid, |
3453 | user_id: user_id, | 3557 | user_id: user_id, |
@@ -3475,49 +3579,6 @@ Page({ | @@ -3475,49 +3579,6 @@ Page({ | ||
3475 | }, | 3579 | }, |
3476 | 3580 | ||
3477 | 3581 | ||
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 | - | ||
3521 | 3582 | ||
3522 | 3583 | ||
3523 | 3584 |