Commit 67b506fbe2d9324af6cea3eecbfce0507afd85f0

Authored by yvan.ni
2 parents c590a695 6b3a4638

Merge branch 'dev' of http://git.vipzhuang.cn/wxd/MShopWeApp into dev

packageA/pages/cart2_ser/cart2_ser.js
@@ -484,6 +484,8 @@ Page({ @@ -484,6 +484,8 @@ Page({
484 'price': gg.money, 484 'price': gg.money,
485 'pickup_id': gg.pick_id, 485 'pickup_id': gg.pick_id,
486 'pickup_keyid': list[i].keyid, 486 'pickup_keyid': list[i].keyid,
  487 + 'prom_type': gg.prom_type, //促销活动类型
  488 + 'prom_id': gg.prom_id, //促销活动id
487 }; 489 };
488 //--导购分享过来的id-- 490 //--导购分享过来的id--
489 if (gg.guide_id) { 491 if (gg.guide_id) {
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,106 @@ Page({ @@ -859,69 +863,106 @@ 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 -  
891 - if(this.data.sele_g.viplimited > 0 && !this.data.is_normal) { 869 +
  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 + 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 + if (maxNum > redisNum) {
  910 + wx.showModal({
  911 + title: '超出活动库存',
  912 + });
  913 + return false;
  914 + }
  915 +
  916 + // 是否开启个人限购
  917 + if (th.data.sele_g.viplimited > 0) {
  918 +
  919 + if (maxNum + th.data.sele_g.buy_num > th.data.sele_g.buy_limit) {
  920 + wx.showModal({
  921 + title: '超出活动限购数量',
  922 + });
  923 + return false;
  924 + }
  925 +
  926 + }
  927 +
  928 +
  929 +
  930 + }
  931 +
  932 + // 以下为立即购买
  933 + // 每人限购数
893 th.data.sele_g.viplimited = th.data.sele_g.buy_limit; 934 th.data.sele_g.viplimited = th.data.sele_g.buy_limit;
  935 +
  936 + // 是否开启个人限购
894 if (th.data.sele_g.viplimited > 0) { 937 if (th.data.sele_g.viplimited > 0) {
895 - var gd_buy_num = th.data.sele_g.buy_num;  
896 - 938 + // 已经付款的单数
  939 + var gd_buy_num = th.data.sele_g.buy_num;
  940 +
897 if (t + gd_buy_num > th.data.sele_g.viplimited) { 941 if (t + gd_buy_num > th.data.sele_g.viplimited) {
898 wx.showModal({ 942 wx.showModal({
899 - title: '超出活动库存', 943 + title: '超出活动限购数量',
900 }); 944 });
901 945
902 let num = th.data.sele_g.viplimited - gd_buy_num; 946 let num = th.data.sele_g.viplimited - gd_buy_num;
903 if (num <= 0) num = 1; 947 if (num <= 0) num = 1;
904 th.setData({goodsInputNum: num}); 948 th.setData({goodsInputNum: num});
905 return false; 949 return false;
906 - } 950 + }
  951 +
  952 +
907 }; 953 };
  954 +
  955 +
  956 +
908 }; 957 };
909 }; 958 };
910 959
911 960
912 -  
913 // }; 961 // };
914 962
915 -  
916 -  
917 -  
918 -  
919 -  
920 -  
921 -  
922 963
923 964
924 - if(action=="buy"){ 965 + if(action=="buy"){ // 立即购买
925 //--------------此时操作的数据------------ 966 //--------------此时操作的数据------------
926 var newd = { 967 var newd = {
927 id: th.data.data.id, 968 id: th.data.data.id,
@@ -946,10 +987,7 @@ Page({ @@ -946,10 +987,7 @@ Page({
946 987
947 // console.log('newd++++++++', newd); 988 // console.log('newd++++++++', newd);
948 th.buyNow(newd); 989 th.buyNow(newd);
949 - } else {  
950 -  
951 -  
952 - 990 + } else { // 购物车
953 991
954 var newd = { 992 var newd = {
955 service_id: th.data.data.id, 993 service_id: th.data.data.id,
@@ -976,7 +1014,6 @@ Page({ @@ -976,7 +1014,6 @@ Page({
976 newd['money'] = th.data.prom_price; 1014 newd['money'] = th.data.prom_price;
977 }; 1015 };
978 }; 1016 };
979 -  
980 1017
981 //----先看会员在购物车中是否加入了该商品----- 1018 //----先看会员在购物车中是否加入了该商品-----
982 getApp().request.get("/api/weshop/cartService/page", { 1019 getApp().request.get("/api/weshop/cartService/page", {
@@ -1129,7 +1166,7 @@ Page({ @@ -1129,7 +1166,7 @@ Page({
1129 if (t > redis_num) { 1166 if (t > redis_num) {
1130 wx.showModal({ 1167 wx.showModal({
1131 // title: '超出商品活动库存', 1168 // title: '超出商品活动库存',
1132 - title: '来晚了,已被抢光~', 1169 + title: '超出活动库存',
1133 }); 1170 });
1134 th.setData({goodsInputNum: redis_num}) 1171 th.setData({goodsInputNum: redis_num})
1135 return false; 1172 return false;