xiaoyu 3 lat temu
rodzic
commit
b178521d69

+ 1 - 1
helper/rbridge/wsd/Bridge.php

@@ -46,10 +46,10 @@ class Bridge implements IBridge
             'mch_order' => $params['chargeId'],
             'notify_url' => config::MCH_NOTIFY_URL];
 
-        refill\util::push_queue($mchid,$params['chargeId'],time());
         $code = refill\util::push_add($input);
         if($code) {
             $ret = $this->retbody($code, '提交成功', $params);
+            refill\util::push_queue_order($mchid,$params['chargeId'],ORDER_STATE_QUEUE);
         }
         else {
             $ret = $this->retbody($code, '提交失败', $params);

+ 7 - 0
helper/refill/RefillBase.php

@@ -155,6 +155,7 @@ class RefillBase
         }
 
         $mod_refill->edit($order_id, ['notify_time' => time(), 'notify_state' => 1]);
+        util::pop_queue_order($mchid,$mch_order);
         QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
         util::del_exclude_channel($mchid,$mch_order,$card_type);
 
@@ -604,6 +605,9 @@ class RefillBase
                 $refill_order = Model('refill_order');
                 $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
                 mtopcard\cards_helper::assign($order_id);
+
+                $refill_info = $refill_order->getOrderInfo(['order_id' => $order_id]);
+                util::pop_queue_order($refill_info['mchid'],$refill_info['mch_order']);
             }
             else {
                 $tran->commit();
@@ -637,6 +641,9 @@ class RefillBase
                 $refill_order = Model('refill_order');
                 $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
                 mtopcard\cards_helper::reuse($order_id);
+
+                $refill_info = $refill_order->getOrderInfo(['order_id' => $order_id]);
+                util::pop_queue_order($refill_info['mchid'],$refill_info['mch_order']);
             }
             else {
                 $tran->commit();

+ 18 - 18
helper/refill/util.php

@@ -223,8 +223,8 @@ class util
     public static function push_add($params)
     {
         try {
-            queue\DispatcherClient::instance()->push('add', $params);
-            return true;
+            $ret = queue\DispatcherClient::instance()->push('add', $params);
+            return $ret !== false;
         } catch (Exception $ex) {
             return false;
         }
@@ -233,8 +233,8 @@ class util
     public static function push_addthird($params)
     {
         try {
-            queue\DispatcherClient::instance()->push('addthird', $params);
-            return true;
+            $ret = queue\DispatcherClient::instance()->push('addthird', $params);
+            return $ret !== false;
         } catch (Exception $ex) {
             return false;
         }
@@ -243,8 +243,8 @@ class util
     public static function push_notify($chname, $params)
     {
         try {
-            queue\DispatcherClient::instance()->push('notify', ['channel' => $chname, 'params' => $params]);
-            return true;
+            $ret = queue\DispatcherClient::instance()->push('notify', ['channel' => $chname, 'params' => $params]);
+            return $ret !== false;
         } catch (Exception $ex) {
             return false;
         }
@@ -253,8 +253,8 @@ class util
     public static function push_notify_merchant($order_id, $manual)
     {
         try {
-            queue\DispatcherClient::instance()->push('notify_mechant', ['order_id' => $order_id, 'manual' => $manual]);
-            return true;
+            $ret = queue\DispatcherClient::instance()->push('notify_mechant', ['order_id' => $order_id, 'manual' => $manual]);
+            return $ret !== false;
         } catch (Exception $ex) {
             return false;
         }
@@ -263,8 +263,8 @@ class util
     public static function push_query($order_id)
     {
         try {
-            queue\DispatcherClient::instance()->push('query', ['order_id' => $order_id]);
-            return true;
+            $ret = queue\DispatcherClient::instance()->push('query', ['order_id' => $order_id]);
+            return $ret !== false;
         } catch (Exception $ex) {
             return false;
         }
@@ -273,8 +273,8 @@ class util
     public static function manual_success($order_id)
     {
         try {
-            queue\DispatcherClient::instance()->push('manual_success', ['order_id' => $order_id]);
-            return true;
+            $ret = queue\DispatcherClient::instance()->push('manual_success', ['order_id' => $order_id]);
+            return $ret !== false;
         } catch (Exception $ex) {
             return false;
         }
@@ -283,8 +283,8 @@ class util
     public static function manual_cancel($order_id)
     {
         try {
-            queue\DispatcherClient::instance()->push('manual_cancel', ['order_id' => $order_id]);
-            return true;
+            $ret = queue\DispatcherClient::instance()->push('manual_cancel', ['order_id' => $order_id]);
+            return $ret !== false;
         } catch (Exception $ex) {
             return false;
         }
@@ -475,16 +475,16 @@ class util
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    public static function push_queue($mchid,$mch_order,$val)
+    public static function push_queue_order($mchid,$mch_order,$order_state)
     {
         $ins = Cache::getInstance('cacheredis');
 
         $name = 'merchant_order_query';
         $key = "{$mchid}-{$mch_order}";
-        $ins->hset($name, '', [$key => $val]);
+        $ins->hset($name, '', [$key => $order_state]);
     }
 
-    public static function pop_queue($mchid,$mch_order)
+    public static function pop_queue_order($mchid,$mch_order)
     {
         $ins = Cache::getInstance('cacheredis');
 
@@ -493,7 +493,7 @@ class util
         $ins->hdel($name, '', $key);
     }
 
-    public static function query_queue($mchid,$mch_order)
+    public static function query_queue_order($mchid,$mch_order)
     {
         $ins = Cache::getInstance('cacheredis');
 

+ 39 - 21
mobile/control/refill.php

@@ -110,14 +110,13 @@ class refillControl extends merchantControl
 
         [$can_refill, $period] = refill\util::can_commit($card_no, $card_type);
         if ($can_refill === false) {
-            refill\util::push_queue($this->mchid(),$mch_order,time() + $period);
             $state = refill\util::async_add($params, $period);
         } else {
-            refill\util::push_queue($this->mchid(),$mch_order,time());
             $state = refill\util::push_add($params);
         }
 
         if ($state === true) {
+            refill\util::push_queue_order($this->mchid(),$mch_order,ORDER_STATE_QUEUE);
             return self::outsuccess(['state' => true]);
         } else {
             $code = $state;
@@ -289,36 +288,55 @@ class refillControl extends merchantControl
             return self::outerr(201,"客户订单号order_sn错误");
         }
 
-        $mod_refill = Model('refill_order');
-        $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
+        $order_state = refill\util::query_queue_order($mchid,$order_sn);
+        if ($order_state == ORDER_STATE_QUEUE || $order_state == ORDER_STATE_SEND) {
+            Log::record("query_state in queue mchid={$mchid} mch_order={$order_sn} order_state={$order_state}" ,Log::DEBUG);
+            $result['mchid'] = $mchid;
+            $result['order_sn'] = $order_sn;
+            $result['order_state'] = $order_state;
 
-        if(empty($refill_info))
+            $this->query_request($mchid,$order_sn);
+            return self::outsuccess($result);
+        }
+        else
         {
-            $ret = refill\util::query_queue($mchid,$order_sn);
-            if ($ret > 0) {
-                $result['mchid'] = $mchid;
-                $result['order_sn'] = $order_sn;
-                $result['order_state'] = ORDER_STATE_QUEUE;
-                return self::outsuccess($result);
-            } else {
+            $mod_refill = Model('refill_order');
+            $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
+
+            if(empty($refill_info))
+            {
+                Log::record("query_state in db no order mchid={$mchid} mch_order={$order_sn}" ,Log::DEBUG);
                 return self::outerr(202, "无此订单");
             }
+            else
+            {
+                $vr_order = Model('vr_order');
+                $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
+                Log::record("query_state in db mchid={$mchid} mch_order={$order_sn} order_state={$order_info['order_state']}" ,Log::DEBUG);
+
+                if (empty($order_info)) {
+                    return self::outerr(203, "无此交易号");
+                } else {
+                    $result = $this->format($order_info, $refill_info);
+                    return self::outsuccess($result);
+                }
+            }
         }
-        else
+    }
+
+    private function query_request($mchid,$order_sn)
+    {
+        $mod_refill = Model('refill_order');
+        $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
+
+        if(!empty($refill_info))
         {
             $vr_order = Model('vr_order');
             $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
 
-            if(empty($order_info)) {
-                return self::outerr(203,"无此交易号");
-            }
-
-            if($order_info['order_state'] == ORDER_STATE_SEND) {
+            if(!empty($order_info) && $order_info['order_state'] == ORDER_STATE_SEND) {
                 QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]);
             }
-
-            $result = $this->format($order_info,$refill_info);
-            return self::outsuccess($result);
         }
     }
 }

+ 51 - 56
racc/control/lzrefill.php

@@ -98,13 +98,12 @@ class lzrefillControl extends lzbaseControl
             'org_quality' => $quality
         ];
 
-        refill\util::push_queue($this->mchid(),$mch_order,time());
         $ret = refill\util::push_add($params);
-        if($ret) {
+        if ($ret) {
+            refill\util::push_queue_order($this->mchid(), $mch_order, ORDER_STATE_QUEUE);
             return self::outsuccess($this->merchant_available);
-        }
-        else {
-            return self::outerr(-6,$this->merchant_available);
+        } else {
+            return self::outerr(-6, $this->merchant_available);
         }
     }
 
@@ -267,80 +266,76 @@ class lzrefillControl extends lzbaseControl
             return self::outerr(-9,$this->merchant_available);
         }
 
-        $mod_refill = Model('refill_order');
-        $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
-
-        if(empty($refill_info))
-        {
-            $state = 3;
-            $msg = "{$order_sn}-无此订单";
+        $order_state = refill\util::query_queue_order($mchid,$order_sn);
+        if ($order_state == ORDER_STATE_QUEUE || $order_state == ORDER_STATE_SEND) {
+            $state = 0;
+            $msg = "{$order_sn}-充值中";
             $remark = "";
             $content = "|{$state}|{$msg}|{$remark}";
             echo $content;
+            $this->query_request($mchid,$order_sn);
+
             return true;
         }
-
-        if(empty($refill_info))
+        else
         {
-            $ret = refill\util::query_queue($mchid,$order_sn);
-            if ($ret > 0) {
-                $state = 0;
-                $msg = "{$order_sn}-充值中";
+            $mod_refill = Model('refill_order');
+            $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
+
+            if(empty($refill_info))
+            {
+                $state = 3;
+                $msg = "{$order_sn}-无此订单";
                 $remark = "";
                 $content = "|{$state}|{$msg}|{$remark}";
                 echo $content;
                 return true;
-            } else {
-                $state = 3;
-                $msg = "{$order_sn}-无此订单";
-                $remark = "";
+            }
+            else
+            {
+                $vr_order = Model('vr_order');
+                $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
+
+                $order_state = $order_info['order_state'];
+                if ($order_state == ORDER_STATE_CANCEL) {
+                    $state = 2;
+                    $msg = "{$order_sn}-充值失败";
+                    $remark = "";
+                } else {
+                    $state = 1;
+                    $msg = "{$order_sn}-充值成功";
+                    $remark = "{$refill_info['official_sn']}";
+                }
+
+                if($refill_info['card_type'] == mtopcard\ThirdRefillCard) {
+                    $remark = $this->third_remark($refill_info);
+                }
+
                 $content = "|{$state}|{$msg}|{$remark}";
                 echo $content;
+
                 return true;
             }
         }
+    }
 
-        $vr_order = Model('vr_order');
-        $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
+    private function query_request($mchid,$order_sn)
+    {
+        $mod_refill = Model('refill_order');
+        $refill_info = $mod_refill->getOrderInfo(['mch_order' => $order_sn,'mchid' => $mchid,'inner_status' => 0]);
 
-        if($refill_info['is_retrying'])
-        {
-            QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]);
-            $state = 0;
-            $msg = "{$order_sn}-充值中";
-            $remark = "";
-        }
-        else
+        if(!empty($refill_info))
         {
-            $order_state = $order_info['order_state'];
-            if($order_state == ORDER_STATE_SEND || $order_state == ORDER_STATE_PAY || $order_state == ORDER_STATE_NEW) {
+            $vr_order = Model('vr_order');
+            $order_info = $vr_order->getOrderInfo(['order_sn' => $refill_info['order_sn']]);
+
+            if(!empty($order_info) && $order_info['order_state'] == ORDER_STATE_SEND) {
                 QueueClient::push("QueryRefillState",['order_id' => $refill_info['order_id']]);
-                $state = 0;
-                $msg = "{$order_sn}-充值中";
-                $remark = "";
-            }
-            elseif($order_state == ORDER_STATE_CANCEL) {
-                $state = 2;
-                $msg = "{$order_sn}-充值失败";
-                $remark = "";
             }
-            else {
-                $state = 1;
-                $msg = "{$order_sn}-充值成功";
-                $remark = "{$refill_info['official_sn']}";
-            }
-        }
-
-        if($refill_info['card_type'] == mtopcard\ThirdRefillCard) {
-            $remark = $this->third_remark($refill_info);
         }
-
-        $content = "|{$state}|{$msg}|{$remark}";
-        echo $content;
-
-        return true;
     }
 
+
     private function third_remark($refill_info)
     {
         $mchinfo = Model('merchant')->getMerchantInfo(['mchid' => $this->mchid()]);

+ 1 - 1
racc/control/refill.php

@@ -106,7 +106,7 @@ class refillControl extends merchantControl
             'org_quality' => $quality
         ];
 
-        refill\util::push_queue($this->mchid(),$mch_order,time());
+        refill\util::push_queue_order($this->mchid(),$mch_order,ORDER_STATE_QUEUE);
         refill\util::push_add($params);
         return self::outsuccess(['state' => true]);
     }

+ 1 - 1
rdispatcher/processor.php

@@ -37,7 +37,7 @@ class processor extends queue\ILooper
                     $input = $params['params'];
 
                     if (empty($channel) || empty($params))
-                        return;
+                        continue;
                     $this->mProxy->notify($channel, $input);
                 } elseif ($method == 'notify_mechant') {
                     $order_id = intval($params['order_id']);

+ 7 - 7
rdispatcher/proxy.php

@@ -35,8 +35,9 @@ class proxy
         $regin_no   = intval($params['regin_no']) ?? 0;
         $quantity = 1;
 
-        Log::record("proxy::add mch_order={$mch_order} card_no = {$card_no}",Log::DEBUG);
+        refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_SEND);
 
+        Log::record("proxy::add mch_order={$mch_order} card_no = {$card_no}",Log::DEBUG);
         $need_check = false;
         $first_comit = false;
         if($card_type == 0)
@@ -64,6 +65,8 @@ class proxy
                 $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
                     $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality, $order_time, $commit_times,
                     "无效的手机号");
+
+                refill\util::pop_queue_order($mchid,$mch_order);
                 QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id, 'manual' => false]);
                 util::del_exclude_channel($mchid,$mch_order,$card_type);
                 return;
