Commit d6279bdae211962394c4c3ae943dae6c23a7f554

Authored by 泉州测试
1 parent a38fab6d

fix购物车大于库存 限购

Showing 1 changed file with 39 additions and 24 deletions
pages/cart/cart/cart.js
... ... @@ -2042,22 +2042,25 @@ Page({
2042 2042 if(redis_num == 0) {
2043 2043 wx.showToast({
2044 2044 title: '超出活动库存',
2045   - icon: 'none',
  2045 + icon: 'none',
2046 2046 });
2047 2047 th.setData({[txt]: redis_num});
  2048 + await e.doCheckAll();
2048 2049 return false;
2049 2050 };
2050 2051  
2051   - if(t.goods_num > redis_num) {
2052   - wx.showToast({
2053   - title: '超出活动库存',
2054   - icon: 'none',
2055   - });
2056   - th.setData({[txt]: redis_num});
2057   - return false;
2058   - };
  2052 + var buylimit = 0
  2053 + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, {
  2054 +
  2055 + }).then(res => {
  2056 + if(res.data.code == 0) {
  2057 +
  2058 + th.data.sele_g = res.data.data;
  2059 + th.data.sele_g.viplimited = res.data.data.buy_limit;
  2060 + buylimit = res.data.data.buy_limit;
  2061 + };
  2062 + });
2059 2063  
2060   - // 个人限购
2061 2064 //----获取用户活动购买数----
2062 2065 await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+t.store_id+"&user_id="+getApp().globalData.user_id+"&card_id="+t.goods_id+"&prom_type="+t.prom_type+"&prom_id="+t.prom_id, {
2063 2066 }).then(tt => {
... ... @@ -2068,33 +2071,45 @@ Page({
2068 2071 });
2069 2072 };
2070 2073 });
2071   -
2072   - var buylimit = 0
2073   - await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, {
2074   -
2075   - }).then(res => {
2076   - if(res.data.code == 0) {
2077   -
2078   - th.data.sele_g = res.data.data;
2079   - th.data.sele_g.viplimited = res.data.data.buy_limit;
2080   - buylimit = res.data.data.buy_limit;
  2074 + var gd_buy_num = th.data.promcardbuynum;
  2075 +
  2076 +
  2077 + if(t.goods_num > redis_num) {
  2078 + wx.showToast({
  2079 + title: '超出活动库存',
  2080 + icon: 'none',
  2081 + });
  2082 +
  2083 + if (buylimit > 0) {
  2084 + let num = buylimit - gd_buy_num;
  2085 + if (num > redis_num) {
  2086 + th.setData({[txt]: redis_num});
  2087 + } else {
  2088 + th.setData({[txt]: num});
  2089 + }
  2090 + } else {
  2091 + th.setData({[txt]: redis_num});
  2092 + }
  2093 +
  2094 + await e.doCheckAll();
  2095 + return false;
2081 2096 };
2082   - });
  2097 +
  2098 +
2083 2099 //--秒杀:判断商品是否超出活动限购--
2084 2100 if (buylimit > 0) {
2085   -
2086   - var gd_buy_num = th.data.promcardbuynum;
2087 2101  
2088 2102 // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量”
2089 2103 if(t.goods_num + gd_buy_num > buylimit) {
2090 2104 // 计算还可以购买的数量:库存量 - 已购数
2091 2105 wx.showToast({
2092 2106 title: '超出活动限购',
2093   - icon: 'none',
  2107 + icon: 'none',
2094 2108 });
2095 2109 let num = buylimit - gd_buy_num;
2096 2110 if (num <= 0) num = 1;
2097 2111 th.setData({[txt]: num});
  2112 + await e.doCheckAll();
2098 2113 return false;
2099 2114 };
2100 2115  
... ...