Commit 937fb8b4ea30c07e73f03d32e305b76616881d53

Authored by 泉州测试
1 parent 1ca5e1b6

fix购物车服务卡限购和库存

Showing 1 changed file with 38 additions and 15 deletions
pages/cart/cart/cart.js
... ... @@ -1150,9 +1150,10 @@ Page({
1150 1150 var e = {
1151 1151 goods_num: a.goods_num - 1,
1152 1152 id: a.id,
1153   - goods_id: a.goods_id,
  1153 + goods_id: a.service_id,
1154 1154 store_id: oo.stoid
1155 1155 };
  1156 +
1156 1157 this.postCardList_ser(e, t.currentTarget.dataset.item, t.currentTarget.dataset.pitems);
1157 1158 }
1158 1159 },
... ... @@ -2025,13 +2026,36 @@ Page({
2025 2026 e.setData({
2026 2027 [txt]: t.goods_num
2027 2028 });
2028   -
2029   -
  2029 +
  2030 +
  2031 +
2030 2032 if(t.prom_type == 1) {
2031 2033 var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num";
2032 2034 var redis_num = 0;
2033 2035  
2034   - //------判断活动是否抢光-----
  2036 + // 获取其他门店,同类商品的数量
  2037 + var cartGoodsNum = 0;
  2038 + await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+t.store_id+"&user_id="+getApp().globalData.user_id+"&service_id="+t.goods_id,
  2039 + { }).then(res => {
  2040 + if (res.data.data.pageData.length > 0) {
  2041 + const tmpObj = res.data.data.pageData;
  2042 + tmpObj.forEach(v => {
  2043 + if (t.id != v.id) {
  2044 + cartGoodsNum += parseInt(v.goods_num);
  2045 + }
  2046 +
  2047 + });
  2048 + }
  2049 + });
  2050 + // 当前商品数量包括其他门店
  2051 + var totalNum = 0
  2052 + if (cartGoodsNum > 0) {
  2053 + totalNum = t.goods_num + cartGoodsNum;
  2054 + } else {
  2055 + totalNum = t.goods_num;
  2056 + }
  2057 +
  2058 + //获取当前商品活动库存
2035 2059 await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" +
2036 2060 t.store_id + "/" + t.prom_type + "/" + t.prom_id, {
2037 2061 1: 1
... ... @@ -2050,19 +2074,19 @@ Page({
2050 2074 return false;
2051 2075 };
2052 2076  
  2077 + // 限购数量
2053 2078 var buylimit = 0
2054 2079 await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, {
2055 2080  
2056 2081 }).then(res => {
2057 2082 if(res.data.code == 0) {
2058   -
2059 2083 th.data.sele_g = res.data.data;
2060 2084 th.data.sele_g.viplimited = res.data.data.buy_limit;
2061 2085 buylimit = !res.data.data.buy_limit ? 0 : res.data.data.buy_limit;
2062 2086 };
2063 2087 });
2064 2088  
2065   - //----获取用户活动购买数----
  2089 + //用户已经成功付款购买的数量
2066 2090 var gd_buy_num = 0;
2067 2091 await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+t.store_id+"&user_id="+getApp().globalData.user_id+"&card_id="+t.card_id+"&prom_type="+t.prom_type+"&prom_id="+t.prom_id, {
2068 2092 }).then(tt => {
... ... @@ -2075,22 +2099,23 @@ Page({
2075 2099 };
2076 2100 });
2077 2101  
  2102 + // 剩余购买数
  2103 + let num = buylimit - gd_buy_num;
2078 2104  
2079   - if(t.goods_num > redis_num) {
  2105 + if(totalNum > redis_num) {
2080 2106 wx.showToast({
2081 2107 title: '超出活动库存',
2082 2108 icon: 'none',
2083 2109 });
2084 2110 // 开启限购
2085 2111 if (buylimit > 0) {
2086   - let num = buylimit - gd_buy_num;
2087 2112 if (num > redis_num) {
2088   - th.setData({[txt]: redis_num});
  2113 + th.setData({[txt]: redis_num-cartGoodsNum});
2089 2114 } else {
2090   - th.setData({[txt]: num});
  2115 + th.setData({[txt]: num - cartGoodsNum});
2091 2116 }
2092 2117 } else {
2093   - th.setData({[txt]: redis_num});
  2118 + th.setData({[txt]: redis_num - cartGoodsNum});
2094 2119 }
2095 2120  
2096 2121 await e.doCheckAll();
... ... @@ -2102,15 +2127,14 @@ Page({
2102 2127 if (buylimit > 0) {
2103 2128  
2104 2129 // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量”
2105   - if(t.goods_num + gd_buy_num > buylimit) {
  2130 + if(totalNum > num) {
2106 2131 // 计算还可以购买的数量:库存量 - 已购数
2107 2132 wx.showToast({
2108 2133 title: '超出活动限购',
2109 2134 icon: 'none',
2110 2135 });
2111   - let num = buylimit - gd_buy_num;
2112 2136 if (num <= 0) num = 1;
2113   - th.setData({[txt]: num});
  2137 + th.setData({[txt]: num - cartGoodsNum});
2114 2138 await e.doCheckAll();
2115 2139 return false;
2116 2140 };
... ... @@ -2334,7 +2358,6 @@ Page({
2334 2358 update_cart_ser: function (t, pitem, item) {
2335 2359 var e = this;
2336 2360  
2337   - console.log('t===>', t);
2338 2361 getApp().request.put("/api/weshop/cartService/update", {
2339 2362 data: t,
2340 2363 success: async function (ee) {
... ...