优化出水上限判断
diff --git a/supwisdom/sp_constant.h b/supwisdom/sp_constant.h
index af5b43c..6971775 100644
--- a/supwisdom/sp_constant.h
+++ b/supwisdom/sp_constant.h
@@ -23,6 +23,8 @@
 #define RC_NOT_SAME_CARD				30	//²»Í¬¿¨
 
 #define RC_UPDPROG_ERR					43	//Éý¼¶Ê§°Ü
+#define RC_WATER_LIMIT_OUT				44  // µ¥´ÎÁ÷Á¿³¬ÏÞ
+#define RC_AMOUNT_LIMIT_OUT				45  // µ¥´ÎÏû·Ñ½ð¶î³¬ÏÞ
 
 #define RC_CONFPARA_CRC_ERR   			55  //ÅäÖòÎÊýcrc´íÎó
 #define RC_TRANSDTL_FULL				58	//	Á÷Ë®ÒÑÂú
diff --git a/supwisdom/sp_consume.c b/supwisdom/sp_consume.c
index ff53b27..d14f728 100644
--- a/supwisdom/sp_consume.c
+++ b/supwisdom/sp_consume.c
@@ -313,6 +313,15 @@
 
   if(pos->purchase.prepaid_num > 0)
   {
+    if((pos->purchase.paid_num +pos->purchase.prepaid_num) >= card->waterlimit)
+    {
+      return RC_WATER_LIMIT_OUT;
+    }
+    else if((pos->purchase.paid_sum +pos->purchase.prepaid_amt) >= card->amountlimit)
+    {
+      return RC_AMOUNT_LIMIT_OUT;
+    }
+
     pos->purchase.paid_num += pos->purchase.prepaid_num;
     pos->purchase.paid_sum += pos->purchase.prepaid_amt;
     pos->purchase.prepaid_num = 0;
@@ -442,8 +451,23 @@
     }
     cardWorkState->pause_status = 0;
     ret = do_work(pos, card);
+    if(RC_WATER_LIMIT_OUT == ret)
+    {
+      sp_valve_off();
+      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î³öË®ÉÏÏÞ", DELAY_TIME2s);
+      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
+      break;
+    }
+    else if(RC_AMOUNT_LIMIT_OUT == ret)
+    {
+      sp_valve_off();
+      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î½ð¶îÉÏÏÞ", DELAY_TIME2s);
+      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
+      break;
+    }
     if(ret)
     {
+      sp_valve_off();
       show_error(pos,"Ïû·Ñʧ°Ü",ret);
       err = do_stop(pos, card);
       if(err != 0)
@@ -453,18 +477,6 @@
       cardWorkState->current_state = CARDWORKSTATUS_ERROR;
       break;
     }
-    if(pos->purchase.used_num >= card->waterlimit)
-    {
-      sp_valve_off();
-      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î³öË®ÉÏÏÞ", DELAY_TIME2s);
-      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
-    }
-    else if(pos->purchase.paid_sum >= card->amountlimit)
-    {
-      sp_valve_off();
-      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î½ð¶îÉÏÏÞ", DELAY_TIME2s);
-      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
-    }
     cardWorkState->pause_tick = timer_get_ticker();
     break;
   case CARDWORKSTATUS_STOPPING:
@@ -706,8 +718,23 @@
     break;
   case CARDWORKSTATUS_WORKING:
     ret = do_work(pos, &CARD);
+    if(RC_WATER_LIMIT_OUT == ret)
+    {
+      sp_valve_off();
+      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î³öË®ÉÏÏÞ", DELAY_TIME2s);
+      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
+      break;
+    }
+    else if(RC_AMOUNT_LIMIT_OUT == ret)
+    {
+      sp_valve_off();
+      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î½ð¶îÉÏÏÞ", DELAY_TIME2s);
+      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
+      break;
+    }
     if(ret)
     {
+      sp_valve_off();
       show_error(pos,"Ïû·Ñʧ°Ü",ret);
       ret = do_stop(pos, &CARD);
       if(ret)
@@ -717,18 +744,6 @@
       cardWorkState->current_state = CARDWORKSTATUS_ERROR;
       break;
     }
-    if(pos->purchase.used_num >= CARD.waterlimit)
-    {
-      sp_valve_off();
-      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î³öË®ÉÏÏÞ", DELAY_TIME2s);
-      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
-    }
-    else if(pos->purchase.paid_sum >= CARD.amountlimit)
-    {
-      sp_valve_off();
-      disp_hint_info_two(pos, "Í£Ö¹³öË®","ÒÑ´ïµ¥´Î½ð¶îÉÏÏÞ", DELAY_TIME2s);
-      cardWorkState->current_state = CARDWORKSTATUS_STOPPING;
-    }
     /**È·ÈϳöË®ºó³¬¹ýµÈ´ýʱ¼äδ³öˮֹͣ³öË®**/
     CARD.qrcode.nowtime = sp_get_ticker();
     if((CARD.qrcode.nowtime - CARD.qrcode.starttime) >= CARD.qrcode.waittime*DELAY_TIME1s)