Prechádzať zdrojové kódy

add transation to retry

stanley-king 4 rokov pred
rodič
commit
a7fe1772d7

+ 32 - 11
helper/refill/RefillFactory.php

@@ -64,10 +64,12 @@ use QueueClient;
 use member_info;
 use Exception;
 use rbridge\RBridgeFactory;
+use trans_wapper;
 
 class RefillFactory
 {
     private static $stInstance = null;
+    private $trans_wapper;
 
     public static function instance()
     {
@@ -262,13 +264,16 @@ class RefillFactory
             return false;
         }
 
-        if ($caller->verify($input)) {
+        $this->trans_wapper = trans_wapper;
+        if ($caller->verify($input))
+        {
             [$order_id, $success, $can_try, $need_handle] = $caller->notify($input);
             if (!$need_handle) {
                 return true;
             }
 
-            if ($order_id !== false) {
+            if ($order_id !== false)
+            {
                 $mod_order = Model('vr_order');
                 $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
                 $order_state = intval($order_info['order_state']);
@@ -277,22 +282,38 @@ class RefillFactory
                     return false;
                 }
 
-                $mod_refill = Model('refill_order');
-                $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id]);
-
                 $logic_vr_order = Logic("vr_order");
                 if ($success) {
                     $logic_vr_order->changeOrderStateSuccess($order_id);
-                } elseif ($can_try) {
-                    $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试");
-                    if ($this->retry($refill_info, $order_info) !== false) {
-                        $mod_refill->edit($order_id, ['inner_status' => 1, 'notify_time' => time(), 'notify_state' => 1]);
-                        return true;
+                }
+                elseif ($can_try)
+                {
+                    try
+                    {
+                        $mod_refill = Model('refill_order');
+                        $trans = new trans_wapper($mod_refill, __METHOD__);
+                        $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
+                        if(!empty($refill_info))
+                        {
+                            $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试");
+                            if ($this->retry($refill_info, $order_info)) {
+                                $mod_refill->edit($order_id, ['inner_status' => 1, 'notify_time' => time(), 'notify_state' => 1]);
+                            }
+                        }
+                        $trans->commit();
                     }
-                } else {
+                    catch (Exception $ex) {
+                        $trans->rollback();
+                        Log::record("Error:" . $ex->getMessage(),Log::ERR);
+                    }
+
+                    return true;
+                }
+                else {
                     $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.");
                 }
 
+                $mod_refill = Model('refill_order');
                 $mod_refill->edit($order_id, ['notify_time' => time(), 'notify_state' => 1]);
                 QueueClient::push("NotifyMerchantComplete", ['order_id' => $order_id]);
             } else {

+ 5 - 1
helper/refill/bjb/RefillCallBack.php

@@ -40,8 +40,12 @@ class RefillCallBack implements refill\IRefillCallBack
 
         if ($status === 1) {
             return [$order_id, true, false,true];
-        } elseif ($status === 2) {
+        }
+        elseif ($status === 2) {
             return [$order_id, false, true,true];
         }
+        else {
+            return [$order_id, false, false,false];
+        }
     }
 }

+ 5 - 1
helper/refill/jiec/RefillCallBack.php

@@ -41,8 +41,12 @@ class RefillCallBack implements refill\IRefillCallBack
 
         if ($status === 'success') {
             return [$order_id, true, false,true];
-        } elseif ($status === 'fail') {
+        }
+        elseif ($status === 'fail') {
             return [$order_id, false, true,true];
         }
+        else {
+            return [$order_id, false, false,false];
+        }
     }
 }

+ 3 - 3
test/TestRefill.php

@@ -17,7 +17,7 @@ require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
 const LocalTest = 1;
 const NetTest = 2;
 
-const CurrentTest = LocalTest;
+const CurrentTest = NetTest;
 
 class TestRefill extends TestCase
 {
@@ -341,8 +341,8 @@ class TestRefill extends TestCase
         $params['order'] = 'null';
         $params['phone_no'] = '18500608333';
         $params['amount'] = '30.00';
-        $params['op_no'] = '920663589436764221';
-        $params['sign'] = 'ab66d3e485bb05878772c8e7b1843f03';
+        $params['op_no'] = '800663597981819221';
+        $params['sign'] = '2510046895e8e12322c8a32547905ee9';
 
         $resp = http_request($this->mReqHost . "/mobile/refill_jiec.php", $params, 'POST');
     }