Commit ec5b07d3e14f057e8c261235e2d80370b5b26717

Authored by 泉州测试
1 parent c3372aa0

fix服务卡商品业购物业限购和库存问题

packageA/pages/goodsInfo/goodsInfo.js
... ... @@ -447,7 +447,7 @@ Page({
447 447 sto_sele_name: e.pickup_name,
448 448 sto_sele_id: e.pickup_id,
449 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 562 // <---- 秒杀
563 563  
564 564  
565   -
566   -
567   -
568 565  
569 566  
570 567  
... ... @@ -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 846 addCart: async function(t) {
... ... @@ -837,7 +848,11 @@ Page({
837 848 var ind = t.currentTarget.dataset.openSpecModal_ind;
838 849 var action= t.currentTarget.dataset.action;
839 850 if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind;
840   -
  851 + // 活动ID
  852 + var prom_id = th.data.prom_id;
  853 +
  854 +
  855 +
841 856 th.setData({
842 857 open_ind_store: ind
843 858 });
... ... @@ -848,98 +863,126 @@ Page({
848 863 };
849 864  
850 865  
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({
  866 + if(this.data.prom_type == 1) {
  867 +
  868 + this.data.sele_g.viplimited = this.data.sele_g.buy_limit;
  869 +
  870 + // 每人限购数
  871 + th.data.sele_g.viplimited = th.data.sele_g.buy_limit;
  872 +
  873 + // 已经付款的单数
  874 + var gd_buy_num = !th.data.sele_g.buy_num ? 0 : th.data.sele_g.buy_num;
  875 +
  876 + // 检查redis库存量
  877 + var redisNum = 0;
  878 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
  879 + if (res.data.code == 0) {
  880 + redisNum = res.data.data;
  881 + };
  882 + });
  883 +
  884 + // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程
  885 + // 没有库存,已抢光的情况下,走正常购买流程
  886 + if(redisNum > 0 && !this.data.is_normal) {
  887 + // 输入的数量
  888 + var t = th.data.goodsInputNum;
  889 +
  890 + if (t > redisNum) {
  891 + wx.showModal({
894 892 title: '超出活动库存',
895   - });
896   - th.setData({
897   - goodsInputNum: res,
898   - });
899   - return false;
900   - };
901   - };
902   -
903   - if(limited <= res) {
904   - if(curNum > limited) {
  893 + });
  894 +
  895 + // 开启限购
  896 + if (th.data.sele_g.viplimited > 0) {
  897 + let num = th.data.sele_g.viplimited - gd_buy_num;
  898 + if (num > redisNum) {
  899 + th.setData({goodsInputNum: redisNum});
  900 + } else {
  901 + th.setData({goodsInputNum: num});
  902 + }
  903 + } else {
  904 + th.setData({goodsInputNum: redisNum});
  905 + }
  906 +
  907 +
  908 + return false;
  909 + }
  910 +
  911 + // 获取购物车同款数量 判断是否超库存
  912 + var cartGoodsNum = 0;
  913 + 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,
  914 + { }).then(res => {
  915 + if (res.data.data.pageData.length > 0) {
  916 + const tmpObj = res.data.data.pageData[0];
  917 + cartGoodsNum = !tmpObj.goods_num ? 0 : tmpObj.goods_num;
  918 + }
  919 +
  920 + });
  921 +
  922 + // 跳过<立即购买> 购物车
  923 + if (action !="buy") {
  924 +
  925 + // 输入的数量 + 购物车同款商品的数量
  926 + var maxNum = parseInt(t) + parseInt(cartGoodsNum);
  927 +
  928 + // 是否开启个人限购
  929 + if (th.data.sele_g.viplimited > 0) {
  930 +
  931 + if (maxNum + gd_buy_num > th.data.sele_g.buy_limit) {
  932 + wx.showModal({
  933 + title: '超出活动限购数量',
  934 + });
  935 +
  936 + // 可购买数量
  937 + let num = th.data.sele_g.viplimited - gd_buy_num - cartGoodsNum;
  938 + th.setData({goodsInputNum: num});
  939 + return false;
  940 + }
  941 +
  942 + }
  943 +
  944 + if (maxNum > redisNum) {
905 945 wx.showModal({
906   - title: '超出限购数量',
907   - });
908   - th.setData({
909   - goodsInputNum: canBuyNum,
  946 + title: '超出活动库存',
910 947 });
  948 + // 可购买数量
  949 + let num = redisNum - cartGoodsNum;
  950 + th.setData({goodsInputNum: num});
911 951 return false;
  952 + }
  953 +
  954 + } else {
  955 +
  956 + // 以下为立即购买
  957 + // 是否开启个人限购
  958 + if (th.data.sele_g.viplimited > 0) {
  959 +
  960 + if (t + gd_buy_num > th.data.sele_g.viplimited) {
  961 + wx.showModal({
  962 + title: '超出活动限购数量',
  963 + });
  964 +
  965 + let num = th.data.sele_g.viplimited - gd_buy_num;
  966 + if (num > redisNum) {
  967 + th.setData({goodsInputNum: redisNum});
  968 + } else {
  969 + th.setData({goodsInputNum: num});
  970 + }
  971 + return false;
  972 + }
  973 +
  974 +
912 975 };
913   - };
914   -
915   -
916   - });
917   -
918   -
919   -
  976 + }
  977 +
920 978 };
921   - });
922   -
923 979 };
924 980  
925 981  
926   - };
927   -
928   -
929   -
930   -
931   -
932   -
933   -
934   -
935   -
936   -
937   -
938   -
939 982  
940 983  
941 984  
942   - if(action=="buy"){
  985 + if(action=="buy"){ // 立即购买
943 986 //--------------此时操作的数据------------
944 987 var newd = {
945 988 id: th.data.data.id,
... ... @@ -961,13 +1004,23 @@ Page({
961 1004 newd['prom_type'] = 0;
962 1005 newd['prom_price'] = this.data.data.shop_price;
963 1006 };
  1007 +
  1008 + // 判断是否为0库存的情况
  1009 + var tmpRedisNum = 0;
  1010 + // 检查redis库存量
  1011 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
  1012 + if (res.data.code == 0) {
  1013 + tmpRedisNum = res.data.data;
  1014 + };
  1015 + });
  1016 + if(this.data.prom_type == 1 && tmpRedisNum == 0) {
  1017 + newd['prom_type'] = 0;
  1018 + newd['prom_price'] = this.data.data.shop_price;
  1019 + };
964 1020  
965 1021 // console.log('newd++++++++', newd);
966 1022 th.buyNow(newd);
967   - } else {
968   -
969   -
970   -
  1023 + } else { // 购物车
971 1024  
972 1025 var newd = {
973 1026 service_id: th.data.data.id,
... ... @@ -994,7 +1047,19 @@ Page({
994 1047 newd['money'] = th.data.prom_price;
995 1048 };
996 1049 };
997   -
  1050 +
  1051 + // 判断是否为0库存的情况
  1052 + var tmpRedisNum = 0;
  1053 + // 检查redis库存量
  1054 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
  1055 + if (res.data.code == 0) {
  1056 + tmpRedisNum = res.data.data;
  1057 + };
  1058 + });
  1059 + if(th.data.options.prom_type == 1 && tmpRedisNum == 0) {
  1060 + newd['prom_type'] = 0;
  1061 + newd['money'] = th.data.data.shop_price;
  1062 + };
998 1063  
999 1064 //----先看会员在购物车中是否加入了该商品-----
1000 1065 getApp().request.get("/api/weshop/cartService/page", {
... ... @@ -1091,121 +1156,140 @@ Page({
1091 1156 },
1092 1157  
1093 1158 //------检查数量是不是超出限购------
1094   - checkCartNum: async function(t) {
1095   - var th = this;
  1159 + checkCartNum: function(t) {
1096 1160  
1097   - if(!th.data.def_pick_store) {
1098   - wx.showModal({title: '请选择门店',});
1099   - return false;
1100   - };
1101   -
1102   - // 非秒杀活动
1103 1161 if(this.data.prom_type != 1) {
1104   - this.setData({
1105   - goodsInputNum: t,
1106   - });
  1162 + this.setData({goodsInputNum: t});
  1163 + return false;
1107 1164 };
1108 1165  
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   - };
  1166 + var th = this;
1183 1167  
  1168 + // if(this.data.prom_act.is_shop_buy && this.data.options.prom_type != 1) {
  1169 +
  1170 + if(t == 0) return false;
  1171 + // th.setData({goodsInputNum:t});
1184 1172  
1185   -
  1173 + // if(this.data.options.prom_type == 1 && !this.data.openSpecModal_flash_normal) {
  1174 +
  1175 + this.get_buy_num(this.data.sele_g, async function () {
  1176 + th.data.sele_g.viplimited = th.data.sele_g.buy_limit;
  1177 +
  1178 + //--判断商品是否超出限购--
  1179 + // if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) {
  1180 + // if(!th.data.prom_act.is_shop_buy) {
  1181 +
  1182 + // if (th.data.sele_g.viplimited > 0) {
  1183 + // var gd_buy_num = th.data.sele_g.buy_num;
  1184 +
  1185 + // if (t + gd_buy_num> th.data.sele_g.viplimited) {
  1186 + // wx.showModal({
  1187 + // title: '超出商品限购',
  1188 + // });
  1189 +
  1190 + // var num = th.data.sele_g.viplimited - gd_buy_num;
  1191 + // if (num <= 0) num = 1;
  1192 + // th.setData({goodsInputNum: num})
  1193 + // return false;
  1194 + // }
  1195 + // };
  1196 +
  1197 +
  1198 + // 单独购买
  1199 + if(th.data.openSpecModal_flash_normal) th.data.is_normal = 1;
  1200 +
  1201 + // 秒杀:判断活动是否抢光
  1202 + if (th.data.sele_g.prom_type == 1 && !th.data.is_normal) {
  1203 + var redis_num = 0;
  1204 + //------判断活动是否抢光-----
  1205 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
  1206 + os.stoid + "/" + th.data.sele_g.prom_type + "/" + th.data.sele_g.prom_id, {
  1207 + 1: 1
  1208 + }).then(res => {
  1209 + redis_num = res.data.data;
  1210 + });
  1211 +
  1212 + if (t > redis_num) {
  1213 + wx.showModal({
  1214 + // title: '超出商品活动库存',
  1215 + title: '超出活动库存',
  1216 + });
  1217 + th.setData({goodsInputNum: redis_num})
  1218 + return false;
  1219 + }
  1220 + };
1186 1221  
  1222 + //--秒杀:判断商品是否超出活动限购--
  1223 + if (th.data.sele_g.viplimited > 0 && !th.data.is_normal && th.data.prom_type == 1) {
  1224 + var gd_buy_num = th.data.promcardbuynum;
  1225 +
  1226 + // 如果限购数量>活动库存数量,增加数量时会先超过库存数量,此时应该提示“超出活动库存”;
  1227 + // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量”
  1228 + if(th.data.sele_g.viplimited > th.data.sele_g.goods_num) {
  1229 +
  1230 + // 计算还可以购买的数量:库存量 - 已购数
  1231 + var num = th.data.sele_g.goods_num - gd_buy_num;
  1232 + if(num < 0) num = 0;
  1233 + if(t > num) {
  1234 + wx.showModal({
  1235 + title: '超出活动库存',
  1236 + });
  1237 +
  1238 + th.setData({goodsInputNum: num})
  1239 + return false;
  1240 +
  1241 + };
  1242 +
  1243 + } else {
  1244 + if ((t + gd_buy_num> th.data.sele_g.viplimited) && (t<=th.data.sele_g.goods_num)) {
  1245 + wx.showModal({
  1246 + title: '超出活动限购数量',
  1247 + });
  1248 +
  1249 + var num = th.data.sele_g.viplimited - gd_buy_num;
  1250 + if (num <= 0) num = 1;
  1251 + th.setData({goodsInputNum: num})
  1252 + return false;
  1253 + };
  1254 + };
  1255 +
  1256 +
  1257 +
  1258 + };
1187 1259  
1188   -
  1260 + //--秒杀:判断商品是否超出活动限购--
  1261 + // if (th.data.prom_buy_num != -1 && th.data.prom_buy_limit > 0 && !th.data.is_normal) {
  1262 + // if (t + th.data.prom_buy_num > th.data.prom_buy_limit) {
  1263 + // wx.showModal({
  1264 + // title: '超出商品活动限购',
  1265 + // });
  1266 +
  1267 + // var num = th.data.prom_buy_limit - th.data.prom_buy_num;
  1268 + // if (num < 0) num = 0;
  1269 + // th.setData({goodsInputNum: num})
  1270 + // return false;
  1271 + // };
  1272 + // };
1189 1273  
1190 1274  
1191 1275  
1192 1276  
1193 1277  
1194 1278 // 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   - // }
  1279 + var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4
  1280 + 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)) {
  1281 + if (!th.data.def_pick_store) {
  1282 + wx.showModal({title: '请选择门店',});
  1283 + return false;
  1284 + } else {
  1285 + // e = th.data.def_pick_store.CanOutQty;
  1286 + }
  1287 + }
1204 1288  
1205 1289  
1206   - // th.setData({goodsInputNum: t});
  1290 + th.setData({goodsInputNum: t});
1207 1291  
1208   - // });
  1292 + });
1209 1293  
1210 1294  
1211 1295 },
... ... @@ -3197,18 +3281,19 @@ Page({
3197 3281  
3198 3282  
3199 3283 //获取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, {
  3284 + async getactLen(func) {
  3285 + var r_num = 0,
  3286 + prom_type = this.data.prom_type,
  3287 + prom_id = this.data.prom_id;
  3288 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
3204 3289 1: 1
3205 3290 }).then(res => {
3206   - if (res.data.code == 0) {
3207   - // 当前可以购买的数量
3208   - let r_num = res.data.data;
3209   - return r_num;
3210   - };
  3291 + var em = res;
  3292 + if (em.data.code == 0) {
  3293 + r_num = em.data.data;
  3294 + }
3211 3295 })
  3296 + func(r_num);
3212 3297 },
3213 3298  
3214 3299  
... ... @@ -3447,7 +3532,7 @@ Page({
3447 3532 //----获取商品购买数----
3448 3533 if (th.data.prom_type == 1) {
3449 3534 //----获取活动购买数----
3450   - getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", {
  3535 + getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", {
3451 3536 data: {
3452 3537 store_id: os.stoid,
3453 3538 user_id: user_id,
... ... @@ -3475,49 +3560,6 @@ Page({
3475 3560 },
3476 3561  
3477 3562  
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 3563  
3522 3564  
3523 3565  
... ...
pages/cart/cart/cart.js
... ... @@ -1131,10 +1131,11 @@ Page({
1131 1131 },
1132 1132 //-------------减数量---------------------
1133 1133 subNum_ser: function (t) {
  1134 +
1134 1135 if (!this.data.is_load) return false;
1135 1136 if (this.data.up_dating == 1) return false;
1136 1137 this.data.up_dating = 1;
1137   -
  1138 +
1138 1139 var a = t.currentTarget.dataset.item;
1139 1140 var b = t.currentTarget.dataset.pitems;
1140 1141 a = this.data.service_data[b].goods[a];
... ...