Commit 2e9f4bfe4cde14f2ec23c378a2b66f62f103dd62

Authored by yvan.ni
1 parent e499af95

组合购 会员限购的bug优化

packageB/pages/zuhegou/index/index.js
... ... @@ -472,34 +472,61 @@ Page({
472 472 var txt2 = "list[" + index + "].showNum";
473 473 th.data.sele_g = this.data.list[index];
474 474  
475   -
476 475 wx.showModal({
477 476 title: '温馨提示',
478   - content: '确定将该商品移出购物车?',
  477 + content: "确定取消该商品参与活动?",
479 478 success (res) {
480 479 if (res.confirm) {
481 480 console.log('用户点击确定');
  481 + if(th.data.sele_g.cart_num){
482 482  
483   - var url = '/api/weshop/cart/del/' + os.stoid + '/' + th.data.sele_g.cart_id;
484   - getApp().request.delete(url, {
485   - success:function (res) {
486   -
487   - if(res.data.code==0) {
488   - title = '移除购物车成功';
489   - th.setData({
490   - [txt1]: 1,
491   - [txt2]: false,
492   - [txt]: false,
493   - });
494   - wx.showToast({
495   - title: title,
496   - icon: 'success',
497   - });
498   -
499   - th.re_sum_price();
500   - }
  483 + var updata = {
  484 + id: th.data.sele_g.cart_id,
  485 + goods_num: th.data.sele_g.cart_num - th.data.sele_g.num,
  486 + store_id: os.stoid
501 487 }
502   - });
  488 + getApp().request.put("/api/weshop/cart/update", {
  489 + data: updata,
  490 + success:function (rs) {
  491 + if(rs.data.code==0) {
  492 + title = '取消成功';
  493 + th.setData({
  494 + [txt1]: 0,
  495 + [txt2]: false,
  496 + [txt]: false,
  497 + });
  498 + wx.showToast({
  499 + title: title,
  500 + icon: 'success',
  501 + });
  502 + th.re_sum_price();
  503 + }
  504 + }
  505 + })
  506 +
  507 + }else{
  508 + var url = '/api/weshop/cart/del/' + os.stoid + '/' + th.data.sele_g.cart_id;
  509 + getApp().request.delete(url, {
  510 + success:function (res) {
  511 +
  512 + if(res.data.code==0) {
  513 + title = '取消成功';
  514 + th.setData({
  515 + [txt1]: 0,
  516 + [txt2]: false,
  517 + [txt]: false,
  518 + });
  519 + wx.showToast({
  520 + title: title,
  521 + icon: 'success',
  522 + });
  523 +
  524 + th.re_sum_price();
  525 + }
  526 + }
  527 + });
  528 + }
  529 +
503 530 } else if (res.cancel) {
504 531 console.log('用户点击取消')
505 532 self.setData({
... ... @@ -551,6 +578,7 @@ Page({
551 578 var index = e.currentTarget.dataset.index;
552 579 var item = this.data.list[index];
553 580 let num = item.num;
  581 + th.data.s_cart_num = this.data.sele_g.cart_num - 1;
554 582  
555 583 if (num >= 2) {
556 584 var check_num = num - 1;
... ... @@ -569,7 +597,7 @@ Page({
569 597 th.data.sele_g = item;
570 598 th.data.sele_index = index;
571 599 th.data.goodsInputNum = check_num;
572   - th.data.s_cart_num = this.data.sele_g.cart_num - 1;
  600 +
573 601 th.sub_updata_cart();
574 602 return false;
575 603 }
... ... @@ -580,27 +608,54 @@ Page({
580 608  
581 609 wx.showModal({
582 610 title: '温馨提示',
583   - content: '确定将该商品移出购物车?',
  611 + content: '确定取消该商品参与活动?',
584 612 success (res) {
585 613 if (res.confirm) {
586   - var url = '/api/weshop/cart/del/' + os.stoid + '/' + item.cart_id;
587   - getApp().request.delete(url, {
588   - success:function (res) {
589   - if(res.data.code==0) {
590   - var title = '移除购物车成功';
591   - th.setData({
592   - [txt1]: 1,
593   - [txt2]: false,
594   - [txt]: false,
595   - });
596   - wx.showToast({
597   - title: title,
598   - icon: 'success',
599   - });
600   - th.re_sum_price();//重新统计数量和总金额
601   - }
  614 +
  615 + if(th.data.s_cart_num){
  616 + var updata = {
  617 + id: th.data.sele_g.cart_id,
  618 + goods_num:h.data.s_cart_num ,
  619 + store_id: os.stoid
602 620 }
603   - });
  621 + getApp().request.put("/api/weshop/cart/update", {
  622 + data: updata,
  623 + success:function (rs) {
  624 + if(rs.data.code==0) {
  625 + var title = '取消成功';
  626 + th.setData({
  627 + [txt1]: 0,
  628 + [txt2]: false,
  629 + [txt]: false,
  630 + });
  631 + wx.showToast({
  632 + title: title,
  633 + icon: 'success',
  634 + });
  635 + th.re_sum_price();
  636 + }
  637 + }
  638 + })
  639 + }else {
  640 + var url = '/api/weshop/cart/del/' + os.stoid + '/' + item.cart_id;
  641 + getApp().request.delete(url, {
  642 + success: function (res) {
  643 + if (res.data.code == 0) {
  644 + var title = '移除购物车成功';
  645 + th.setData({
  646 + [txt1]: 1,
  647 + [txt2]: false,
  648 + [txt]: false,
  649 + });
  650 + wx.showToast({
  651 + title: title,
  652 + icon: 'success',
  653 + });
  654 + th.re_sum_price();//重新统计数量和总金额
  655 + }
  656 + }
  657 + });
  658 + }
604 659  
605 660 } else if (res.cancel) {
606 661 console.log('用户点击取消')
... ... @@ -844,6 +899,10 @@ Page({
844 899 goods_sn: o.goods_sn,
845 900 };
846 901  
  902 + if(th.data.s_cart_num){
  903 + newd.goods_num=th.data.s_cart_num;
  904 + }
  905 +
847 906 //---是不是从收藏夹出来的---
848 907 if (th.data.c_guide_id) {
849 908 newd['guide_id'] = th.data.c_guide_id;
... ... @@ -951,6 +1010,12 @@ Page({
951 1010 });
952 1011 th.data.adding = 0;
953 1012 th.data.sele_store = 1;
  1013 +
  1014 + if(th.data.s_cart_num){
  1015 + var txt_temp = "list[" + index + "].cart_num";
  1016 + th.setData({[txt_temp]:th.data.s_cart_num})
  1017 + }
  1018 +
954 1019 th.re_sum_price();//重新统计数量和总金额
955 1020 }
956 1021 });
... ... @@ -1470,8 +1535,8 @@ Page({
1470 1535 store_id: os.stoid,
1471 1536 user_id: user_id,
1472 1537 goods_id: gd.goods_id,
1473   - prom_type: gd.prom_type,
1474   - prom_id: gd.prom_id
  1538 + prom_type: 7,
  1539 + prom_id: th.data.act.id
1475 1540 },
1476 1541 }).then(res2=>{
1477 1542 var g_buy_num=0;
... ... @@ -1540,6 +1605,11 @@ Page({
1540 1605 });
1541 1606 th.data.adding = 0;
1542 1607 th.data.sele_store = 1;
  1608 + if(th.data.s_cart_num){
  1609 + var txt_temp = "list[" + index + "].cart_num";
  1610 + th.setData({[txt_temp]:th.data.s_cart_num})
  1611 + }
  1612 +
1543 1613 th.re_sum_price();//重新统计数量和总金额
1544 1614 }
1545 1615 });
... ... @@ -1594,7 +1664,7 @@ Page({
1594 1664 if(check_obj.prom_buybum && check_obj.prom_buybum>0) prom_buybum=check_obj.prom_buybum;
1595 1665  
1596 1666 if(check_obj){
1597   - if(check_obj.prom_buybum && check_obj.prom_buybum>th.data.sele_g.buyqty &&
  1667 + if(check_obj.prom_buybum && check_obj.prom_buybum>=th.data.sele_g.buyqty &&
1598 1668 th.data.sele_g.buyqty>0
1599 1669 ){
1600 1670 wx.showToast({
... ... @@ -1604,7 +1674,7 @@ Page({
1604 1674 });
1605 1675 return false;
1606 1676 }
1607   - if(check_obj.gd_buynum && check_obj.gd_buynum>th.data.sele_g.viplimited &&
  1677 + if(check_obj.gd_buynum && check_obj.gd_buynum>=th.data.sele_g.viplimited &&
1608 1678 th.data.sele_g.viplimited>0
1609 1679 ){
1610 1680 wx.showToast({
... ... @@ -1616,12 +1686,12 @@ Page({
1616 1686 }
1617 1687 }
1618 1688  
1619   - item.cbuy=-1;
1620   - var cbuy=th.data.sele_g.viplimited>0?th.data.sele_g.viplimited-gd_buynum:-1;
1621   - if(cbuy>-1) item.cbuy=cbuy;
1622   - var cbuy2=th.data.sele_g.buyqty>0?th.data.sele_g.buyqty-prom_buybum:-1;
1623   - if(cbuy2>-1){
1624   - if(item.cbuy==-1 || item.cbuy>cbuy2) item.cbuy=cbuy2;
  1689 + item.cbuy='no';
  1690 + var cbuy=th.data.sele_g.viplimited>0?th.data.sele_g.viplimited-gd_buynum:'no';
  1691 + if(cbuy!='no') item.cbuy=cbuy;
  1692 + var cbuy2=th.data.sele_g.buyqty>0?th.data.sele_g.buyqty-prom_buybum:'no';
  1693 + if(cbuy2!='no'){
  1694 + if(item.cbuy=='no' || item.cbuy>cbuy2) item.cbuy=cbuy2;
1625 1695 }
1626 1696  
1627 1697 var num=item.goods_num;
... ... @@ -1637,17 +1707,12 @@ Page({
1637 1707 [txt5]: item.goods_num,
1638 1708 });
1639 1709  
1640   - if(item.cbuy>-1){
1641   - th.setData({
1642   - [txt5]: item.cbuy,
1643   - });
1644   - }
1645   -
1646 1710 var updata = {
1647 1711 id: item.id,
1648 1712 prom_type: 7,
1649 1713 goods_price: cur_price,
1650   - prom_id: th.data.act.id
  1714 + prom_id: th.data.act.id,
  1715 + store_id: os.stoid,
1651 1716 };
1652 1717 if (getApp().globalData.guide_id) {
1653 1718 updata['guide_id'] = getApp().globalData.guide_id;
... ...
pages/cart/cart/cart.js
... ... @@ -198,6 +198,7 @@ Page({
198 198 get_cart: function() {
199 199 var th = this;
200 200 var rd = Math.random().toString(36).substr(2, 15);
  201 + var user_id=getApp().globalData.userInfo.user_id;
201 202 getApp().request.get("/api/weshop/cart/list", {
202 203 data: {
203 204 user_id: app.globalData.user_id,
... ... @@ -249,6 +250,40 @@ Page({
249 250 //商品已经下架
250 251 continue;
251 252 }
  253 + var goodsbuynum=0,promgoodsbuynum=0,limit=0;
  254 +
  255 + //--要获得商品,该用户买了多少件,同步应用--
  256 + await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
  257 + data: {
  258 + store_id: oo.stoid,
  259 + user_id: user_id,
  260 + goods_id: item.goods_id,
  261 + prom_type: item.prom_type,
  262 + prom_id: item.prom_id
  263 + },
  264 + }).then(res => {
  265 + var buy_num_data = res.data.data;
  266 + if (buy_num_data.promgoodsbuynum) {
  267 + promgoodsbuynum = buy_num_data.promgoodsbuynum;
  268 + }
  269 + goodsbuynum = buy_num_data.goodsbuynum;
  270 + })
  271 + limit=good.viplimited;
  272 + //判断商品的限购
  273 + if(item.goods_num+goodsbuynum>limit && limit>0){
  274 + var cbuy=limit-goodsbuynum;
  275 + if(cbuy<=0){
  276 + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id;
  277 + a.delete(url, {});
  278 + continue;
  279 + }
  280 + //-- 购物车更新 --
  281 + var updata1={id: item.id,goods_num:cbuy };
  282 + getApp().request.put("/api/weshop/cart/update", {
  283 + data: updata1,
  284 + })
  285 + item.goods_num=cbuy;
  286 + }
252 287  
253 288 //如果秒杀活动都去掉了,或者结束了,那么这个商品也没有必要留着
254 289 if (item.prom_type == 1) {
... ... @@ -266,6 +301,22 @@ Page({
266 301 //商品已经下架
267 302 continue;
268 303 }
  304 +
  305 + //判断秒杀的限购
  306 + if(item.goods_num+promgoodsbuynum>prom.buy_limit && prom.buy_limit>0){
  307 + var cbuy=prom.buy_limit-promgoodsbuynum;
  308 + if(cbuy<=0){
  309 + var url = '/api/weshop/cart/del/' + oo.stoid + '/' + item.id;
  310 + a.delete(url, {});
  311 + continue;
  312 + }
  313 + //-- 购物车更新 --
  314 + var updata1={id: item.id,goods_num:cbuy };
  315 + getApp().request.put("/api/weshop/cart/update", {
  316 + data: updata1,
  317 + })
  318 + item.goods_num=cbuy;
  319 + }
269 320 }
270 321 //--判断优惠活动有没有过期--
271 322 else if (item.prom_type == 3) {
... ... @@ -330,6 +381,25 @@ Page({
330 381 getApp().request.delete(url, {});
331 382 continue;
332 383 }
  384 + item.zh_b_num=promgoodsbuynum;
  385 +
  386 + var url1 = "/api/weshop/prom/zhbuyGoods/page";
  387 + var req_data = {
  388 + page: 1,
  389 + pageSize: 2000,
  390 + store_id: os.stoid,
  391 + zh_id: item.prom_id,
  392 + goods_id:item.goods_id
  393 + }
  394 + await getApp().request.promiseGet(url1, {
  395 + data: req_data
  396 + }).then(res => {
  397 + if (ut.ajax_ok(res)) {
  398 + gdlist = res.data.data.pageData[0];
  399 + item.buyqty=gdlist.buyqty;
  400 + }
  401 + })
  402 +
333 403 }
334 404 else if(item.prom_type == 0) {
335 405 //如果有优惠活动,要更新活动
... ... @@ -348,6 +418,7 @@ Page({
348 418 })
349 419 }
350 420  
  421 +
351 422 all_num += item.goods_num;
352 423 item.original_img = oo.imghost + item.original_img;
353 424 item.selected = 0;
... ...
pages/cart/cart/cart.wxml
... ... @@ -88,12 +88,14 @@
88 88 <view class="abs flex-center fs26" wx:if="{{items.distr_type==2}}">物流</view>
89 89 </block>
90 90  
91   - <block wx:if="{{items.prom_type==7 && items.zhqty}}">
  91 + <block wx:if="{{items.prom_type==7}}">
92 92 <block wx:if="{{items.selected}}">
93   - <text wx:if="{{items.zhqty>items.goods_num}}" class="abs2">还需购买{{items.zhqty-items.goods_num}}件</text>
  93 + <!-- 主要显示限购 -->
  94 + <text wx:if="{{items.buyqty>0 && items.zh_b_num>0}}" class="abs2">活动剩余可购{{items.buyqty-items.zh_b_num>0?items.buyqty-items.zh_b_num:0}}件</text>
  95 + <text wx:elif="{{items.zhqty>items.goods_num}}" class="abs2">还需购买{{items.zhqty-items.goods_num}}件</text>
94 96 </block>
95 97 <block wx:else>
96   - <text class="abs2">需购买{{items.zhqty}}件</text>
  98 + <text wx:if="{{items.zhqty}}" class="abs2">需购买{{items.zhqty}}件</text>
97 99 </block>
98 100 </block>
99 101  
... ... @@ -106,7 +108,7 @@
106 108 <view class="specifications ellipsis-1">
107 109 <view wx:if="{{items.goods_color || items.goods_spec}}">
108 110 {{items.goods_color}}{{items.goods_color?"/":''}}{{items.goods_spec}}</view>
109   - <view wx:else>规格1</view>
  111 + <view wx:else>规格1{{items.buyqty}}--{{items.zh_b_num}}</view>
110 112 </view>
111 113 <block wx:if="{{items.is_gift}}">
112 114 <view>{{items.goods_num}}件</view>
... ...
pages/cart/cart/zh_calculate.js
... ... @@ -115,6 +115,7 @@ module.exports = {
115 115 var cart_num=get_num(item).goods_num;
116 116 var zh_b_num=get_num2(item).zh_b_num;
117 117  
  118 + item.cart_num =cart_num;
118 119 //-- 当商品有购买的时候,以及有限购的时候 --
119 120 if(zh_b_num>0 && item.buyqty>0){
120 121  
... ... @@ -139,13 +140,14 @@ module.exports = {
139 140 item.num =cart_num;
140 141 }
141 142  
142   -
143 143 item.goods_price=get_num(item).goods_price;
144 144 item.offline_price=get_num(item).offline_price;
145   -
  145 + if(item.cart_num){
  146 + all_price += item.cart_num * item.goods_price;
  147 + }
146 148 if (item.num) {
147 149 all_num += item.num;
148   - all_price += item.num * item.goods_price;
  150 +
149 151 //当有起购数的控制的时候
150 152 if (item.zhqty) {
151 153 all_zhqty += item.zhqty;
... ...
pages/cart/cart2/cart2.js
... ... @@ -940,8 +940,8 @@ Page({
940 940  
941 941 //计算价格
942 942 th.calculatePrice2();
943   - //获取优惠券
944   - th.get_buy_now_quan();
  943 + //获取优惠券,如果有券的钱,就调用
  944 + if(th.data.ckeck_quan_price>0) th.get_buy_now_quan();
945 945 }
946 946 });
947 947  
... ... @@ -1259,7 +1259,7 @@ Page({
1259 1259 o_price_no_zh += item[j].goods_price * item[j].goods_num;
1260 1260 }
1261 1261 //组合购的商品,且没有订单优惠的叠加,is_orderyh就是优惠叠加
1262   - if(zh_prom_goods[item[j].prom_id] && !zh_prom_goods[item[j].prom_id].act.is_orderyh )
  1262 + if(zh_prom_goods && zh_prom_goods[item[j].prom_id] && !zh_prom_goods[item[j].prom_id].act.is_orderyh )
1263 1263 {
1264 1264 o_price_no_zh += item[j].goods_price * item[j].goods_num;
1265 1265 }
... ... @@ -1273,7 +1273,7 @@ Page({
1273 1273 o_price_no_zh-=c_arr[i].cut_price;
1274 1274 }
1275 1275 //如果有组合购优惠的钱,就要减价
1276   - if (c_arr[i].zh_cut_price > 0){
  1276 + if (c_arr[i].zh_cut_price>0 || c_arr[i].zh_cut_price<0){
1277 1277 o_price -= c_arr[i].zh_cut_price;
1278 1278 if(o_price_no_zh>0){
1279 1279 //找到那些可以订单优惠叠加的
... ...
pages/cart/cart2/cart2.wxml
... ... @@ -428,7 +428,7 @@
428 428 <view class="co-red">- ¥ {{filters.toFix(formData.cut_price,2)}}元</view>
429 429 </view>
430 430 <!-- 组合购优惠金额 -->
431   - <view class="item" wx:if="{{formData.zh_cut_price>0}}">
  431 + <view class="item" wx:if="{{formData.zh_cut_price>0 || formData.zh_cut_price<0}}">
432 432 <view>组合购优惠</view>
433 433 <view class="co-red">- ¥ {{filters.toFix(formData.zh_cut_price,2)}}元</view>
434 434 </view>
... ...