Commit 7be6eb40b5c4cf0fefaa640d1b6ac5f7b9ee3bdd

Authored by yvan.ni
1 parent fb660a87

限购的问题的优化

packageC/pages/luckyGo/luckyGo_goodsInfo/luckyGo_goodsInfo.js
@@ -2195,6 +2195,9 @@ Page({ @@ -2195,6 +2195,9 @@ Page({
2195 2195
2196 this.get_buy_num(this.data.sele_g, async function () { 2196 this.get_buy_num(this.data.sele_g, async function () {
2197 2197
  2198 +
  2199 + var is_show_bs=0;
  2200 + var l_num=-1;
2198 //--判断商品是否超出限购-- 2201 //--判断商品是否超出限购--
2199 if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { 2202 if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) {
2200 2203
@@ -2205,10 +2208,11 @@ Page({ @@ -2205,10 +2208,11 @@ Page({
2205 // title: '超出商品限购', 2208 // title: '超出商品限购',
2206 // }); 2209 // });
2207 getApp().my_warnning('超出商品限购', 0, th); 2210 getApp().my_warnning('超出商品限购', 0, th);
2208 - var num = th.data.sele_g.viplimited - gd_buy_num;  
2209 - if (num < 0) num = 0;  
2210 - th.setData({ goodsInputNum: num })  
2211 - return false; 2211 + l_num = th.data.sele_g.viplimited - gd_buy_num;
  2212 + if (l_num < 0) l_num = 0;
  2213 + //th.setData({ goodsInputNum: num })
  2214 + //return false;
  2215 + is_show_bs=1;
2212 } 2216 }
2213 } 2217 }
2214 2218
@@ -2263,22 +2267,41 @@ Page({ @@ -2263,22 +2267,41 @@ Page({
2263 } 2267 }
2264 } 2268 }
2265 2269
  2270 + //-- 限购数量也要进行计算一下 --
  2271 + if(l_num>-1){
  2272 + if(e>l_num) e=l_num;
  2273 + }
  2274 +
  2275 + //提示了一个,就不要提示第二个
  2276 + var is_show_bs=0;
2266 //--- 促销活动也不控制起订量, 这里很重要的一个控制,起订量的 ---- 2277 //--- 促销活动也不控制起订量, 这里很重要的一个控制,起订量的 ----
2267 if(th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1){ 2278 if(th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1){
2268 - if(t<mo_num) t=mo_num; 2279 + if(t<mo_num){
  2280 + t=mo_num;
  2281 + if(!is_show_bs){
  2282 + wx.showToast({
  2283 + title: '购买数未达到起订量',
  2284 + icon: 'none',
  2285 + });
  2286 + }
  2287 + is_show_bs=1;
  2288 + }
2269 if(t>mo_num && (t-mo_num)%steep!=0){ 2289 if(t>mo_num && (t-mo_num)%steep!=0){
2270 - wx.showToast({  
2271 - title: '购买数必须是起订量的倍数',  
2272 - icon: 'none',  
2273 - }); 2290 + if(!is_show_bs) {
  2291 + wx.showToast({
  2292 + title: '购买数必须是起订量的倍数',
  2293 + icon: 'none',
  2294 + });
  2295 + }
2274 t=mo_num+ parseInt((t-mo_num)/steep)*steep+steep; 2296 t=mo_num+ parseInt((t-mo_num)/steep)*steep+steep;
  2297 + is_show_bs=1;
2275 } 2298 }
2276 } 2299 }
2277 2300
2278 if (!e) e = 0; 2301 if (!e) e = 0;
2279 //库存不足,不增加 2302 //库存不足,不增加
2280 if (e < t) { 2303 if (e < t) {
2281 - wx.showModal({ title: '库存不足', }); 2304 + if(!is_show_bs) wx.showModal({ title: '库存不足', });
2282 if (e < 0) e = 0; 2305 if (e < 0) e = 0;
2283 2306
2284 if(th.data.is_normal == 1){ 2307 if(th.data.is_normal == 1){
pages/cart/cart/cart.js
@@ -1559,9 +1559,9 @@ Page({ @@ -1559,9 +1559,9 @@ Page({
1559 valueToNum: function (t) { 1559 valueToNum: function (t) {
1560 if (!this.data.is_load) return false; 1560 if (!this.data.is_load) return false;
1561 //控制住,避免事件响应冲突,只有input有输入的时候,才刷新 1561 //控制住,避免事件响应冲突,只有input有输入的时候,才刷新
1562 - if (this.data.btn_click) {  
1563 - return false;  
1564 - } 1562 + // if (this.data.btn_click) {
  1563 + // return false;
  1564 + // }
1565 this.data.btn_click = 1; 1565 this.data.btn_click = 1;
1566 1566
1567 var a = t.currentTarget.dataset.item; 1567 var a = t.currentTarget.dataset.item;
@@ -2601,55 +2601,7 @@ Page({ @@ -2601,55 +2601,7 @@ Page({
2601 2601
2602 //----------------------更新购物数量,加减,调用接口--------------------- 2602 //----------------------更新购物数量,加减,调用接口---------------------
2603 postCardList: function (t, item, pitem) { 2603 postCardList: function (t, item, pitem) {
2604 - var e = this,  
2605 - th = e,  
2606 - user_id = getApp().globalData.user_id;  
2607 -  
2608 - function normal_check(store_count, goodsinfo, wareIds,cx_arr) {  
2609 -  
2610 -  
2611 - // getApp().my_warnning('购买数量超出商品库存', 0, th);  
2612 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2613 - //-- 要判断是不是起订量不购 --  
2614 - if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){  
2615 - var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length);  
2616 - var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1);  
2617 - if(mo_num>1 && t.goods_num<mo_num){  
2618 - wx.showToast({  
2619 - title: '购买数量小于商品的起订量',  
2620 - icon: 'none',  
2621 - });  
2622 - t.goods_num =mo_num;  
2623 - }  
2624 - if(steep>1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0 ){  
2625 -  
2626 - wx.showToast({  
2627 - title: '购买数量必须是起订量的倍数',  
2628 - icon: 'none',  
2629 - });  
2630 - t.goods_num =mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep+steep;  
2631 - }  
2632 - }  
2633 -  
2634 -  
2635 - //--- 看一下是不是线下库存 ---  
2636 - if (th.data.sales_rules >= 2 && !goodsinfo.whsle_id) {  
2637 - th.check_down_line(t, pitem, item, wareIds);  
2638 - } else {  
2639 - if (t.goods_num > store_count) {  
2640 - wx.showToast({  
2641 - title: '购买数量超出商品库存',  
2642 - icon: 'none',  
2643 - });  
2644 - e.setData({  
2645 - [txt]: store_count  
2646 - });  
2647 - e.doCheckAll();  
2648 - t.goods_num = store_count;  
2649 - }  
2650 - e.update_cart(t, pitem, item);  
2651 - }  
2652 - } 2604 + var e = this,th = e,user_id = getApp().globalData.user_id;
2653 2605
2654 // console.log('update'); 2606 // console.log('update');
2655 // console.log('9995959595959',t); 2607 // console.log('9995959595959',t);
@@ -2666,7 +2618,9 @@ Page({ @@ -2666,7 +2618,9 @@ Page({
2666 var promgoodsbuynum = 0; 2618 var promgoodsbuynum = 0;
2667 var goodsbuynum = 0; 2619 var goodsbuynum = 0;
2668 2620
2669 - //--要获得商品,该用户买了多少件,同步应用-- 2621 + var is_showing=0;
  2622 +
  2623 + //--要获得商品,该用户买了多少件,同步应用,用于限购的计算--
2670 await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", { 2624 await getApp().request.promiseGet("/api/weshop/ordergoods/getUserBuyGoodsNum", {
2671 data: { 2625 data: {
2672 store_id: oo.stoid, 2626 store_id: oo.stoid,
@@ -2686,279 +2640,280 @@ Page({ @@ -2686,279 +2640,280 @@ Page({
2686 } 2640 }
2687 goodsbuynum = buy_num_data.goodsbuynum; 2641 goodsbuynum = buy_num_data.goodsbuynum;
2688 2642
2689 -  
2690 }) 2643 })
2691 2644
2692 //--> by ty 2645 //--> by ty
2693 // var buyed_mum2 = t.goods_num + goodsbuynum; 2646 // var buyed_mum2 = t.goods_num + goodsbuynum;
2694 var buyed_mum2 = t.goods_num; 2647 var buyed_mum2 = t.goods_num;
2695 //<-- 2648 //<--
  2649 + // 判断当前预购买的数量是否超过可购买的数量,限购还要考虑到商品的库存
  2650 + if (limit > 0) {
2696 2651
2697 - // 判断当前预购买的数量是否超过可购买的数量  
2698 - if (buyed_mum2 > (limit - goodsbuynum) && limit > 0) {  
2699 - wx.showToast({  
2700 - title: '购买数量超出商品限购',  
2701 - icon: 'none',  
2702 - });  
2703 //getApp().my_warnning('购买数量超出商品限购', 0, th); 2652 //getApp().my_warnning('购买数量超出商品限购', 0, th);
2704 var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num"; 2653 var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";
2705 2654
2706 - //--> by ty  
2707 - var cbuy = limit - goodsbuynum;  
2708 - // var cbuy = limit - buyed_mum2 + 1;  
2709 - //<--  
2710 -  
2711 - e.setData({  
2712 - // [txt]: cbuy > 0 ? cbuy : 0,  
2713 - [txt]: cbuy > 0 ? cbuy : limit,  
2714 - });  
2715 - e.doCheckAll();  
2716 -  
2717 - t.goods_num = cbuy > 0 ? cbuy : limit;  
2718 -  
2719 - if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){  
2720 -  
2721 - //-- 判断商品是不是 --  
2722 - var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id);  
2723 -  
2724 - var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length);  
2725 - var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1);  
2726 -  
2727 - if(mo_num>1 && t.goods_num<mo_num){  
2728 - wx.showToast({  
2729 - title: '购买数量小于商品的起订量',  
2730 - icon: 'none',  
2731 - });  
2732 - t.goods_num=0;  
2733 - }  
2734 -  
2735 - if(steep>1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0 ){  
2736 -  
2737 - wx.showToast({  
2738 - title: '购买数量必须是起订量的倍数',  
2739 - icon: 'none',  
2740 - }); 2655 + limit = limit - goodsbuynum;
  2656 + if(limit<0) limit=0;
2741 2657
2742 - t.goods_num=mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep  
2743 - } 2658 + if(buyed_mum2>limit){
  2659 + wx.showToast({
  2660 + title: '购买数量超出商品限购',
  2661 + icon: 'none',
  2662 + });
  2663 + is_showing=1;
2744 } 2664 }
2745 - // t.goods_num = cbuy > 0 ? cbuy : 0,  
2746 - e.update_cart(t, pitem, item);  
2747 - return false;  
2748 - }  
2749 2665
  2666 + // e.setData({
  2667 + // // [txt]: cbuy > 0 ? cbuy : 0,
  2668 + // [txt]: cbuy > 0 ? cbuy : limit,
  2669 + // });
  2670 + //e.doCheckAll();
  2671 + // t.goods_num = cbuy > 0 ? cbuy : limit;
  2672 + //
  2673 + // if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){
  2674 + //
  2675 + // //-- 判断商品是不是 --
  2676 + // var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id);
  2677 + // var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length);
  2678 + // var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1);
  2679 + //
  2680 + // if(mo_num>1 && t.goods_num<mo_num){
  2681 + // wx.showToast({
  2682 + // title: '购买数量小于商品的起订量',
  2683 + // icon: 'none',
  2684 + // });
  2685 + // t.goods_num=0;
  2686 + // }
  2687 + //
  2688 + // if(steep>1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0 ){
  2689 + //
  2690 + // wx.showToast({
  2691 + // title: '购买数量必须是起订量的倍数',
  2692 + // icon: 'none',
  2693 + // });
  2694 + //
  2695 + // t.goods_num=mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep
  2696 + // }
  2697 + // }
  2698 + // // t.goods_num = cbuy > 0 ? cbuy : 0,
  2699 + // e.update_cart(t, pitem, item);
  2700 + // return false;
  2701 + }
  2702 + else limit=100000;
2750 2703
2751 switch (goodsinfo.prom_type) { 2704 switch (goodsinfo.prom_type) {
2752 case 1: 2705 case 1:
2753 - //-- 读取秒杀 --  
2754 - rq.get("/api/ms/flash_sale/getFlashSaleOne/" + oo.stoid + "/" + goodsinfo.prom_id, {  
2755 - isShowLoading: 0,  
2756 - success: function (res_d) {  
2757 - if (res_d.data.code == 0 && res_d.data.data) {  
2758 - if (t.goods_num > store_count) {  
2759 - // wx.showModal({  
2760 - // title: '提示',  
2761 - // content: '购买数量超出商品库存'  
2762 - // }); 2706 + //-- 读取秒杀 --
  2707 + var res_d= await getApp().promiseGet("/api/ms/flash_sale/getFlashSaleOne/" + oo.stoid + "/" + goodsinfo.prom_id, {});
  2708 + if (res_d.data.code == 0 && res_d.data.data) {
  2709 +
  2710 + var cbuy=limit;
  2711 + if (t.goods_num > store_count && !is_showing) {
2763 wx.showToast({ 2712 wx.showToast({
2764 title: '购买数量超出商品库存', 2713 title: '购买数量超出商品库存',
2765 icon: 'none', 2714 icon: 'none',
2766 }); 2715 });
2767 - // getApp().my_warnning('购买数量超出商品库存', 0, th);  
2768 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2769 - e.setData({  
2770 - [txt]: store_count  
2771 - });  
2772 - e.doCheckAll();  
2773 -  
2774 - t.goods_num = store_count;  
2775 - e.update_cart(t, pitem, item);  
2776 -  
2777 - return false; 2716 + is_showing=1;
2778 } 2717 }
  2718 + //一直都要给一个最小值,和库存比较
  2719 + if(cbuy>store_count) cbuy=store_count;
2779 2720
2780 var false_data = res_d.data.data; 2721 var false_data = res_d.data.data;
2781 //--判断库存-- 2722 //--判断库存--
2782 - if (t.goods_num > false_data.goods_num - false_data.buy_num) {  
2783 - // wx.showModal({  
2784 - // title: '提示',  
2785 - // content: '购买数量超出活动库存'  
2786 - // }); 2723 + if (t.goods_num > false_data.goods_num - false_data.buy_num && !is_showing) {
2787 wx.showToast({ 2724 wx.showToast({
2788 title: '购买数量超出活动库存', 2725 title: '购买数量超出活动库存',
2789 icon: 'none', 2726 icon: 'none',
2790 }); 2727 });
2791 - // getApp().my_warnning('购买数量超出活动库存', 0, th);  
2792 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2793 - e.setData({  
2794 - [txt]: false_data.goods_num - false_data.buy_num  
2795 - });  
2796 - e.doCheckAll();  
2797 -  
2798 - t.goods_num = false_data.goods_num - false_data.buy_num;  
2799 - e.update_cart(t, pitem, item);  
2800 -  
2801 - return false; 2728 + is_showing=1;
2802 } 2729 }
  2730 + //一直都要给一个最小值,和活动库存比较
  2731 + if(cbuy>false_data.goods_num - false_data.buy_num) cbuy=false_data.goods_num - false_data.buy_num;
2803 2732
2804 //--判断redis数量是否已经超出-- 2733 //--判断redis数量是否已经超出--
2805 - if (t.goods_num > false_data.redisnum) {  
2806 - // wx.showModal({  
2807 - // title: '提示',  
2808 - // content: '购买数量超出商品库存'  
2809 - // }); 2734 + if (t.goods_num > false_data.redisnum && !is_showing) {
2810 wx.showToast({ 2735 wx.showToast({
2811 title: '购买数量超出商品库存', 2736 title: '购买数量超出商品库存',
2812 icon: 'none', 2737 icon: 'none',
2813 }); 2738 });
2814 - //getApp().my_warnning('购买数量超出商品库存', 0, th);  
2815 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2816 - e.setData({  
2817 - [txt]: false_data.redisnum  
2818 - });  
2819 - e.doCheckAll();  
2820 -  
2821 - t.goods_num = false_data.redisnum;  
2822 - e.update_cart(t, pitem, item);  
2823 - return false; 2739 + is_showing=1;
2824 } 2740 }
2825 2741
  2742 + //一直都要给一个最小值,和活动库存比较
  2743 + if(cbuy>false_data.redisnum) cbuy=false_data.redisnum;
  2744 +
2826 //--活动的限购是不是要判断-- 2745 //--活动的限购是不是要判断--
2827 - if (t.goods_num + promgoodsbuynum > false_data.buy_limit && false_data.buy_limit > 0) {  
2828 - // wx.showModal({  
2829 - // title: '提示',  
2830 - // content: '购买数量超出秒杀限购'  
2831 - // });  
2832 - wx.showToast({  
2833 - title: '购买数量超出秒杀限购',  
2834 - icon: 'none',  
2835 - });  
2836 - // getApp().my_warnning('购买数量超出秒杀限购', 0, th);  
2837 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2838 - e.setData({  
2839 - [txt]: false_data.buy_limit  
2840 - });  
2841 - e.doCheckAll();  
2842 - t.goods_num = (false_data.buy_limit - promgoodsbuynum) ? false_data.buy_limit - promgoodsbuynum : 0;  
2843 - e.update_cart(t, pitem, item);  
2844 - return false; 2746 + if(false_data.buy_limit > 0) {
  2747 +
  2748 + if(t.goods_num + promgoodsbuynum > false_data.buy_limit && !is_showing){
  2749 + wx.showToast({
  2750 + title: '购买数量超出秒杀限购',
  2751 + icon: 'none',
  2752 + });
  2753 + }
  2754 +
  2755 + var act_limit=false_data.buy_limit-promgoodsbuynum;
  2756 + if(!act_limit) act_limit=0;
  2757 +
  2758 + if(cbuy>act_limit) cbuy=act_limit;
  2759 +
2845 } 2760 }
  2761 +
  2762 + if(t.goods_num>cbuy) t.goods_num=cbuy;
  2763 +
2846 e.update_cart(t, pitem, item); 2764 e.update_cart(t, pitem, item);
2847 2765
2848 - } else {  
2849 - normal_check(store_count, goodsinfo, wareIds);  
2850 - }  
2851 - }  
2852 - })  
2853 - break; 2766 + } else {
  2767 + e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算
  2768 + }
  2769 + break;
2854 case 2: 2770 case 2:
2855 - getApp().request.promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + goodsinfo.goods_id + "/" + goodsinfo.prom_id, {}).then(res => { 2771 + //-- 读取团购 --
  2772 + var res= await getApp().promiseGet("/api/weshop/goods/groupBuy/getActInfo/" + os.stoid + "/" + goodsinfo.goods_id + "/" + goodsinfo.prom_id, {});
2856 if (res.data.code == 0 && res.data.data) { 2773 if (res.data.code == 0 && res.data.data) {
2857 - if (t.goods_num > store_count) {  
2858 - // wx.showModal({  
2859 - // title: '提示',  
2860 - // content: '购买数量超出商品库存'  
2861 - // }); 2774 +
  2775 + var cbuy=limit;
  2776 + if (t.goods_num > store_count && !is_showing) {
2862 wx.showToast({ 2777 wx.showToast({
2863 title: '购买数量超出商品库存', 2778 title: '购买数量超出商品库存',
2864 icon: 'none', 2779 icon: 'none',
2865 }); 2780 });
2866 - // getApp().my_warnning('购买数量超出商品库存', 0, th);  
2867 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2868 - e.setData({  
2869 - [txt]: store_count  
2870 - });  
2871 - e.doCheckAll();  
2872 -  
2873 - t.goods_num = store_count;  
2874 - e.update_cart(t, pitem, item);  
2875 -  
2876 - return false; 2781 + is_showing=1;
2877 } 2782 }
  2783 + //一直都要给一个最小值,和库存比较
  2784 + if(cbuy>store_count) cbuy=store_count;
2878 2785
2879 var gr_data = res.data.data; 2786 var gr_data = res.data.data;
2880 //--判断库存-- 2787 //--判断库存--
2881 - if (t.goods_num > gr_data.goods_num - gr_data.buy_num) {  
2882 - // wx.showModal({  
2883 - // title: '提示',  
2884 - // content: '购买数量超出活动库存'  
2885 - // }); 2788 + if (t.goods_num > gr_data.goods_num - gr_data.buy_num && !is_showing) {
2886 wx.showToast({ 2789 wx.showToast({
2887 title: '购买数量超出活动库存', 2790 title: '购买数量超出活动库存',
2888 icon: 'none', 2791 icon: 'none',
2889 }); 2792 });
2890 - // getApp().my_warnning('购买数量超出活动库存', 0, th);  
2891 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2892 - e.setData({  
2893 - [txt]: gr_data.goods_num - gr_data.buy_num  
2894 - });  
2895 - e.doCheckAll();  
2896 -  
2897 - t.goods_num = gr_data.goods_num - gr_data.buy_num;  
2898 - e.update_cart(t, pitem, item);  
2899 -  
2900 - return false; 2793 + is_showing=1;
2901 } 2794 }
  2795 + //一直都要给一个最小值,和库存比较
  2796 + if(cbuy>gr_data.goods_num - gr_data.buy_num ) cbuy=gr_data.goods_num - gr_data.buy_num ;
2902 2797
2903 //--判断redis数量是否已经超出-- 2798 //--判断redis数量是否已经超出--
2904 - if (t.goods_num > gr_data.redisnum) {  
2905 - // wx.showModal({  
2906 - // title: '提示',  
2907 - // content: '购买数量超出商品库存'  
2908 - // }); 2799 + if (t.goods_num > gr_data.redisnum && !is_showing) {
2909 wx.showToast({ 2800 wx.showToast({
2910 title: '购买数量超出商品库存', 2801 title: '购买数量超出商品库存',
2911 icon: 'none', 2802 icon: 'none',
2912 }); 2803 });
2913 - // getApp().my_warnning('购买数量超出商品库存', 0, th);  
2914 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2915 - e.setData({  
2916 - [txt]: gr_data.redisnum  
2917 - });  
2918 - e.doCheckAll();  
2919 -  
2920 - t.goods_num = gr_data.redisnum;  
2921 - e.update_cart(t, pitem, item);  
2922 - return false; 2804 + is_showing=1;
2923 } 2805 }
  2806 + if(cbuy>gr_data.redisnum ) cbuy=gr_data.redisnum;
2924 2807
2925 //--活动的限购是不是要判断-- 2808 //--活动的限购是不是要判断--
2926 - if (t.goods_num + promgoodsbuynum > gr_data.buy_limit && gr_data.buy_limit > 0) {  
2927 - // wx.showModal({  
2928 - // title: '提示',  
2929 - // content: '购买数量超出团购限购'  
2930 - // });  
2931 - wx.showToast({  
2932 - title: '购买数量超出团购限购',  
2933 - icon: 'none',  
2934 - });  
2935 - // getApp().my_warnning('购买数量超出团购限购', 0, th);  
2936 - var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";  
2937 - e.setData({  
2938 - [txt]: gr_data.buy_limit  
2939 - });  
2940 - e.doCheckAll(); 2809 + if (gr_data.buy_limit > 0) {
  2810 + if(t.goods_num + promgoodsbuynum > gr_data.buy_limit && !is_showing){
  2811 + wx.showToast({
  2812 + title: '购买数量超出团购限购',
  2813 + icon: 'none',
  2814 + });
  2815 + is_showing=1;
  2816 + }
  2817 +
  2818 + var act_limit=gr_data.buy_limit-promgoodsbuynum;
  2819 + if(!act_limit) act_limit=0;
  2820 +
  2821 + if(cbuy>act_limit) cbuy=act_limit;
2941 2822
2942 - t.goods_num = (gr_data.buy_limit - promgoodsbuynum) ? gr_data.buy_limit - promgoodsbuynum : 0;  
2943 - e.update_cart(t, pitem, item);  
2944 - return false;  
2945 } 2823 }
  2824 +
  2825 + if(t.goods_num>cbuy) t.goods_num=cbuy;
  2826 +
2946 e.update_cart(t, pitem, item); 2827 e.update_cart(t, pitem, item);
2947 2828
2948 } else { 2829 } else {
2949 - normal_check(store_count, goodsinfo, wareIds); 2830 + e.normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds); //普通商品的调用和计算
2950 } 2831 }
2951 - })  
2952 - break; 2832 + break;
2953 default: 2833 default:
2954 - var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id);  
2955 - normal_check(store_count, goodsinfo, wareIds,cx_arr); 2834 + e.normal_check(t, item, pitem,store_count,limit, goodsinfo, wareIds); //普通商品的调用和计算
2956 break 2835 break
2957 } 2836 }
2958 } 2837 }
2959 }); 2838 });
2960 }, 2839 },
2961 2840
  2841 + //-- 这个函数在计算的时候,要包含限购的那一部分 --
  2842 + async normal_check(t, item, pitem,store_count,limit,goodsinfo, wareIds){
  2843 +
  2844 + var cx_arr=await getApp().get_has_cx_act(goodsinfo.goods_id);
  2845 +
  2846 + var th=this;
  2847 + // getApp().my_warnning('购买数量超出商品库存', 0, th);
  2848 + var txt = "requestData[" + pitem + "].goods[" + item + "].goods_num";
  2849 +
  2850 + //--- 看一下是不是线下库存 ---
  2851 + if (th.data.sales_rules >= 2 && !goodsinfo.whsle_id) {
  2852 +
  2853 + //th.check_down_line(t, pitem, item, wareIds,limit);
  2854 + var ob = {};
  2855 + await th.check_down_line_next(t, pitem, item, erpwareid, function (res) {
  2856 + ob = res;
  2857 + });
  2858 +
  2859 +
  2860 + } else {
  2861 +
  2862 + var is_showing=0;
  2863 + var cbuy=limit;
  2864 + if (t.goods_num > limit) {
  2865 + wx.showToast({
  2866 + title: '购买数量超出商品限购',
  2867 + icon: 'none',
  2868 + });
  2869 + is_showing=1;
  2870 + }
  2871 +
  2872 + if (t.goods_num > store_count) {
  2873 + if(!is_showing){
  2874 + wx.showToast({
  2875 + title: '购买数量超出商品库存',
  2876 + icon: 'none',
  2877 + });
  2878 + is_showing=1;
  2879 + }
  2880 + }
  2881 + if(cbuy>store_count) cbuy=store_count;
  2882 +
  2883 + if(t.goods_num>cbuy) t.goods_num=cbuy;
  2884 +
  2885 + if([0,3,5,7,10].indexOf(goodsinfo.prom_type)>-1){
  2886 + var mo_num=getApp().get_limit_qty(goodsinfo,cx_arr.length);
  2887 + var steep=getApp().get_limit_qty(goodsinfo,cx_arr.length,1);
  2888 +
  2889 + if(mo_num>1 && t.goods_num<mo_num){
  2890 + if(!is_showing) {
  2891 + wx.showToast({
  2892 + title: '购买数量小于商品的起订量',
  2893 + icon: 'none',
  2894 + });
  2895 + }
  2896 + t.goods_num=mo_num;
  2897 + }
  2898 +
  2899 + if(steep>1 && t.goods_num>mo_num && (t.goods_num-mo_num)%steep!=0){
  2900 + if(!is_showing) {
  2901 + wx.showToast({
  2902 + title: '购买数量必须是起订量的倍数',
  2903 + icon: 'none',
  2904 + });
  2905 + }
  2906 + if(t.goods_num<mo_num) t.goods_num=mo_num;
  2907 + else{
  2908 + t.goods_num=mo_num+parseInt((t.goods_num-mo_num)/steep+'')*steep
  2909 + }
  2910 + }
  2911 + }
  2912 +
  2913 + th.update_cart(t, pitem, item);
  2914 + }
  2915 + },
  2916 +
2962 //----------------------更新购物数量,加减,调用接口--------------------- 2917 //----------------------更新购物数量,加减,调用接口---------------------
2963 postCardList_ser: async function (t, item, pitem) { 2918 postCardList_ser: async function (t, item, pitem) {
2964 var e = this, 2919 var e = this,
@@ -3156,11 +3111,10 @@ Page({ @@ -3156,11 +3111,10 @@ Page({
3156 promcardbuynum: tt.data.data.promcardbuynum, 3111 promcardbuynum: tt.data.data.promcardbuynum,
3157 cardbuynum: tt.data.data.cardbuynum, 3112 cardbuynum: tt.data.data.cardbuynum,
3158 }); 3113 });
3159 - }; 3114 + }
3160 }); 3115 });
3161 3116
3162 3117
3163 -  
3164 var buylimit = 0 3118 var buylimit = 0
3165 await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, { 3119 await getApp().request.promiseGet("/api/ms/flash_sale/getNew/" + t.store_id + "/" + getApp().globalData.user_id + "/" + t.prom_id, {
3166 3120
@@ -3170,7 +3124,7 @@ Page({ @@ -3170,7 +3124,7 @@ Page({
3170 th.data.sele_g = res.data.data; 3124 th.data.sele_g = res.data.data;
3171 th.data.sele_g.viplimited = res.data.data.buy_limit; 3125 th.data.sele_g.viplimited = res.data.data.buy_limit;
3172 buylimit = res.data.data.buy_limit; 3126 buylimit = res.data.data.buy_limit;
3173 - }; 3127 + }
3174 }); 3128 });
3175 3129
3176 3130
@@ -3188,18 +3142,15 @@ Page({ @@ -3188,18 +3142,15 @@ Page({
3188 }); 3142 });
3189 // getApp().my_warnning('超出活动限购', 0, th); 3143 // getApp().my_warnning('超出活动限购', 0, th);
3190 th.setData({ [txt]: buylimit }); 3144 th.setData({ [txt]: buylimit });
3191 -  
3192 }; 3145 };
3193 3146
3194 } 3147 }
3195 3148
3196 -  
3197 th.doCheckAll(); 3149 th.doCheckAll();
3198 th.update_cart_ser(t, pitem, item); 3150 th.update_cart_ser(t, pitem, item);
3199 3151
3200 3152
3201 -  
3202 - }; 3153 + }
3203 }, 3154 },
3204 3155
3205 3156
@@ -3232,11 +3183,9 @@ Page({ @@ -3232,11 +3183,9 @@ Page({
3232 3183
3233 var this_obj = this.data.requestData[pitem].goods[item]; 3184 var this_obj = this.data.requestData[pitem].goods[item];
3234 3185
3235 - if (th.data.sales_rules == 3 && this_obj.selected) {  
3236 - 3186 + if (th.data.sales_rules >= 2 && this_obj.selected) {
3237 3187
3238 var goods_id = this_obj.goods_id; 3188 var goods_id = this_obj.goods_id;
3239 -  
3240 var num = 0; 3189 var num = 0;
3241 3190
3242 for (let i = 0; i < this.data.requestData.length; i++) { 3191 for (let i = 0; i < this.data.requestData.length; i++) {
@@ -3257,17 +3206,15 @@ Page({ @@ -3257,17 +3206,15 @@ Page({
3257 return false; 3206 return false;
3258 } 3207 }
3259 3208
3260 -  
3261 -  
3262 } 3209 }
3263 } 3210 }
3264 3211
3265 3212
3266 -  
3267 -  
3268 this.update_cart(t, pitem, item); 3213 this.update_cart(t, pitem, item);
3269 }, 3214 },
3270 3215
  3216 +
  3217 +
3271 //---检验线下库存的数量的子函数--- 3218 //---检验线下库存的数量的子函数---
3272 async check_down_line_next(t, pitem, item, erpwareid, func) { 3219 async check_down_line_next(t, pitem, item, erpwareid, func) {
3273 3220
pages/goods/goodsInfo/goodsInfo.js
@@ -2444,11 +2444,14 @@ Page({ @@ -2444,11 +2444,14 @@ Page({
2444 //------检查数量是不是超出限购------ 2444 //------检查数量是不是超出限购------
2445 checkCartNum: function (t) { 2445 checkCartNum: function (t) {
2446 var th = this; 2446 var th = this;
  2447 +
2447 var mo_num=getApp().get_limit_qty(th.data.sele_g,th.data.is_act); 2448 var mo_num=getApp().get_limit_qty(th.data.sele_g,th.data.is_act);
2448 var steep=getApp().get_limit_qty(th.data.sele_g,th.data.is_act,1); 2449 var steep=getApp().get_limit_qty(th.data.sele_g,th.data.is_act,1);
2449 -  
2450 this.get_buy_num(this.data.sele_g, async function () { 2450 this.get_buy_num(this.data.sele_g, async function () {
2451 2451
  2452 + var is_show_bs=0;
  2453 + var l_num=-1;
  2454 +
2452 //--判断商品是否超出限购-- 2455 //--判断商品是否超出限购--
2453 if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) { 2456 if (th.data.g_buy_num != null && th.data.sele_g.viplimited > 0) {
2454 2457
@@ -2459,13 +2462,16 @@ Page({ @@ -2459,13 +2462,16 @@ Page({
2459 title: '超出商品限购', 2462 title: '超出商品限购',
2460 icon: 'none', 2463 icon: 'none',
2461 }); 2464 });
  2465 +
  2466 + is_show_bs=1;
  2467 +
2462 // s.my_warnning('超出商品限购', 0, th); 2468 // s.my_warnning('超出商品限购', 0, th);
2463 - var num = th.data.sele_g.viplimited - gd_buy_num;  
2464 - if (num < 0) num = 0;  
2465 - th.setData({  
2466 - goodsInputNum: num  
2467 - })  
2468 - return false; 2469 + l_num = th.data.sele_g.viplimited - gd_buy_num;
  2470 + if (l_num < 0) l_num = 0;
  2471 + // th.setData({
  2472 + // goodsInputNum: num
  2473 + // })
  2474 + // return false;
2469 } 2475 }
2470 } 2476 }
2471 2477
@@ -2533,25 +2539,47 @@ Page({ @@ -2533,25 +2539,47 @@ Page({
2533 } 2539 }
2534 } 2540 }
2535 2541
  2542 + //-- 限购数量也要进行计算一下 --
  2543 + if(l_num>-1){
  2544 + if(e>l_num) e=l_num;
  2545 + }
  2546 +
2536 //--- 促销活动也不控制起订量, 这里很重要的一个控制,起订量的 ---- 2547 //--- 促销活动也不控制起订量, 这里很重要的一个控制,起订量的 ----
2537 if([0,3,5,7,10].indexOf(p_type)>-1 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1){ 2548 if([0,3,5,7,10].indexOf(p_type)>-1 || th.data.openSpecModal_inte_normal == 1 || th.data.is_normal == 1){
2538 - if(t<mo_num) t=mo_num; 2549 + if(t<mo_num) {
  2550 + t=mo_num;
  2551 + if(!is_show_bs) {
  2552 + wx.showToast({
  2553 + title: '购买数未达到起订量',
  2554 + icon: 'none',
  2555 + });
  2556 + }
  2557 + is_show_bs=1;
  2558 + }
2539 if(t>mo_num && (t-mo_num)%steep!=0){ 2559 if(t>mo_num && (t-mo_num)%steep!=0){
2540 - wx.showToast({  
2541 - title: '购买数必须是起订量的倍数',  
2542 - icon: 'none',  
2543 - }); 2560 +
  2561 + if(!is_show_bs){
  2562 + wx.showToast({
  2563 + title: '购买数必须是起订量的倍数',
  2564 + icon: 'none',
  2565 + });
  2566 + }
  2567 +
2544 t=mo_num+ parseInt((t-mo_num)/steep)*steep+steep; 2568 t=mo_num+ parseInt((t-mo_num)/steep)*steep+steep;
  2569 + is_show_bs=1;
2545 } 2570 }
2546 } 2571 }
2547 2572
2548 if (!e) e = 0; 2573 if (!e) e = 0;
2549 //库存不足,不增加 2574 //库存不足,不增加
2550 if (e < t) { 2575 if (e < t) {
2551 - wx.showToast({  
2552 - title: '库存不足',  
2553 - icon: 'none',  
2554 - }); 2576 + if(!is_show_bs){
  2577 + wx.showToast({
  2578 + title: '库存不足',
  2579 + icon: 'none',
  2580 + });
  2581 + }
  2582 +
2555 // wx.showModal({title: '库存不足',}); 2583 // wx.showModal({title: '库存不足',});
2556 if (e < 0) e = 0; 2584 if (e < 0) e = 0;
2557 2585