Commit 4eb2fe93999bcd23102a601158a3c1f9f18f3cb9

Authored by 后端研发-苏明海
2 parents 4cb9163f acc24ed9

Merge branch 'dev' into 'test'

Dev

See merge request !985
packageA/pages/details_serviceCard/details_serviceCard.js
... ... @@ -228,7 +228,7 @@ Page({
228 228  
229 229  
230 230 // 再来一单
231   - buy2(t) {
  231 + buy2: async function(t) {
232 232 let details = this.data.details;
233 233 var th = this;
234 234 var ind = 1; // 1:加入购物车
... ... @@ -288,17 +288,57 @@ Page({
288 288 if(details.list[0].prom_type == 1) {
289 289 newd['prom_type'] = details.list[0].prom_type;
290 290 newd['prom_id'] = details.list[0].prom_id;
291   - // if(th.data.openSpecModal_flash_normal) {
292   - // newd['money'] = th.data.data.shop_price;
293   - // newd['is_pd_normal'] = 1;
294   - // } else {
295   - // newd['money'] = th.data.prom_price;
296   - // };
297 291 };
298   -
  292 +
  293 + var prom_id = details.list[0].prom_id > 0 ? details.list[0].prom_id : 0;
  294 + var card_id = details.list[0].card_id;
  295 + var prom_type = details.list[0].prom_type > 0 ? details.list[0].prom_type : 0;
  296 + var is_pd_normal = details.list[0].is_pd_normal;
  297 + // 库存
  298 + var redisNums = 0;
  299 + // 限购数
  300 + var limitNum = 0;
  301 + // 已购买数量
  302 + var boughtNum = 0;
  303 +
  304 + // 秒杀活动中购买
  305 + if (prom_type == 1 && !is_pd_normal) {
  306 +
  307 + // 获取已购数量
  308 + await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+os.stoid+"&user_id="+getApp().globalData.user_id+"&card_id="+card_id+"&prom_type="+prom_type+"&prom_id="+prom_id, {
  309 + }).then(res => {
  310 + boughtNum = !res.data.data.promcardbuynum ? 0 : res.data.data.promcardbuynum;
  311 + });
  312 +
  313 + // 获取库存
  314 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
  315 + if (res.data.code == 0) {
  316 + redisNums = !res.data.data ? 0 : res.data.data;
  317 + };
  318 + });
  319 +
  320 + // 获取限购数
  321 + var user_id = getApp().globalData.user_id;
  322 + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + prom_id, {}).then(res => {
  323 + if (res.data.code == 0) {
  324 + limitNum = res.data.data.buy_limit;
  325 + }
  326 + });
  327 +
  328 + var snum = limitNum - boughtNum;
  329 + var snum = limitNum - boughtNum;
  330 + if (snum <= 0) {
  331 + wx.showModal({
  332 + title: '超出限购数量',
  333 + });
  334 + return false;
  335 + }
  336 +
  337 + }
  338 +
299 339  
300 340 //----先看会员在购物车中是否加入了该商品-----
301   - app.request.get("/api/weshop/cartService/page", {
  341 + app.request.get("/api/weshop/cartService/page", {
302 342 data: {
303 343 store_id: app.globalData.setting.stoid,
304 344 user_id: this.data.userInfo.user_id,
... ... @@ -306,13 +346,30 @@ Page({
306 346 pick_id: details.list[0].pickup_id,
307 347 },
308 348 success: function(re) {
309   -
310 349 //-------如果购物车中有相关的数据---------
311 350 if (re.data.data.total > 0) {
312 351 var item = re.data.data.pageData[0];
  352 + var totalNum = details.list[0].qty + item.goods_num;
  353 +
  354 + if (prom_type == 1 && !is_pd_normal) {
  355 + // 秒杀购物车购买 修正数量
  356 + var snum = limitNum - boughtNum;
  357 +
  358 + if (totalNum >= redisNums){
  359 + if (redisNums > snum) {
  360 + totalNum = snum;
  361 + } else {
  362 + totalNum = redisNums;
  363 + }
  364 + } else {
  365 + if (totalNum > snum)
  366 + totalNum = snum;
  367 + }
  368 + }
  369 +
313 370 var updata = {
314 371 id: item.id,
315   - goods_num: details.list[0].qty + item.goods_num,
  372 + goods_num: totalNum,
316 373 money: details.list[0].price,
317 374 store_id: app.globalData.setting.stoid,
318 375 };
... ... @@ -321,6 +378,7 @@ Page({
321 378 updata['guide_id'] = getApp().globalData.guide_id;
322 379 updata['guide_type'] = 1;
323 380 }
  381 +
324 382 getApp().request.put("/api/weshop/cartService/update", {
325 383 data: updata,
326 384 success: function(t) {
... ... @@ -333,6 +391,8 @@ Page({
333 391 // th.closeSpecModal();
334 392 }
335 393 });
  394 +
  395 +
336 396 } else {
337 397  
338 398 getApp().request.post("/api/weshop/cartService/save", {
... ...
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,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 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 835 addCart: async function(t) {
... ... @@ -848,8 +837,7 @@ Page({
848 837 var ind = t.currentTarget.dataset.openSpecModal_ind;
849 838 var action= t.currentTarget.dataset.action;
850 839 if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind;
851   - // 活动ID
852   - var prom_id = th.data.prom_id;
  840 +
853 841 th.setData({
854 842 open_ind_store: ind
855 843 });
... ... @@ -859,127 +847,96 @@ Page({
859 847 return false;
860 848 };
861 849  
862   - // 秒杀活动
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   - // 已经付款的单数,已经成功购买的数量
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, {
874   - }).then(res => {
875   - gd_buy_num = !res.data.data.promcardbuynum ? 0 : res.data.data.promcardbuynum;
876   - });
877   -
878   -
879   - // 检查redis库存量
880   - var redisNum = 0;
881   - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
882   - if (res.data.code == 0) {
883   - redisNum = !res.data.data ? 0 : res.data.data;
884   - };
885   - });
886   -
887   -
888   - // 有库存的情况下,走秒杀活动流程 否则 走正常购买流程
889   - // 没有库存,已抢光的情况下,走正常购买流程
890   - if(redisNum > 0 && !this.data.is_normal) {
891   - // 输入的数量
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,
899   - { }).then(res => {
900   - if (res.data.data.pageData.length > 0) {
901   - const tmpObj = res.data.data.pageData;
902   -
903   - tmpObj.forEach(v => {
904   - cartGoodsNum += parseInt(v.goods_num);
905   - });
906   -
907   - }
908   -
909   - });
  850 + // 库存
  851 + var redisNums = 0;
  852 + // 限购数
  853 + var limitNum = 0;
  854 + // 已购买数量
  855 + var boughtNum = 0;
  856 +
  857 + // 秒杀活动
  858 + if(this.data.prom_type == 1) {
  859 + // 如果是秒杀活动下的单独购买,is_normal为1
  860 + if(this.data.openSpecModal_flash_normal) this.data.is_normal = 1;
  861 +
  862 + if(!this.data.is_normal) {// 秒杀购买
  863 +
  864 + // 获取redis当前可以购买的数量
  865 + // 如果数量为0,设置和显示已抢光
  866 + // 否则,进一步判断是否超出限购或超出库存
  867 + await this.getactLen().then(async function(res) {
  868 + redisNums = res;
  869 + let curNum = th.data.goodsInputNum;
  870 + // res: redis可购买数量
  871 + console.log('当前可以购买的数量:', res);
  872 + if(res <= 0) {
  873 + // 可购买数量<=0, 设置和显示已抢光
  874 + th.setData({
  875 + prom_r_null: 1,
  876 + });
  877 + wx.showModal({
  878 + title: '超出活动库存',
  879 + });
  880 + return false;
  881 + } else {
  882 + // 可购买数量>0
  883 + // 计算自己还可以购买的数量
  884 + // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b
  885 + // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存
  886 + // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购
  887 + let actInfo = th.data.sele_g;
  888 + await th.get_buy_num2().then(function (data) {
  889 + let limited = actInfo.buy_limit; // 限购数量a
  890 + let promcardbuynum = data.data.data.promcardbuynum;
  891 + let buyedNum = promcardbuynum; // 自己已经购买的数量b
  892 + let canBuyNum = limited - buyedNum; // 自己还可购买的数量c
  893 + limitNum = limited;
  894 + boughtNum = buyedNum;
  895 +
  896 + if(canBuyNum <= 0) {
  897 + canBuyNum = 0;
  898 + };
910 899  
911   - // 输入的数量 + 购物车同款商品的数量
912   - t = parseInt(t) + parseInt(cartGoodsNum);
913   - }
914   -
915   - // 剩余购买数量
916   - let num = th.data.sele_g.viplimited - gd_buy_num;
917   - num = num < 0 ? 0 : num;
918   -
919   - if (t > redisNum) {
920   - wx.showToast({
  900 + if(limited > res) {
  901 + if(curNum > res) { // t当前增减的数量
  902 + wx.showModal({
921 903 title: '超出活动库存',
922   - icon: 'none'
923   - });
924   -
925   - // 开启限购
926   - if (th.data.sele_g.viplimited > 0) {
927   -
928   - if (action != "buy") {
929   - if (t > num) {
930   - th.setData({goodsInputNum: num - cartGoodsNum < 0 ? 0 : num - cartGoodsNum});
931   - }
932   - if (redisNum < num) {
933   - th.setData({goodsInputNum: redisNum - cartGoodsNum < 0 ? 0 : redisNum - cartGoodsNum});
934   - }
935   - } else {
936   - if (num > redisNum) {
937   - th.setData({goodsInputNum: redisNum});
938   - } else {
939   - th.setData({goodsInputNum: num});
940   - }
941   - }
942   -
943   -
944   -
945   -
946   - } else {
947   - th.setData({goodsInputNum: redisNum});
948   - }
949   -
950   - return false;
951   - }
952   -
953   - // 以下小于等于库存
954   - if (t <= redisNum) {
955   - if (th.data.sele_g.viplimited > 0) {
956   -
957   - if (t > num) {
958   - wx.showToast({
959   - title: '超出活动限购数量',
960   - icon: 'none'
961   - });
962   -
963   - if (num > redisNum) {
964   - th.setData({goodsInputNum: redisNum});
965   - } else {
966   - th.setData({goodsInputNum: num});
967   - }
968   - return false;
969   - }
970   -
971   - }
972   - }
  904 + });
  905 + th.setData({
  906 + goodsInputNum: res,
  907 + });
  908 + return false;
  909 + };
  910 + };
973 911  
974   -
  912 + if(limited <= res) {
  913 + if(curNum > limited) {
  914 + wx.showModal({
  915 + title: '超出限购数量',
  916 + });
  917 + th.setData({
  918 + goodsInputNum: canBuyNum,
  919 + });
  920 + return false;
  921 + };
  922 + };
  923 +
  924 +
  925 + });
  926 +
  927 +
  928 +
975 929 };
  930 + });
  931 +
976 932 };
977 933  
978 934  
  935 + };
979 936  
980 937  
981 938  
982   - if(action=="buy"){ // 立即购买
  939 + if(action=="buy"){
983 940 //--------------此时操作的数据------------
984 941 var newd = {
985 942 id: th.data.data.id,
... ... @@ -1001,30 +958,11 @@ Page({
1001 958 newd['prom_type'] = 0;
1002 959 newd['prom_price'] = this.data.data.shop_price;
1003 960 };
1004   -
1005   - // 判断是否为0库存的情况
1006   - var tmpRedisNum = 0;
1007   - // 检查redis库存量
1008   - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
1009   - if (res.data.code == 0) {
1010   - tmpRedisNum = res.data.data;
1011   - };
1012   - });
1013   - if(this.data.prom_type == 1 && tmpRedisNum == 0) {
1014   - newd['prom_type'] = 0;
1015   - newd['prom_price'] = this.data.data.shop_price;
1016   - };
1017 961  
1018 962 // console.log('newd++++++++', newd);
1019 963 th.buyNow(newd);
1020   - } else { // 购物车
1021   -
1022   - // 购买数量大于0的才能加入到购物车
1023   - if (th.data.goodsInputNum <= 0) {
1024   - th.closeSpecModal();
1025   - return false;
1026   - }
1027   -
  964 + } else {
  965 +
1028 966 var newd = {
1029 967 service_id: th.data.data.id,
1030 968 service_sn:th.data.data.service_sn,
... ... @@ -1050,19 +988,7 @@ Page({
1050 988 newd['money'] = th.data.prom_price;
1051 989 };
1052 990 };
1053   -
1054   - // 判断是否为0库存的情况
1055   - var tmpRedisNum = 0;
1056   - // 检查redis库存量
1057   - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
1058   - if (res.data.code == 0) {
1059   - tmpRedisNum = res.data.data;
1060   - };
1061   - });
1062   - if(th.data.options.prom_type == 1 && tmpRedisNum == 0) {
1063   - newd['prom_type'] = 0;
1064   - newd['money'] = th.data.data.shop_price;
1065   - };
  991 +
1066 992  
1067 993 //----先看会员在购物车中是否加入了该商品-----
1068 994 getApp().request.get("/api/weshop/cartService/page", {
... ... @@ -1076,10 +1002,33 @@ Page({
1076 1002  
1077 1003 //-------如果购物车中有相关的数据---------
1078 1004 if (re.data.data.total > 0) {
1079   - var item = re.data.data.pageData[0];
  1005 + var item = re.data.data.pageData[0];
  1006 + var totalNum = th.data.goodsInputNum + item.goods_num;
  1007 +
  1008 + // 秒杀购物车购买 修正数量
  1009 + if (th.data.prom_type == 1 && !th.data.is_normal) {
  1010 + var snum = limitNum - boughtNum;
  1011 + if (snum <= 0) {
  1012 + wx.showModal({
  1013 + title: '超出限购数量',
  1014 + });
  1015 + return false;
  1016 + }
  1017 + if (totalNum >= redisNums){
  1018 + if (redisNums > snum) {
  1019 + totalNum = snum;
  1020 + } else {
  1021 + totalNum = redisNums;
  1022 + }
  1023 + } else {
  1024 + if (totalNum > snum)
  1025 + totalNum = snum;
  1026 + }
  1027 + }
  1028 +
1080 1029 var updata = {
1081 1030 id: item.id,
1082   - goods_num: th.data.goodsInputNum + item.goods_num,
  1031 + goods_num: totalNum,
1083 1032 money: th.data.data.shop_price,
1084 1033 store_id: os.stoid,
1085 1034 };
... ... @@ -1106,7 +1055,7 @@ Page({
1106 1055 getApp().my_warnning('加入购物车成功', 1, th, 450);
1107 1056 var c_num = th.data.cartGoodsNum + th.data.goodsInputNum;
1108 1057 th.setData({
1109   - cartGoodsNum: c_num
  1058 + cartGoodsNum: totalNum
1110 1059 });
1111 1060 th.closeSpecModal();
1112 1061 }
... ... @@ -1159,142 +1108,121 @@ Page({
1159 1108 },
1160 1109  
1161 1110 //------检查数量是不是超出限购------
1162   - checkCartNum: function(t) {
  1111 + checkCartNum: async function(t) {
  1112 + var th = this;
1163 1113  
1164   - if(this.data.prom_type != 1) {
1165   - this.setData({goodsInputNum: t});
1166   - return false;
  1114 + if(!th.data.def_pick_store) {
  1115 + wx.showModal({title: '请选择门店',});
  1116 + return false;
1167 1117 };
1168 1118  
1169   - var th = this;
1170   -
1171   - // if(this.data.prom_act.is_shop_buy && this.data.options.prom_type != 1) {
1172   -
1173   - if(t == 0) return false;
1174   - // th.setData({goodsInputNum:t});
  1119 + // 非秒杀活动
  1120 + if(this.data.prom_type != 1) {
  1121 + this.setData({
  1122 + goodsInputNum: t,
  1123 + });
  1124 + };
1175 1125  
1176   - // if(this.data.options.prom_type == 1 && !this.data.openSpecModal_flash_normal) {
1177   -
1178   - this.get_buy_num(this.data.sele_g, async function () {
1179   - th.data.sele_g.viplimited = th.data.sele_g.buy_limit;
1180   -
1181   - //--判断商品是否超出限购--
1182   - // if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) {
1183   - // if(!th.data.prom_act.is_shop_buy) {
1184   -
1185   - // if (th.data.sele_g.viplimited > 0) {
1186   - // var gd_buy_num = th.data.sele_g.buy_num;
1187   -
1188   - // if (t + gd_buy_num> th.data.sele_g.viplimited) {
1189   - // wx.showModal({
1190   - // title: '超出商品限购',
1191   - // });
1192   -
1193   - // var num = th.data.sele_g.viplimited - gd_buy_num;
1194   - // if (num <= 0) num = 1;
1195   - // th.setData({goodsInputNum: num})
1196   - // return false;
1197   - // }
1198   - // };
1199   -
1200   -
1201   - // 单独购买
1202   - if(th.data.openSpecModal_flash_normal) th.data.is_normal = 1;
1203   -
1204   - // 秒杀:判断活动是否抢光
1205   - if (th.data.sele_g.prom_type == 1 && !th.data.is_normal) {
1206   - var redis_num = 0;
1207   - //------判断活动是否抢光-----
1208   - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
1209   - os.stoid + "/" + th.data.sele_g.prom_type + "/" + th.data.sele_g.prom_id, {
1210   - 1: 1
1211   - }).then(res => {
1212   - redis_num = res.data.data;
  1126 + // 秒杀活动
  1127 + if(this.data.prom_type == 1) {
  1128 + // 如果是秒杀活动下的单独购买,is_normal为1
  1129 + if(this.data.openSpecModal_flash_normal) this.data.is_normal = 1;
  1130 +
  1131 + if(this.data.is_normal) {// 单独购买
  1132 + this.setData({
  1133 + goodsInputNum: t,
  1134 + });
  1135 + } else {// 秒杀购买
  1136 +
  1137 + // 获取redis当前可以购买的数量
  1138 + // 如果数量为0,设置和显示已抢光
  1139 + // 否则,进一步判断是否超出限购或超出库存
  1140 + await this.getactLen().then(async function(res) {
  1141 + // res: redis可购买数量
  1142 + console.log('当前可以购买的数量:', res);
  1143 + if(res <= 0) {
  1144 + // 可购买数量<=0, 设置和显示已抢光
  1145 + th.setData({
  1146 + prom_r_null: 1,
  1147 + });
  1148 + } else {
  1149 + // 可购买数量>0
  1150 + // 计算自己还可以购买的数量
  1151 + // 自己还可购买的数量c = 每人活动限购数量a - 自己已经购买的数量b
  1152 + // 如果限购数量a>redis可购买数量d,当增加数量t>d, 提示超出库存
  1153 + // 如果限购数量a<=redis可购买数量d, 当增加数量t>a,提示超出限购
  1154 + let actInfo = th.data.sele_g;
  1155 + await th.get_buy_num2().then(function (data) {
  1156 + let limited = actInfo.buy_limit; // 限购数量a
  1157 + let promcardbuynum = data.data.data.promcardbuynum;
  1158 + let buyedNum = promcardbuynum; // 自己已经购买的数量b
  1159 + let canBuyNum = limited - buyedNum; // 自己还可购买的数量c
  1160 +
  1161 + if(canBuyNum <= 0) {
  1162 + canBuyNum = 0;
  1163 + };
  1164 +
  1165 + if(limited > res) {
  1166 + if(t > res) { // t当前增减的数量
  1167 + wx.showModal({
  1168 + title: '超出活动库存',
1213 1169 });
1214   -
1215   - if (t > redis_num) {
1216   - wx.showToast({
1217   - // title: '超出商品活动库存',
1218   - title: '超出活动库存',
1219   - icon: 'none',
1220   - });
1221   - th.setData({goodsInputNum: redis_num})
1222   - return false;
1223   - }
  1170 + th.setData({
  1171 + goodsInputNum: res,
  1172 + });
  1173 + return false;
1224 1174 };
1225   -
1226   - //--秒杀:判断商品是否超出活动限购--
1227   - if (th.data.sele_g.viplimited > 0 && !th.data.is_normal && th.data.prom_type == 1) {
1228   - var gd_buy_num = th.data.promcardbuynum;
1229   -
1230   - // 如果限购数量>活动库存数量,增加数量时会先超过库存数量,此时应该提示“超出活动库存”;
1231   - // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量”
1232   - if(th.data.sele_g.viplimited > th.data.sele_g.goods_num) {
1233   -
1234   - // 计算还可以购买的数量:库存量 - 已购数
1235   - var num = th.data.sele_g.goods_num - gd_buy_num;
1236   - if(num < 0) num = 0;
1237   - if(t > num) {
1238   - wx.showToast({
1239   - title: '超出活动库存',
1240   - icon: 'none',
1241   - });
1242   -
1243   - th.setData({goodsInputNum: num})
1244   - return false;
1245   -
1246   - };
1247   -
1248   - } else {
1249   - if ((t + gd_buy_num> th.data.sele_g.viplimited) && (t<=th.data.sele_g.goods_num)) {
1250   - wx.showToast({
1251   - title: '超出活动限购数量',
1252   - icon: 'none',
1253   - });
1254   -
1255   - var num = th.data.sele_g.viplimited - gd_buy_num;
1256   - if (num <= 0) num = 1;
1257   - th.setData({goodsInputNum: num})
1258   - return false;
1259   - };
1260   - };
1261   -
1262   -
1263   -
  1175 + };
  1176 +
  1177 + if(limited <= res) {
  1178 + if(t>limited) {
  1179 + wx.showModal({
  1180 + title: '超出限购数量',
  1181 + });
  1182 + th.setData({
  1183 + goodsInputNum: canBuyNum,
  1184 + });
  1185 + return false;
1264 1186 };
1265   -
1266   - //--秒杀:判断商品是否超出活动限购--
1267   - // if (th.data.prom_buy_num != -1 && th.data.prom_buy_limit > 0 && !th.data.is_normal) {
1268   - // if (t + th.data.prom_buy_num > th.data.prom_buy_limit) {
1269   - // wx.showModal({
1270   - // title: '超出商品活动限购',
1271   - // });
  1187 + };
  1188 +
  1189 + th.setData({
  1190 + goodsInputNum: t,
  1191 + });
  1192 + });
  1193 + };
  1194 + });
1272 1195  
1273   - // var num = th.data.prom_buy_limit - th.data.prom_buy_num;
1274   - // if (num < 0) num = 0;
1275   - // th.setData({goodsInputNum: num})
1276   - // return false;
1277   - // };
1278   - // };
  1196 + }
  1197 +
  1198 +
  1199 + };
  1200 +
  1201 +
  1202 +
  1203 +
  1204 +
  1205 +
1279 1206  
1280 1207  
1281 1208  
1282 1209  
1283 1210  
1284 1211 // var e = th.data.sele_g.goods_num;
1285   - var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4
1286   - 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)) {
1287   - if (!th.data.def_pick_store) {
1288   - wx.showModal({title: '请选择门店',});
1289   - return false;
1290   - } else {
1291   - // e = th.data.def_pick_store.CanOutQty;
1292   - }
1293   - }
1294   -
1295   - th.setData({goodsInputNum: t});
  1212 + // var p_type = th.data.prom_type; //&& p_type!=1 && p_type!=4
  1213 + // 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)) {
  1214 + // if (!th.data.def_pick_store) {
  1215 + // wx.showModal({title: '请选择门店',});
  1216 + // return false;
  1217 + // } else {
  1218 + // e = th.data.def_pick_store.CanOutQty;
  1219 + // }
  1220 + // }
  1221 +
  1222 +
  1223 + // th.setData({goodsInputNum: t});
1296 1224  
1297   - });
  1225 + // });
1298 1226  
1299 1227  
1300 1228 },
... ... @@ -1326,12 +1254,10 @@ Page({
1326 1254 return false;
1327 1255 }
1328 1256  
1329   - var ind = t.currentTarget.dataset.ind;
1330   -
  1257 + var ind = t.currentTarget.dataset.ind;
1331 1258 this.setData({
1332 1259 openSpecModal: !0,
1333   - openSpecModal_ind: ind,
1334   - goodsInputNum: 1,
  1260 + openSpecModal_ind: ind,
1335 1261 });
1336 1262  
1337 1263 },
... ... @@ -3288,19 +3214,18 @@ Page({
3288 3214  
3289 3215  
3290 3216 //获取redis中的数量
3291   - async getactLen(func) {
3292   - var r_num = 0,
3293   - prom_type = this.data.prom_type,
3294   - prom_id = this.data.prom_id;
3295   - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
  3217 + async getactLen() {
  3218 + let prom_type = this.data.options.prom_type;
  3219 + let prom_id = this.data.options.prom_id;
  3220 + return await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/" + prom_type + "/" + prom_id, {
3296 3221 1: 1
3297 3222 }).then(res => {
3298   - var em = res;
3299   - if (em.data.code == 0) {
3300   - r_num = em.data.data;
3301   - }
  3223 + if (res.data.code == 0) {
  3224 + // 当前可以购买的数量
  3225 + let r_num = res.data.data;
  3226 + return r_num;
  3227 + };
3302 3228 })
3303   - func(r_num);
3304 3229 },
3305 3230  
3306 3231  
... ... @@ -3539,7 +3464,7 @@ Page({
3539 3464 //----获取商品购买数----
3540 3465 if (th.data.prom_type == 1) {
3541 3466 //----获取活动购买数----
3542   - getApp().request.get("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", {
  3467 + getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", {
3543 3468 data: {
3544 3469 store_id: os.stoid,
3545 3470 user_id: user_id,
... ... @@ -3567,6 +3492,49 @@ Page({
3567 3492 },
3568 3493  
3569 3494  
  3495 + get_buy_num2: async function () {
  3496 + // var map = this.data.g_buy_num,
  3497 + var th = this,
  3498 + user_id = getApp().globalData.user_id;
  3499 + // if (user_id == null) {
  3500 + // // map.set(gd.goods_id, 0);
  3501 + // th.setData({
  3502 + // // g_buy_num: map,
  3503 + // prom_buy_num: 0,
  3504 + // });
  3505 + // "function" == typeof func && func();
  3506 + // return false;
  3507 + // }
  3508 +
  3509 +
  3510 + //----获取商品购买数----
  3511 +
  3512 + //----获取活动购买数----
  3513 + return await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum", {
  3514 + data: {
  3515 + store_id: os.stoid,
  3516 + user_id: user_id,
  3517 + card_id: th.data.options.goods_id,
  3518 + prom_type: th.data.options.prom_type,
  3519 + prom_id: th.data.options.prom_id
  3520 + },
  3521 + //-----获取-----
  3522 + success: function (tt) {
  3523 + if (tt.data.code == 0) {
  3524 + // map.set(gd.goods_id, g_buy_num);
  3525 + th.setData({
  3526 + // g_buy_num: map,
  3527 + promcardbuynum: tt.data.data.promcardbuynum,
  3528 + cardbuynum: tt.data.data.cardbuynum,
  3529 + });
  3530 + }
  3531 + }
  3532 + });
  3533 +
  3534 +
  3535 + },
  3536 +
  3537 +
3570 3538  
3571 3539  
3572 3540  
... ...
pages/cart/cart/cart.js
... ... @@ -2073,7 +2073,9 @@ Page({
2073 2073 icon: 'none',
2074 2074 });
2075 2075 th.setData({[txt]: redis_num});
2076   - await e.doCheckAll();
  2076 + t.goods_num = redis_num;
  2077 + await th.doCheckAll();
  2078 + await th.update_cart_ser(t, pitem, item);
2077 2079 return false;
2078 2080 };
2079 2081  
... ... @@ -2114,14 +2116,22 @@ Page({
2114 2116 if (buylimit > 0) {
2115 2117 if (num > redis_num) {
2116 2118 th.setData({[txt]: redis_num-cartGoodsNum});
  2119 + t.goods_num = redis_num-cartGoodsNum;
  2120 + await th.doCheckAll();
  2121 + await th.update_cart_ser(t, pitem, item);
2117 2122 } else {
2118 2123 th.setData({[txt]: num - cartGoodsNum});
  2124 + t.goods_num = num - cartGoodsNum;
  2125 + await th.doCheckAll();
  2126 + await th.update_cart_ser(t, pitem, item);
2119 2127 }
2120 2128 } else {
2121 2129 th.setData({[txt]: redis_num - cartGoodsNum});
  2130 + t.goods_num = redis_num - cartGoodsNum;
  2131 + await th.doCheckAll();
  2132 + await th.update_cart_ser(t, pitem, item);
2122 2133 }
2123 2134  
2124   - await e.doCheckAll();
2125 2135 return false;
2126 2136 };
2127 2137  
... ... @@ -2138,7 +2148,9 @@ Page({
2138 2148 });
2139 2149 if (num <= 0) num = 1;
2140 2150 th.setData({[txt]: num - cartGoodsNum});
2141   - await e.doCheckAll();
  2151 + t.goods_num = num - cartGoodsNum;
  2152 + await th.doCheckAll();
  2153 + await th.update_cart_ser(t, pitem, item);
2142 2154 return false;
2143 2155 };
2144 2156  
... ...