Browse Source

add mchids exclude

stanley-king 1 year atrás
parent
commit
403859513c
3 changed files with 57 additions and 8 deletions
  1. 21 5
      admin/control/refill_event.php
  2. 26 3
      helper/refill/event/card_crash.php
  3. 10 0
      helper/refill/util.php

+ 21 - 5
admin/control/refill_event.php

@@ -11,7 +11,7 @@ class refill_eventControl extends SystemControl
 
     public function indexOp()
     {
-        $channels_reader = function ($input)
+        $str_reader = function ($input)
         {
             $ches = [];
             $data = explode(',', $input);
@@ -25,6 +25,20 @@ class refill_eventControl extends SystemControl
             return implode(',', $ches);
         };
 
+        $int_reader = function ($input)
+        {
+            $result = [];
+            $data = explode(',', $input);
+            foreach ($data as $val)
+            {
+                $val = trim($val);
+                if (intval($val) > 0) {
+                    $result[] = $val;
+                }
+            }
+            return implode(',', $result);
+        };
+
         $cacher = Cache::getInstance('cacheredis');
         $cfgs = $cacher->get('event-config', 'refill-');
 
@@ -37,19 +51,21 @@ class refill_eventControl extends SystemControl
             $cfgs['open_crash'] = false;
             $cfgs['cfgs_crash'] = [
                 'channels' => "",
-                'succ_interval' => 900
+                'succ_interval' => 900,
+                'mchids' => ''
             ];
         }
 
         if (chksubmit())
         {
-            $channels = $channels_reader($_POST['channels']);
-            $mchids = $channels_reader($_POST['mchids']);
+            $channels = $str_reader($_POST['channels']);
+            $mchids = $int_reader($_POST['mchids']);
 
             $cfgs['open_crash'] = boolval($_POST['open_crash'] ?? false);
             $cfgs['cfgs_crash'] = [
                 'channels' => $channels,
-                'succ_interval' => intval($_POST['succ_interval'])
+                'succ_interval' => intval($_POST['succ_interval']),
+                'mchids' => $mchids
             ];
             $cacher->set('event-config', serialize($cfgs), 'refill-');
             showMessage('编辑成功');

+ 26 - 3
helper/refill/event/card_crash.php

@@ -15,6 +15,8 @@ class card_crash extends IEventRefill
     protected $mChannels = [];
     protected $mSuccInterval = 900;
 
+    protected $mExMchids = [];
+
     public function __construct()
     {
     }
@@ -30,6 +32,18 @@ class card_crash extends IEventRefill
         }
 
         $this->mSuccInterval = intval($cfgs['succ_interval'] ?? 900);
+
+        //读取撞单排除机构
+        $mchids = $cfgs['mchids'] ?? '';
+        $mchids = explode(',',$mchids);
+        $this->mExMchids = [];
+        foreach ($mchids as $item)
+        {
+            $mchid = intval($item);
+            if($mchid > 0) {
+                $this->mExMchids[] = $mchid;
+            }
+        }
     }
 
     public function onBeforeSubmit(order $order) : bool
@@ -49,10 +63,18 @@ class card_crash extends IEventRefill
             $mod_refill = Model('refill_order');
             $val = $mod_refill->get_detail($mchid, $mch_order);
 
-            if(!empty($val)) {
+            if(!empty($val))
+            {
                 $params = json_decode($val['params'],true);
-                util::async_add($params, 60);
-                Log::record("card_crash mchid=$mchid,mch_order $mch_order sleep one minute.", Log::DEBUG);
+
+                //在排除队列,这时可以提单,后面需要尽快失败返回.
+                if (in_array($mchid, $this->mExMchids)) {
+                    util::async_add_zero($params, 5);
+                    Log::record("card_crash mchid=$mchid,mch_order $mch_order add zero order.", Log::DEBUG);
+                } else {
+                    util::async_add($params, 60);
+                    Log::record("card_crash mchid=$mchid,mch_order $mch_order sleep one minute.", Log::DEBUG);
+                }
 
                 return false;
             }
@@ -79,6 +101,7 @@ class card_crash extends IEventRefill
             return true;
         }
 
+        $mchid = $order->mchid();
         $card_no = $order->card_no();
         $oid = $order->unique_id();
 

+ 10 - 0
helper/refill/util.php

@@ -242,6 +242,16 @@ class util
         }
     }
 
+    public static function async_add_zero($params, $period = 10)
+    {
+        try {
+            QueueClient::async_push("AysncAddDispatcher", ['method' => 'add_zero', 'params' => $params], $period);
+            return true;
+        } catch (Exception $ex) {
+            return false;
+        }
+    }
+
     public static function async_notify($chname,$data, $period)
     {
         try {