Commit cad3828782c425f421b4387eb93dd75f5f9fdfbe
1 parent
0541f89d
fix修改预热活动数量限购问题
Showing
1 changed file
with
112 additions
and
108 deletions
pages/cart/cart/cart.js
... | ... | @@ -1113,6 +1113,7 @@ Page({ |
1113 | 1113 | id: a.id, |
1114 | 1114 | goods_id: a.service_id, |
1115 | 1115 | store_id: oo.stoid, |
1116 | + is_pd_normal: a. is_pd_normal | |
1116 | 1117 | }; |
1117 | 1118 | if(a.prom_type) { |
1118 | 1119 | e.prom_type = a.prom_type; |
... | ... | @@ -1151,7 +1152,8 @@ Page({ |
1151 | 1152 | goods_num: a.goods_num - 1, |
1152 | 1153 | id: a.id, |
1153 | 1154 | goods_id: a.service_id, |
1154 | - store_id: oo.stoid | |
1155 | + store_id: oo.stoid, | |
1156 | + is_pd_normal: a. is_pd_normal | |
1155 | 1157 | }; |
1156 | 1158 | |
1157 | 1159 | this.postCardList_ser(e, t.currentTarget.dataset.item, t.currentTarget.dataset.pitems); |
... | ... | @@ -2027,124 +2029,126 @@ Page({ |
2027 | 2029 | [txt]: t.goods_num |
2028 | 2030 | }); |
2029 | 2031 | |
2030 | - | |
2031 | - | |
2032 | - if(t.prom_type == 1) { | |
2033 | - var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num"; | |
2034 | - var redis_num = 0; | |
2035 | - | |
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 | - }); | |
2032 | + // 1.秒杀活动 | |
2033 | + // 2.活动开始 | |
2034 | + if(t.prom_type == 1 && t.is_pd_normal == 0) { | |
2035 | + var txt = "service_data[" + pitem + "].goods[" + item + "].goods_num"; | |
2036 | + var redis_num = 0; | |
2037 | + | |
2038 | + // 获取其他门店,同类商品的数量 | |
2039 | + var cartGoodsNum = 0; | |
2040 | + await getApp().request.promiseGet("/api/weshop/cartService/page?store_id="+t.store_id+"&user_id="+getApp().globalData.user_id+"&service_id="+t.goods_id, | |
2041 | + { }).then(res => { | |
2042 | + if (res.data.data.pageData.length > 0) { | |
2043 | + const tmpObj = res.data.data.pageData; | |
2044 | + tmpObj.forEach(v => { | |
2045 | + if (t.id != v.id) { | |
2046 | + cartGoodsNum += parseInt(v.goods_num); | |
2048 | 2047 | } |
2048 | + | |
2049 | 2049 | }); |
2050 | - // 当前商品数量包括其他门店 | |
2051 | - var totalNum = 0 | |
2052 | - if (cartGoodsNum > 0) { | |
2053 | - totalNum = t.goods_num + cartGoodsNum; | |
2054 | - } else { | |
2055 | - totalNum = t.goods_num; | |
2056 | - } | |
2050 | + } | |
2051 | + }); | |
2052 | + // 当前商品数量包括其他门店 | |
2053 | + var totalNum = 0 | |
2054 | + if (cartGoodsNum > 0) { | |
2055 | + totalNum = t.goods_num + cartGoodsNum; | |
2056 | + } else { | |
2057 | + totalNum = t.goods_num; | |
2058 | + } | |
2057 | 2059 | |
2058 | - //获取当前商品活动库存 | |
2059 | - await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | |
2060 | - t.store_id + "/" + t.prom_type + "/" + t.prom_id, { | |
2061 | - 1: 1 | |
2062 | - }).then(res => { | |
2063 | - redis_num = res.data.data; | |
2064 | - }); | |
2065 | - | |
2066 | - // 检测库存 | |
2067 | - if(redis_num == 0) { | |
2068 | - wx.showToast({ | |
2069 | - title: '超出活动库存', | |
2070 | - icon: 'none', | |
2071 | - }); | |
2072 | - th.setData({[txt]: redis_num}); | |
2073 | - await e.doCheckAll(); | |
2074 | - return false; | |
2075 | - }; | |
2060 | + //获取当前商品活动库存 | |
2061 | + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + | |
2062 | + t.store_id + "/" + t.prom_type + "/" + t.prom_id, { | |
2063 | + 1: 1 | |
2064 | + }).then(res => { | |
2065 | + redis_num = res.data.data; | |
2066 | + }); | |
2067 | + | |
2068 | + // 检测库存 | |
2069 | + if(redis_num == 0) { | |
2070 | + wx.showToast({ | |
2071 | + title: '超出活动库存', | |
2072 | + icon: 'none', | |
2073 | + }); | |
2074 | + th.setData({[txt]: redis_num}); | |
2075 | + await e.doCheckAll(); | |
2076 | + return false; | |
2077 | + }; | |
2076 | 2078 | |
2077 | - // 限购数量 | |
2078 | - var buylimit = 0 | |
2079 | - await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, { | |
2080 | - | |
2081 | - }).then(res => { | |
2082 | - if(res.data.code == 0) { | |
2083 | - th.data.sele_g = res.data.data; | |
2084 | - th.data.sele_g.viplimited = res.data.data.buy_limit; | |
2085 | - buylimit = !res.data.data.buy_limit ? 0 : res.data.data.buy_limit; | |
2086 | - }; | |
2087 | - }); | |
2079 | + // 限购数量 | |
2080 | + var buylimit = 0 | |
2081 | + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, { | |
2082 | + | |
2083 | + }).then(res => { | |
2084 | + if(res.data.code == 0) { | |
2085 | + th.data.sele_g = res.data.data; | |
2086 | + th.data.sele_g.viplimited = res.data.data.buy_limit; | |
2087 | + buylimit = !res.data.data.buy_limit ? 0 : res.data.data.buy_limit; | |
2088 | + }; | |
2089 | + }); | |
2088 | 2090 | |
2089 | - //用户已经成功付款购买的数量 | |
2090 | - var gd_buy_num = 0; | |
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, { | |
2092 | - }).then(tt => { | |
2093 | - if (tt.data.code == 0) { | |
2094 | - gd_buy_num = !tt.data.data.promcardbuynum ? 0 : tt.data.data.promcardbuynum; | |
2095 | - th.setData({ | |
2096 | - promcardbuynum: !tt.data.data.promcardbuynum ? 0 : tt.data.data.promcardbuynum, | |
2097 | - cardbuynum: tt.data.data.cardbuynum, | |
2098 | - }); | |
2099 | - }; | |
2091 | + //用户已经成功付款购买的数量 | |
2092 | + var gd_buy_num = 0; | |
2093 | + 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, { | |
2094 | + }).then(tt => { | |
2095 | + if (tt.data.code == 0) { | |
2096 | + gd_buy_num = !tt.data.data.promcardbuynum ? 0 : tt.data.data.promcardbuynum; | |
2097 | + th.setData({ | |
2098 | + promcardbuynum: !tt.data.data.promcardbuynum ? 0 : tt.data.data.promcardbuynum, | |
2099 | + cardbuynum: tt.data.data.cardbuynum, | |
2100 | 2100 | }); |
2101 | + }; | |
2102 | + }); | |
2101 | 2103 | |
2102 | - // 剩余购买数 | |
2103 | - let num = buylimit - gd_buy_num; | |
2104 | + // 剩余购买数 | |
2105 | + let num = buylimit - gd_buy_num; | |
2104 | 2106 | |
2105 | - if(totalNum > redis_num) { | |
2106 | - wx.showToast({ | |
2107 | - title: '超出活动库存', | |
2108 | - icon: 'none', | |
2109 | - }); | |
2110 | - // 开启限购 | |
2111 | - if (buylimit > 0) { | |
2112 | - if (num > redis_num) { | |
2113 | - th.setData({[txt]: redis_num-cartGoodsNum}); | |
2114 | - } else { | |
2115 | - th.setData({[txt]: num - cartGoodsNum}); | |
2116 | - } | |
2117 | - } else { | |
2118 | - th.setData({[txt]: redis_num - cartGoodsNum}); | |
2119 | - } | |
2107 | + if(totalNum > redis_num) { | |
2108 | + wx.showToast({ | |
2109 | + title: '超出活动库存', | |
2110 | + icon: 'none', | |
2111 | + }); | |
2112 | + // 开启限购 | |
2113 | + if (buylimit > 0) { | |
2114 | + if (num > redis_num) { | |
2115 | + th.setData({[txt]: redis_num-cartGoodsNum}); | |
2116 | + } else { | |
2117 | + th.setData({[txt]: num - cartGoodsNum}); | |
2118 | + } | |
2119 | + } else { | |
2120 | + th.setData({[txt]: redis_num - cartGoodsNum}); | |
2121 | + } | |
2120 | 2122 | |
2121 | - await e.doCheckAll(); | |
2122 | - return false; | |
2123 | - }; | |
2123 | + await e.doCheckAll(); | |
2124 | + return false; | |
2125 | + }; | |
2124 | 2126 | |
2127 | + | |
2128 | + //--秒杀:判断商品是否超出活动限购-- | |
2129 | + if (buylimit > 0) { | |
2130 | + | |
2131 | + // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” | |
2132 | + if(totalNum > num) { | |
2133 | + // 计算还可以购买的数量:库存量 - 已购数 | |
2134 | + wx.showToast({ | |
2135 | + title: '超出活动限购', | |
2136 | + icon: 'none', | |
2137 | + }); | |
2138 | + if (num <= 0) num = 1; | |
2139 | + th.setData({[txt]: num - cartGoodsNum}); | |
2140 | + await e.doCheckAll(); | |
2141 | + return false; | |
2142 | + }; | |
2125 | 2143 | |
2126 | - //--秒杀:判断商品是否超出活动限购-- | |
2127 | - if (buylimit > 0) { | |
2128 | - | |
2129 | - // 如果限购数量<=活动库存数量,增加数量时会先超过限购数量,此时应提示“超出活动限购数量” | |
2130 | - if(totalNum > num) { | |
2131 | - // 计算还可以购买的数量:库存量 - 已购数 | |
2132 | - wx.showToast({ | |
2133 | - title: '超出活动限购', | |
2134 | - icon: 'none', | |
2135 | - }); | |
2136 | - if (num <= 0) num = 1; | |
2137 | - th.setData({[txt]: num - cartGoodsNum}); | |
2138 | - await e.doCheckAll(); | |
2139 | - return false; | |
2140 | - }; | |
2141 | - | |
2142 | - } | |
2143 | - | |
2144 | - | |
2145 | - } | |
2146 | - await e.doCheckAll(); | |
2147 | - await e.update_cart_ser(t, pitem, item); | |
2144 | + } | |
2145 | + | |
2146 | + | |
2147 | + } | |
2148 | + | |
2149 | + | |
2150 | + await e.doCheckAll(); | |
2151 | + await e.update_cart_ser(t, pitem, item); | |
2148 | 2152 | |
2149 | 2153 | |
2150 | 2154 | }, | ... | ... |