@@ -76,10 +79,6 @@ class proxy
         $params['commit_times'] += 1;
         $commit_times += 1;
 
-        if(!empty($mch_order) && $last_order_id == 0 && $order_id > 0) {
-            refill\util::pop_queue($mchid,$mch_order);
-        }
-
         if($errcode !== true)
         {
             $fNotify = true;
@@ -107,7 +106,6 @@ class proxy
                     if (empty($order_info)) {
                         $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
                             $mch_order, $idcard, $card_name, $notify_url, $quality, $org_quality, $order_time, $commit_times, $errmsg);
-                        refill\util::pop_queue($mchid,$mch_order);
                     } else {
                         $order_id = $order_info['order_id'];
                     }
@@ -116,6 +114,7 @@ class proxy
                     $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
                 }
 
+                refill\util::pop_queue_order($mchid,$mch_order);
                 QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
                 util::del_exclude_channel($mchid,$mch_order,$card_type);
             }
@@ -185,6 +184,7 @@ class proxy
             'quantity' => $quantity,
             'third_card_type' => $third_card_type];
 
+        refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_SEND);
         refill\util::incr_user_commit($mchid,$card_type,$amount,$org_quality);
 
         [$errcode, $errmsg, $order_id, $neterr] = refill\RefillFactory::instance()->add($mchid, $buyer_id, $amount, $card_no,
@@ -200,7 +200,6 @@ class proxy
                     $order_id = refill\RefillFactory::instance()->zero_order($mchid, $buyer_id, $amount, $card_no,
                         $mch_order, $idcard, $card_name, $notify_url, $org_quality, $org_quality,
                         $order_time, $commit_times, $errmsg,$quantity,$third_params);
-                    refill\util::pop_queue($mchid,$mch_order);
                 } else {
                     $order_id = $order_info['order_id'];
                 }
