Przeglądaj źródła

util transfer_success_order

xiaoyu 2 lat temu
rodzic
commit
0190eff73e
1 zmienionych plików z 51 dodań i 0 usunięć
  1. 51 0
      helper/refill/util.php

+ 51 - 0
helper/refill/util.php

@@ -818,4 +818,55 @@ class util
             return [false,"{$ex->getMessage()}"];
         }
     }
+
+    public function transfer_success_order($order_id, $manual_recharge_amount)
+    {
+        $mod_order = Model('vr_order');
+        $mod_refill = Model('refill_order');
+
+        $order_info = $mod_order->getOrderInfo(['order_id' => $order_id]);
+        $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id,'inner_status' => 0]);
+
+        if(empty($refill_info) || empty($order_info)) {
+            return [false,'无此订单'];
+        }
+
+        $tran = new trans_wapper($mod_order,'notify change order state trans');
+
+        try
+        {
+            $order_info = $mod_order->getOrderInfo(['order_id' => $order_id], '*', true, true);
+            $refill_info = $mod_refill->getOrderInfo(['order_id' => $order_id, 'inner_status' => 0], '*', true, true);
+
+            $order_state = intval($order_info['order_state']);
+            if(empty($refill_info) || $refill_info['is_retrying'] == 1 || $order_state != ORDER_STATE_CANCEL) {
+                $tran->commit();
+                return [false,'订单已经在重试'];
+            }
+
+            $mod_refill->edit($order_id, ['is_retrying' => 1]);
+            $order = refill\order::from_db($refill_info,$order_info);
+            $mchid = $order->mchid();
+
+            [$success,$success_order_id,$errmsg] = refill\RefillFactory::instance()->success_order($order);
+            if(!$success) {
+                $tran->rollback();
+                return [false, $errmsg];
+            }
+
+            refill\util::incr_user_success($mchid,$order->card_type(), $order->spec(),$order->cur_quality());
+            $mod_refill->edit($success_order_id, ['mch_notify_state' => 1, 'mch_notify_times' => ['exp', 'mch_notify_times+1']]);
+            $mod_refill->edit($order_id, ['is_retrying' => 0]);
+            if($manual_recharge_amount > 0) {
+                $mod_refill->edit($success_order_id, ['channel_amount' => $manual_recharge_amount]);
+            }
+            $tran->commit();
+            return [true,''];
+        }
+        catch (Exception $ex) {
+            $tran->rollback();
+            Log::record($ex->getMessage(),Log::ERR);
+            return [false,"{$ex->getMessage()}"];
+        }
+    }
 }