Commit acc24ed95f2f90b1013de03cd97e1ad066841355

Authored by 泉州测试
1 parent 4a706205

fix再来一次单增加限购判断

packageA/pages/details_serviceCard/details_serviceCard.js
... ... @@ -228,7 +228,7 @@ Page({
228 228  
229 229  
230 230 // 再来一单
231   - buy2(t) {
  231 + buy2: async function(t) {
232 232 let details = this.data.details;
233 233 var th = this;
234 234 var ind = 1; // 1:加入购物车
... ... @@ -288,17 +288,57 @@ Page({
288 288 if(details.list[0].prom_type == 1) {
289 289 newd['prom_type'] = details.list[0].prom_type;
290 290 newd['prom_id'] = details.list[0].prom_id;
291   - // if(th.data.openSpecModal_flash_normal) {
292   - // newd['money'] = th.data.data.shop_price;
293   - // newd['is_pd_normal'] = 1;
294   - // } else {
295   - // newd['money'] = th.data.prom_price;
296   - // };
297 291 };
298   -
  292 +
  293 + var prom_id = details.list[0].prom_id > 0 ? details.list[0].prom_id : 0;
  294 + var card_id = details.list[0].card_id;
  295 + var prom_type = details.list[0].prom_type > 0 ? details.list[0].prom_type : 0;
  296 + var is_pd_normal = details.list[0].is_pd_normal;
  297 + // 库存
  298 + var redisNums = 0;
  299 + // 限购数
  300 + var limitNum = 0;
  301 + // 已购买数量
  302 + var boughtNum = 0;
  303 +
  304 + // 秒杀活动中购买
  305 + if (prom_type == 1 && !is_pd_normal) {
  306 +
  307 + // 获取已购数量
  308 + await getApp().request.promiseGet("/api/weshop/rechargeServicelist/getUserBuyGoodsNum?store_id="+os.stoid+"&user_id="+getApp().globalData.user_id+"&card_id="+card_id+"&prom_type="+prom_type+"&prom_id="+prom_id, {
  309 + }).then(res => {
  310 + boughtNum = !res.data.data.promcardbuynum ? 0 : res.data.data.promcardbuynum;
  311 + });
  312 +
  313 + // 获取库存
  314 + await getApp().request.promiseGet("/api/weshop/activitylist/getActLen/" + os.stoid + "/1/" + prom_id, {}).then(res => {
  315 + if (res.data.code == 0) {
  316 + redisNums = !res.data.data ? 0 : res.data.data;
  317 + };
  318 + });
  319 +
  320 + // 获取限购数
  321 + var user_id = getApp().globalData.user_id;
  322 + await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + os.stoid + "/" + user_id + "/" + prom_id, {}).then(res => {
  323 + if (res.data.code == 0) {
  324 + limitNum = res.data.data.buy_limit;
  325 + }
  326 + });
  327 +
  328 + var snum = limitNum - boughtNum;
  329 + var snum = limitNum - boughtNum;
  330 + if (snum <= 0) {
  331 + wx.showModal({
  332 + title: '超出限购数量',
  333 + });
  334 + return false;
  335 + }
  336 +
  337 + }
  338 +
299 339  
300 340 //----先看会员在购物车中是否加入了该商品-----
301   - app.request.get("/api/weshop/cartService/page", {
  341 + app.request.get("/api/weshop/cartService/page", {
302 342 data: {
303 343 store_id: app.globalData.setting.stoid,
304 344 user_id: this.data.userInfo.user_id,
... ... @@ -306,13 +346,30 @@ Page({
306 346 pick_id: details.list[0].pickup_id,
307 347 },
308 348 success: function(re) {
309   -
310 349 //-------如果购物车中有相关的数据---------
311 350 if (re.data.data.total > 0) {
312 351 var item = re.data.data.pageData[0];
  352 + var totalNum = details.list[0].qty + item.goods_num;
  353 +
  354 + if (prom_type == 1 && !is_pd_normal) {
  355 + // 秒杀购物车购买 修正数量
  356 + var snum = limitNum - boughtNum;
  357 +
  358 + if (totalNum >= redisNums){
  359 + if (redisNums > snum) {
  360 + totalNum = snum;
  361 + } else {
  362 + totalNum = redisNums;
  363 + }
  364 + } else {
  365 + if (totalNum > snum)
  366 + totalNum = snum;
  367 + }
  368 + }
  369 +
313 370 var updata = {
314 371 id: item.id,
315   - goods_num: details.list[0].qty + item.goods_num,
  372 + goods_num: totalNum,
316 373 money: details.list[0].price,
317 374 store_id: app.globalData.setting.stoid,
318 375 };
... ... @@ -321,6 +378,7 @@ Page({
321 378 updata['guide_id'] = getApp().globalData.guide_id;
322 379 updata['guide_type'] = 1;
323 380 }
  381 +
324 382 getApp().request.put("/api/weshop/cartService/update", {
325 383 data: updata,
326 384 success: function(t) {
... ... @@ -333,6 +391,8 @@ Page({
333 391 // th.closeSpecModal();
334 392 }
335 393 });
  394 +
  395 +
336 396 } else {
337 397  
338 398 getApp().request.post("/api/weshop/cartService/save", {
... ...
packageA/pages/goodsInfo/goodsInfo.js
... ... @@ -1004,9 +1004,16 @@ Page({
1004 1004 if (re.data.data.total > 0) {
1005 1005 var item = re.data.data.pageData[0];
1006 1006 var totalNum = th.data.goodsInputNum + item.goods_num;
  1007 +
  1008 + // 秒杀购物车购买 修正数量
1007 1009 if (th.data.prom_type == 1 && !th.data.is_normal) {
1008 1010 var snum = limitNum - boughtNum;
1009   -
  1011 + if (snum <= 0) {
  1012 + wx.showModal({
  1013 + title: '超出限购数量',
  1014 + });
  1015 + return false;
  1016 + }
1010 1017 if (totalNum >= redisNums){
1011 1018 if (redisNums > snum) {
1012 1019 totalNum = snum;
... ...
pages/cart/cart/cart.js
... ... @@ -2073,7 +2073,9 @@ Page({
2073 2073 icon: 'none',
2074 2074 });
2075 2075 th.setData({[txt]: redis_num});
2076   - await e.doCheckAll();
  2076 + t.goods_num = redis_num;
  2077 + await th.doCheckAll();
  2078 + await th.update_cart_ser(t, pitem, item);
2077 2079 return false;
2078 2080 };
2079 2081  
... ... @@ -2114,14 +2116,22 @@ Page({
2114 2116 if (buylimit > 0) {
2115 2117 if (num > redis_num) {
2116 2118 th.setData({[txt]: redis_num-cartGoodsNum});
  2119 + t.goods_num = redis_num-cartGoodsNum;
  2120 + await th.doCheckAll();
  2121 + await th.update_cart_ser(t, pitem, item);
2117 2122 } else {
2118 2123 th.setData({[txt]: num - cartGoodsNum});
  2124 + t.goods_num = num - cartGoodsNum;
  2125 + await th.doCheckAll();
  2126 + await th.update_cart_ser(t, pitem, item);
2119 2127 }
2120 2128 } else {
2121 2129 th.setData({[txt]: redis_num - cartGoodsNum});
  2130 + t.goods_num = redis_num - cartGoodsNum;
  2131 + await th.doCheckAll();
  2132 + await th.update_cart_ser(t, pitem, item);
2122 2133 }
2123 2134  
2124   - await e.doCheckAll();
2125 2135 return false;
2126 2136 };
2127 2137  
... ... @@ -2138,7 +2148,9 @@ Page({
2138 2148 });
2139 2149 if (num <= 0) num = 1;
2140 2150 th.setData({[txt]: num - cartGoodsNum});
2141   - await e.doCheckAll();
  2151 + t.goods_num = num - cartGoodsNum;
  2152 + await th.doCheckAll();
  2153 + await th.update_cart_ser(t, pitem, item);
2142 2154 return false;
2143 2155 };
2144 2156  
... ...