@@ -209,6 +208,7 @@ class proxy
                 $refill_order->edit($order_id, ['notify_time' => time(), 'notify_state' => 1,'is_retrying' => 0]);
             }
 
+            refill\util::pop_queue_order($mchid,$mch_order);
             QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id,'manual' => false]);
             util::del_exclude_channel($mchid,$mch_order,$card_type);
         }

+ 16 - 0
test/TestRedis.php

@@ -13,6 +13,8 @@ require_once(BASE_HELPER_PATH . '/refill/RefillFactory.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/rlock.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/rstorage.php');
 
+use refill;
+
 
 function sub_callback($redis, $chan, $msg)
 {
@@ -293,6 +295,20 @@ class TestRedis extends TestCase
     }
 
 
+    public function testPushQueue()
+    {
+        refill\util::push_queue_order(1,"xxxxx",ORDER_STATE_QUEUE);
+        $ret = refill\util::query_queue_order(1,"xxxxx");
+        $ret = refill\util::query_queue_order(1,"xxxxxx");
+        $x = 1;
+    }
+
+    public function testPushReturn()
+    {
+        $ret = refill\util::push_add(['xxxx']);
+        $ret = refill\util::push_notify('xxx',['xxxx']);
+    }
+
     ////docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRedis::testCancel)( .*)?$/" --test-suffix TestRedis.php /var/www/html/test
     ////docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRedis::testCancelPayed)( .*)?$/" --test-suffix TestRedis.php /var/www/html/test
     public static function tearDownAfterClass() : void