Commit 3f05ca8435fece5754899dc459885576e9f77a90

Authored by yvan.ni
1 parent 104e9025

购物车单个商品再加减的时候,就算单个商品的,再结算的时候统一判断

Showing 1 changed file with 43 additions and 29 deletions
pages/cart/cart/cart.js
... ... @@ -2102,7 +2102,7 @@ Page({
2102 2102 th.click_set_limit(gd_info,pitems,i,act)
2103 2103 }
2104 2104  
2105   - if (!gd_info.whsle_id && [1, 2, 4, 6, 8, 9].indexOf(gd_info.prom_type) == -1 && !gd_info.selected) {
  2105 + if(!gd_info.whsle_id && [1, 2, 4, 6, 8, 9].indexOf(gd_info.prom_type) == -1 && !gd_info.selected && th.data.sales_rules >= 2 ) {
2106 2106 var ob = {};
2107 2107 await th.check_down_line_next(gd_info, pitems, i, gd_info.erpwareid, function (res) {
2108 2108 ob = res;
... ... @@ -2602,14 +2602,33 @@ Page({
2602 2602 //-- 循环汇总其他门店,其他活动有此商品的购买数量的汇总,不包含赠品 --
2603 2603 get_goods_other(item, pitem,only){
2604 2604 var goods_id = this.data.requestData[pitem].goods[item].goods_id;
  2605 + var prom_type = this.data.requestData[pitem].goods[item].prom_type;
  2606 + var prom_id = this.data.requestData[pitem].goods[item].prom_id;
  2607 +
2605 2608 var num=0;
  2609 + //-- 相同活动的商品汇总,秒杀,团购 --
  2610 + if(only==2){
  2611 + for (let j = 0; j < this.data.requestData.length;j++){
  2612 + if(j!=pitem){
  2613 + var goods=this.data.requestData[j].goods;
  2614 + for (let k = 0; k <goods.length ; k++) {
  2615 + var m_item=goods[k];
  2616 + if(m_item.goods_id==goods_id && m_item.is_gift==0
  2617 + && m_item.prom_id==prom_id && m_item.prom_type==prom_type ){
  2618 + num+=m_item.goods_num
  2619 + }
  2620 + }
  2621 + }
  2622 + }
  2623 + return num;
  2624 + }
  2625 +
2606 2626 for (let i = 0; i < this.data.requestData[pitem].goods.length; i++) {
2607 2627 var t_item=this.data.requestData[pitem].goods[i]
2608 2628 if(i!=item && t_item.goods_id==goods_id && t_item.is_gift==0){
2609 2629 num+=t_item.goods_num
2610 2630 }
2611 2631 }
2612   -
2613 2632 if(only) return num;
2614 2633 for (let j = 0; j < this.data.requestData.length;j++){
2615 2634 if(j!=pitem){
... ... @@ -2622,6 +2641,7 @@ Page({
2622 2641 }
2623 2642 }
2624 2643 }
  2644 +
2625 2645 return num;
2626 2646 },
2627 2647  
... ... @@ -2643,7 +2663,6 @@ Page({
2643 2663 var goodsinfo = e.data.requestData[pitem].goods[item];
2644 2664 var promgoodsbuynum = 0;
2645 2665 var goodsbuynum = 0;
2646   - var other_gd_num=th.get_goods_other(item, pitem);
2647 2666  
2648 2667 var is_showing=0;
2649 2668 //--要获得商品,该用户买了多少件,同步应用,用于限购的计算--
... ... @@ -2668,9 +2687,6 @@ Page({
2668 2687  
2669 2688 })
2670 2689  
2671   - //-- 已经购买数量要汇总其他活动,其他门店的商品数量 --
2672   - goodsbuynum+=other_gd_num;
2673   -
2674 2690 //--> by ty
2675 2691 // var buyed_mum2 = t.goods_num + goodsbuynum;
2676 2692 var buyed_mum2 = t.goods_num;
... ... @@ -2684,11 +2700,11 @@ Page({
2684 2700 if(limit<0) limit=0;
2685 2701  
2686 2702 if(buyed_mum2>limit){
2687   - wx.showToast({
2688   - title: '购买数量超出商品限购',
2689   - icon: 'none',
2690   - });
2691   - is_showing=1;
  2703 + wx.showToast({
  2704 + title: '购买数量超出商品限购',
  2705 + icon: 'none',
  2706 + });
  2707 + is_showing=1;
2692 2708 }
2693 2709  
2694 2710 // e.setData({
... ... @@ -2736,7 +2752,7 @@ Page({
2736 2752 if (res_d.data.code == 0 && res_d.data.data) {
2737 2753  
2738 2754 var cbuy=limit;
2739   - if (t.goods_num+other_gd_num > store_count && !is_showing) {
  2755 + if (t.goods_num> store_count && !is_showing) {
2740 2756 wx.showToast({
2741 2757 title: '购买数量超出商品库存',
2742 2758 icon: 'none',
... ... @@ -2744,19 +2760,21 @@ Page({
2744 2760 is_showing=1;
2745 2761 }
2746 2762 //一直都要给一个最小值,和库存比较
2747   - if(cbuy>store_count-other_gd_num) cbuy=store_count-other_gd_num;
  2763 + if(cbuy>store_count) cbuy=store_count;
2748 2764  
2749 2765 var false_data = res_d.data.data;
2750 2766 //--判断库存--
2751   - if (t.goods_num > false_data.goods_num - false_data.buy_num && !is_showing) {
  2767 + if (t.goods_num > false_data.goods_num - false_data.buy_num && !is_showing) {
2752 2768 wx.showToast({
2753 2769 title: '购买数量超出活动库存',
2754 2770 icon: 'none',
2755 2771 });
2756 2772 is_showing=1;
2757 2773 }
  2774 +
2758 2775 //一直都要给一个最小值,和活动库存比较
2759   - if(cbuy>false_data.goods_num - false_data.buy_num) cbuy=false_data.goods_num - false_data.buy_num;
  2776 + if(cbuy>false_data.goods_num - false_data.buy_num)
  2777 + cbuy=false_data.goods_num - false_data.buy_num;
2760 2778  
2761 2779 //--判断redis数量是否已经超出--
2762 2780 if (t.goods_num > false_data.redisnum && !is_showing) {
... ... @@ -2778,10 +2796,8 @@ Page({
2778 2796 icon: 'none',
2779 2797 });
2780 2798 }
2781   -
2782 2799 var act_limit=false_data.buy_limit-promgoodsbuynum;
2783 2800 if(!act_limit) act_limit=0;
2784   -
2785 2801 if(cbuy>act_limit) cbuy=act_limit;
2786 2802  
2787 2803 }
... ... @@ -2791,7 +2807,7 @@ Page({
2791 2807 e.update_cart(t, pitem, item);
2792 2808  
2793 2809 } else {
2794   - e.normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds); //普通商品的调用和计算
  2810 + e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算
2795 2811 }
2796 2812 break;
2797 2813 case 2:
... ... @@ -2801,7 +2817,7 @@ Page({
2801 2817 if (res.data.code == 0 && res.data.data) {
2802 2818  
2803 2819 var cbuy=limit;
2804   - if (t.goods_num > store_count-other_gd_num && !is_showing) {
  2820 + if (t.goods_num > store_count && !is_showing) {
2805 2821 wx.showToast({
2806 2822 title: '购买数量超出商品库存',
2807 2823 icon: 'none',
... ... @@ -2809,7 +2825,7 @@ Page({
2809 2825 is_showing=1;
2810 2826 }
2811 2827 //一直都要给一个最小值,和库存比较
2812   - if(cbuy>store_count) cbuy=store_count-other_gd_num;
  2828 + if(cbuy>store_count) cbuy=store_count;
2813 2829  
2814 2830 var gr_data = res.data.data;
2815 2831 //--判断库存--
... ... @@ -2821,7 +2837,7 @@ Page({
2821 2837 is_showing=1;
2822 2838 }
2823 2839 //一直都要给一个最小值,和库存比较
2824   - if(cbuy>gr_data.goods_num - gr_data.buy_num ) cbuy=gr_data.goods_num - gr_data.buy_num ;
  2840 + if(cbuy>gr_data.goods_num - gr_data.buy_num ) cbuy=gr_data.goods_num - gr_data.buy_num;
2825 2841  
2826 2842 //--判断redis数量是否已经超出--
2827 2843 if (t.goods_num > gr_data.redisnum && !is_showing) {
... ... @@ -2831,7 +2847,7 @@ Page({
2831 2847 });
2832 2848 is_showing=1;
2833 2849 }
2834   - if(cbuy>gr_data.redisnum ) cbuy=gr_data.redisnum;
  2850 + if(cbuy>gr_data.redisnum) cbuy=gr_data.redisnum;
2835 2851  
2836 2852 //--活动的限购是不是要判断--
2837 2853 if (gr_data.buy_limit > 0) {
... ... @@ -2847,7 +2863,6 @@ Page({
2847 2863 if(!act_limit) act_limit=0;
2848 2864  
2849 2865 if(cbuy>act_limit) cbuy=act_limit;
2850   -
2851 2866 }
2852 2867  
2853 2868 if(t.goods_num>cbuy) t.goods_num=cbuy;
... ... @@ -2855,11 +2870,11 @@ Page({
2855 2870 e.update_cart(t, pitem, item);
2856 2871  
2857 2872 } else {
2858   - e.normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds); //普通商品的调用和计算
  2873 + e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算
2859 2874 }
2860 2875 break;
2861 2876 default:
2862   - e.normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds); //普通商品的调用和计算
  2877 + e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算
2863 2878 break
2864 2879 }
2865 2880 }
... ... @@ -2867,7 +2882,7 @@ Page({
2867 2882 },
2868 2883  
2869 2884 //-- 这个函数在计算的时候,要包含限购的那一部分 --
2870   - async normal_check(t, item, pitem,store_count,limit,other_gd_num,goodsinfo, wareIds){
  2885 + async normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds){
2871 2886  
2872 2887 var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id);
2873 2888  
... ... @@ -2899,7 +2914,7 @@ Page({
2899 2914 is_showing=1;
2900 2915 }
2901 2916  
2902   - if (t.goods_num > cQty-other_gd_num) {
  2917 + if (t.goods_num > cQty) {
2903 2918 if(!is_showing){
2904 2919 wx.showToast({
2905 2920 title: '购买数量超出商品库存',
... ... @@ -2908,7 +2923,7 @@ Page({
2908 2923 is_showing=1;
2909 2924 }
2910 2925 }
2911   - if(cbuy>cQty-other_gd_num) cbuy=cQty-other_gd_num;
  2926 + if(cbuy>cQty) cbuy=cQty;
2912 2927  
2913 2928 if(t.goods_num>cbuy) t.goods_num=cbuy;
2914 2929  
... ... @@ -3506,7 +3521,6 @@ Page({
3506 3521 }
3507 3522  
3508 3523  
3509   -
3510 3524 //--普通商品,如果有开启线下库存的功能,要调用线下库存进行计算,赠品不要进行调用线下库存---
3511 3525 if ((i_arr[j].prom_type == 0 || i_arr[j].prom_type == 3 || i_arr[j].prom_type == 5 || i_arr[j].prom_type == 7 || i_arr[j].prom_type == 10 ||
3512 3526 i_arr[j].need_downlow_num) && th.data.sales_rules >= 2 && i_arr[j].is_gift != 1 && !i_arr[j].whsle_id) {
... ...