Commit da959847c64e5401f189766c4da0fda20b857781

Authored by 泉州测试
1 parent 5cfde18d

fix:购物车库存限制

packageA/pages/goodsInfo/goodsInfo.js
@@ -843,12 +843,16 @@ Page({ @@ -843,12 +843,16 @@ Page({
843 }, 843 },
844 844
845 //------------加入购物车-------------- 845 //------------加入购物车--------------
846 - addCart: function(t) { 846 + addCart: async function(t) {
847 var th = this; 847 var th = this;
848 var ind = t.currentTarget.dataset.openSpecModal_ind; 848 var ind = t.currentTarget.dataset.openSpecModal_ind;
849 var action= t.currentTarget.dataset.action; 849 var action= t.currentTarget.dataset.action;
850 if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind; 850 if(!ind) ind = t.currentTarget.dataset.openspecmodal_ind;
851 - 851 + // 活动ID
  852 + var prom_id = th.data.prom_id;
  853 +
  854 + var redisNum = 0;
  855 +
852 th.setData({ 856 th.setData({
853 open_ind_store: ind 857 open_ind_store: ind
854 }); 858 });
@@ -859,69 +863,79 @@ Page({ @@ -859,69 +863,79 @@ Page({
859 }; 863 };
860 864
861 865
862 -  
863 -  
864 - //000000  
865 - //如果是秒杀的话,要看redis够不够  
866 - // if (this.data.prom_type == 1) {  
867 -  
868 - // if (this.data.openSpecModal_flash_normal) {  
869 - // this.data.is_normal=1; //是普通购买  
870 - // return false;  
871 - // }  
872 -  
873 -  
874 - // this.getactLen(function (num) {  
875 - // if (num < th.data.goodsInputNum) {  
876 - // getApp().my_warnning("活动库存不足!", 0, th);  
877 - // return false;  
878 - // } else {  
879 - // // th.add_cart_func(t);  
880 - // }  
881 - // });  
882 - // } else {  
883 - // // th.add_cart_func(t);  
884 - // }  
885 - //000000  
886 -  
887 // if(!this.data.openSpecModal_ind) { 866 // if(!this.data.openSpecModal_ind) {
888 if(this.data.prom_type == 1) { 867 if(this.data.prom_type == 1) {
889 this.data.sele_g.viplimited = this.data.sele_g.buy_limit; 868 this.data.sele_g.viplimited = this.data.sele_g.buy_limit;
890 869
891 - if(this.data.sele_g.viplimited > 0 && !this.data.is_normal) { 870 + if(!this.data.is_normal) {
  871 + // 输入的数量
892 var t = th.data.goodsInputNum; 872 var t = th.data.goodsInputNum;
  873 +
  874 + // 检查redis库存量
  875 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
  876 + os.stoid + "/1/" + prom_id,
  877 + {}
  878 + ).then(res => {
  879 + if (res.data.code == 0) {
  880 + redisNum = res.data.data;
  881 + };
  882 + });
  883 +
  884 + if (t > redisNum) {
  885 + wx.showModal({
  886 + title: '超出活动库存',
  887 + });
  888 + return false;
  889 + }
  890 +
  891 + // 获取购物车同类数量 判断是否超库存
  892 + var cartGoodsNum = 0;
  893 + 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,
  894 + { }).then(res => {
  895 + if (res.data.data.pageData.length > 0) {
  896 + const tmpObj = res.data.data.pageData[0];
  897 + cartGoodsNum = tmpObj.goods_num;
  898 + }
  899 +
  900 + });
  901 +
  902 + if (cartGoodsNum >= redisNum) {
  903 + wx.showModal({
  904 + title: '超出活动库存',
  905 + });
  906 + return false;
  907 + }
  908 +
  909 + // 每人限购数
893 th.data.sele_g.viplimited = th.data.sele_g.buy_limit; 910 th.data.sele_g.viplimited = th.data.sele_g.buy_limit;
  911 +
  912 + // 是否开启个人限购
894 if (th.data.sele_g.viplimited > 0) { 913 if (th.data.sele_g.viplimited > 0) {
895 - var gd_buy_num = th.data.sele_g.buy_num;  
896 - 914 + // 已经付款的单数
  915 + var gd_buy_num = th.data.sele_g.buy_num;
  916 +
897 if (t + gd_buy_num > th.data.sele_g.viplimited) { 917 if (t + gd_buy_num > th.data.sele_g.viplimited) {
898 wx.showModal({ 918 wx.showModal({
899 - title: '超出活动库存', 919 + title: '超出活动限购数量',
900 }); 920 });
901 921
902 let num = th.data.sele_g.viplimited - gd_buy_num; 922 let num = th.data.sele_g.viplimited - gd_buy_num;
903 if (num <= 0) num = 1; 923 if (num <= 0) num = 1;
904 th.setData({goodsInputNum: num}); 924 th.setData({goodsInputNum: num});
905 return false; 925 return false;
906 - } 926 + }
  927 +
  928 +
907 }; 929 };
908 }; 930 };
909 }; 931 };
910 932
911 933
912 -  
913 // }; 934 // };
914 935
915 -  
916 -  
917 -  
918 -  
919 -  
920 -  
921 -  
922 936
923 937
924 - if(action=="buy"){ 938 + if(action=="buy"){ // 直接购买
925 //--------------此时操作的数据------------ 939 //--------------此时操作的数据------------
926 var newd = { 940 var newd = {
927 id: th.data.data.id, 941 id: th.data.data.id,
@@ -946,10 +960,7 @@ Page({ @@ -946,10 +960,7 @@ Page({
946 960
947 // console.log('newd++++++++', newd); 961 // console.log('newd++++++++', newd);
948 th.buyNow(newd); 962 th.buyNow(newd);
949 - } else {  
950 -  
951 -  
952 - 963 + } else { // 购物车
953 964
954 var newd = { 965 var newd = {
955 service_id: th.data.data.id, 966 service_id: th.data.data.id,
@@ -976,7 +987,6 @@ Page({ @@ -976,7 +987,6 @@ Page({
976 newd['money'] = th.data.prom_price; 987 newd['money'] = th.data.prom_price;
977 }; 988 };
978 }; 989 };
979 -  
980 990
981 //----先看会员在购物车中是否加入了该商品----- 991 //----先看会员在购物车中是否加入了该商品-----
982 getApp().request.get("/api/weshop/cartService/page", { 992 getApp().request.get("/api/weshop/cartService/page", {