xiaoyu 3 years ago
parent
commit
d8e95d13ee
1 changed files with 32 additions and 20 deletions
  1. 32 20
      admin/control/refill_order_manual.php

+ 32 - 20
admin/control/refill_order_manual.php

@@ -159,6 +159,7 @@ class refill_order_manualControl extends SystemControl
 
         $cond = [];
         $cond['refill_order.order_id'] = ['in',$order_ids];
+        $cond['refill_order.inner_status'] = 0;
         $cond['refill_order.is_retrying'] = 0;
 
         if ($oper_type == 'success' || $oper_type == 'cancel') {
@@ -201,11 +202,12 @@ class refill_order_manualControl extends SystemControl
         $admininfo = $this->getAdminInfo();
         $bz = empty($bz) ? '' : $bz;
 
-        $refill_buyback_model = Model('refill_buyback');
-        $buybacks = $refill_buyback_model->getList(['order_id' => ['in',$order_ids], 'manual_type' => $oper_type]);
-        $buyback_ids = array_column($buybacks, 'order_id');
-        $buyback_ids = $this->int_array($buyback_ids);
-        $buyback_ids = $this->unique_array($buyback_ids);
+        $buyback_ids = function ($order_ids,$oper_type){
+            $buybacks = Model('refill_buyback')->getList(['order_id' => ['in',$order_ids], 'manual_type' => $oper_type]);
+            $buyback_ids = array_column($buybacks, 'order_id');
+            $buyback_ids = $this->int_array($buyback_ids);
+            return $this->unique_array($buyback_ids);
+        };
 
         if($oper_type == 'buyback') {
             $mchids = array_column($orders, 'mchid');
@@ -221,11 +223,17 @@ class refill_order_manualControl extends SystemControl
                 $providers[$provider['store_id']] = $provider;
             }
         }
-
+        $fetch = true;
+        $resp = true;
         $cur_time = time();
-        $trans = new trans_wapper($refill_buyback_model, __METHOD__);
-        try {
-            foreach ($orders as $order) {
+        $refill_buyback_model = Model('refill_buyback');
+        foreach ($orders as $order) {
+            $trans = new trans_wapper($refill_buyback_model, __METHOD__);
+            try {
+                if($fetch) {
+                    $buyback_ids = $buyback_ids($order_ids, $oper_type);
+                    $fetch = false;
+                }
                 $order_id = intval($order['order_id']);
                 //已经找到相同类型的操作记录,不处理.
                 if(algorithm::binary_search($buyback_ids,$order_id)) continue;
@@ -238,7 +246,8 @@ class refill_order_manualControl extends SystemControl
                     if(empty($mchid) || empty($buyer_id)) {
                         Log::record("refill order manual merchant err order_id:{$order_id}, order_sn:{$order['order_sn']}");
                         $trans->rollback();
-                        showMessage('机构数据获取失败!');
+                        $resp = false;
+                        break;
                     }
                     $merchant_bz = "机构:{$mchid},订单号:{$order['mch_order']},卡号:{$order['card_no']},返销退款:{$order['mch_amount']}";
                     $this->ct_refill_evidence(['mch_amount' => $order['mch_amount'], 'bz' => $merchant_bz], $merchant_info, $cur_time, $admininfo);
@@ -250,7 +259,8 @@ class refill_order_manualControl extends SystemControl
                     if(empty($store_id) || empty($account_id)) {
                         Log::record("refill order manual provider err order_id:{$order_id}, order_sn:{$order['order_sn']}");
                         $trans->rollback();
-                        showMessage('通道数据获取失败!');
+                        $resp = false;
+                        break;
                     }
                     $provider_bz = "通道:{$store_id},椰子单号:{$order['order_sn']},卡号:{$order['card_no']},返销退款:{$order['channel_amount']}";
                     $this->ct_provider_amount(['channel_amount' => $order['channel_amount']], $provider_info, $cur_time, $admininfo);
@@ -280,17 +290,19 @@ class refill_order_manualControl extends SystemControl
                     'order_id' => $order['order_id'], 'order_sn' => $order['order_sn'],'order_time' => $order['order_time'], 'notify_time' => $order['notify_time'],
                     'manual_type' => $oper_type, 'admin_id' => $admininfo['id'], 'admin_name' => $admininfo['name'], 'act_time' => $cur_time, 'bz' => $bz
                 ];
+
+                $trans->commit();
+            }catch (Exception $e){
+                $trans->rollback();
+                Log::record("manual_record err: {$e->getMessage()}", Log::ERR);
+                $resp = false;
+                break;
             }
-            if(!empty($ins)) {
-                $refill_buyback_model->insertAll($ins);
-            }
-            $trans->commit();
-            return true;
-        }catch (Exception $e){
-            $trans->rollback();
-            Log::record("manual_record err: {$e->getMessage()}", Log::ERR);
-            return false;
         }
+        if($resp && !empty($ins)) {
+            $refill_buyback_model->insertAll($ins);
+        }
+        return $resp;
     }
 
     public function set_cancel_orderOp()