Commit 4a706205a1df4e1609c83a5d8245ac0ff9a0cd19

Authored by 泉州测试
1 parent c4d1d430

fix修改购物车行为

packageA/pages/goodsInfo/goodsInfo.js
@@ -847,6 +847,12 @@ Page({ @@ -847,6 +847,12 @@ Page({
847 return false; 847 return false;
848 }; 848 };
849 849
  850 + // 库存
  851 + var redisNums = 0;
  852 + // 限购数
  853 + var limitNum = 0;
  854 + // 已购买数量
  855 + var boughtNum = 0;
850 856
851 // 秒杀活动 857 // 秒杀活动
852 if(this.data.prom_type == 1) { 858 if(this.data.prom_type == 1) {
@@ -859,6 +865,7 @@ Page({ @@ -859,6 +865,7 @@ Page({
859 // 如果数量为0,设置和显示已抢光 865 // 如果数量为0,设置和显示已抢光
860 // 否则,进一步判断是否超出限购或超出库存 866 // 否则,进一步判断是否超出限购或超出库存
861 await this.getactLen().then(async function(res) { 867 await this.getactLen().then(async function(res) {
  868 + redisNums = res;
862 let curNum = th.data.goodsInputNum; 869 let curNum = th.data.goodsInputNum;
863 // res: redis可购买数量 870 // res: redis可购买数量
864 console.log('当前可以购买的数量:', res); 871 console.log('当前可以购买的数量:', res);
@@ -883,7 +890,9 @@ Page({ @@ -883,7 +890,9 @@ Page({
883 let promcardbuynum = data.data.data.promcardbuynum; 890 let promcardbuynum = data.data.data.promcardbuynum;
884 let buyedNum = promcardbuynum; // 自己已经购买的数量b 891 let buyedNum = promcardbuynum; // 自己已经购买的数量b
885 let canBuyNum = limited - buyedNum; // 自己还可购买的数量c 892 let canBuyNum = limited - buyedNum; // 自己还可购买的数量c
886 - 893 + limitNum = limited;
  894 + boughtNum = buyedNum;
  895 +
887 if(canBuyNum <= 0) { 896 if(canBuyNum <= 0) {
888 canBuyNum = 0; 897 canBuyNum = 0;
889 }; 898 };
@@ -925,18 +934,6 @@ Page({ @@ -925,18 +934,6 @@ Page({
925 934
926 }; 935 };
927 936
928 -  
929 -  
930 -  
931 -  
932 -  
933 -  
934 -  
935 -  
936 -  
937 -  
938 -  
939 -  
940 937
941 938
942 if(action=="buy"){ 939 if(action=="buy"){
@@ -965,9 +962,6 @@ Page({ @@ -965,9 +962,6 @@ Page({
965 // console.log('newd++++++++', newd); 962 // console.log('newd++++++++', newd);
966 th.buyNow(newd); 963 th.buyNow(newd);
967 } else { 964 } else {
968 -  
969 -  
970 -  
971 965
972 var newd = { 966 var newd = {
973 service_id: th.data.data.id, 967 service_id: th.data.data.id,
@@ -1008,10 +1002,26 @@ Page({ @@ -1008,10 +1002,26 @@ Page({
1008 1002
1009 //-------如果购物车中有相关的数据--------- 1003 //-------如果购物车中有相关的数据---------
1010 if (re.data.data.total > 0) { 1004 if (re.data.data.total > 0) {
1011 - 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 + if (th.data.prom_type == 1 && !th.data.is_normal) {
  1008 + var snum = limitNum - boughtNum;
  1009 +
  1010 + if (totalNum >= redisNums){
  1011 + if (redisNums > snum) {
  1012 + totalNum = snum;
  1013 + } else {
  1014 + totalNum = redisNums;
  1015 + }
  1016 + } else {
  1017 + if (totalNum > snum)
  1018 + totalNum = snum;
  1019 + }
  1020 + }
  1021 +
1012 var updata = { 1022 var updata = {
1013 id: item.id, 1023 id: item.id,
1014 - goods_num: th.data.goodsInputNum + item.goods_num, 1024 + goods_num: totalNum,
1015 money: th.data.data.shop_price, 1025 money: th.data.data.shop_price,
1016 store_id: os.stoid, 1026 store_id: os.stoid,
1017 }; 1027 };
@@ -1038,7 +1048,7 @@ Page({ @@ -1038,7 +1048,7 @@ Page({
1038 getApp().my_warnning('加入购物车成功', 1, th, 450); 1048 getApp().my_warnning('加入购物车成功', 1, th, 450);
1039 var c_num = th.data.cartGoodsNum + th.data.goodsInputNum; 1049 var c_num = th.data.cartGoodsNum + th.data.goodsInputNum;
1040 th.setData({ 1050 th.setData({
1041 - cartGoodsNum: c_num 1051 + cartGoodsNum: totalNum
1042 }); 1052 });
1043 th.closeSpecModal(); 1053 th.closeSpecModal();
1044 } 1054 }