stanley-king 1 vuosi sitten
vanhempi
commit
a76a3dda92

+ 35 - 15
helper/refill/EventManager.php

@@ -7,6 +7,7 @@ require_once(BASE_HELPER_PATH . '/refill/event/crash.php');
 require_once(BASE_HELPER_PATH . '/refill/event/card_crash.php');
 
 use refill\event\card_crash;
+use Cache;
 
 class EventManager
 {
@@ -15,7 +16,7 @@ class EventManager
     {
         if (self::$stInstance == null) {
             self::$stInstance = new EventManager();
-            self::instance()->load();
+            self::$stInstance->load();
         }
 
         return self::$stInstance;
@@ -25,13 +26,25 @@ class EventManager
 
     public function load()
     {
-        $cfgs = [
-            'open_crash' => true,
-            'cfgs_crash' => [
-                'channels' => 'beirui_sec',
-                'succ_interval' => 900
-            ]
-        ];
+//配置文件样式
+//        $cfgs = [
+//            'open_crash' => true,
+//            'cfgs_crash' => [
+//                'channels' => 'beirui_sec',
+//                'succ_interval' => 900
+//            ]
+//        ];
+
+        $this->mStubs = [];
+
+        $cacher = Cache::getInstance('cacheredis');
+        $cfgs = $cacher->get('event-config', 'refill-');
+
+        if (empty($cfgs)) {
+            return;
+        } else {
+            $cfgs = unserialize($cfgs);
+        }
 
         $open_crash = $cfgs['open_crash'] ?? false;
         if($open_crash) {
@@ -43,7 +56,8 @@ class EventManager
 
     public function onBeforeSubmit(order $order)
     {
-        foreach ($this->mStubs as $stub)
+        $stubs = $this->mStubs;
+        foreach ($stubs as $stub)
         {
             if($stub->onBeforeSubmit($order) === false) {
                 return false;
@@ -54,14 +68,16 @@ class EventManager
     }
     public function onSubmit(order $order)
     {
-        foreach ($this->mStubs as $stub) {
+        $stubs = $this->mStubs;
+        foreach ($stubs as $stub) {
             $stub->onSubmit($order);
         }
     }
 
     public function onBeforeCommit(order $order, $ch_name): bool
     {
-        foreach ($this->mStubs as $stub)
+        $stubs = $this->mStubs;
+        foreach ($stubs as $stub)
         {
             if ($stub->onBeforeCommit($order, $ch_name) === false) {
                 return false;
@@ -72,28 +88,32 @@ class EventManager
     }
     public function onCommit(order $order, $ch_name)
     {
-        foreach ($this->mStubs as $stub) {
+        $stubs = $this->mStubs;
+        foreach ($stubs as $stub) {
             $stub->onCommit($order, $ch_name);
         }
     }
 
     public function onNeterror(order $order, $ch_name)
     {
-        foreach ($this->mStubs as $stub) {
+        $stubs = $this->mStubs;
+        foreach ($stubs as $stub) {
             $stub->onNeterror($order, $ch_name);
         }
     }
 
     public function onNotify($refill_info, $order_info, $success)
     {
-        foreach ($this->mStubs as $stub) {
+        $stubs = $this->mStubs;
+        foreach ($stubs as $stub) {
             $stub->onNotify($refill_info, $order_info, $success);
         }
     }
 
     public function onComplete($refill_info, $order_info, $success)
     {
-        foreach ($this->mStubs as $stub) {
+        $stubs = $this->mStubs;
+        foreach ($stubs as $stub) {
             $stub->onComplete($refill_info, $order_info, $success);
         }
     }

+ 1 - 0
helper/refill/XYZRefillFactory.php

@@ -40,6 +40,7 @@ require_once(BASE_HELPER_PATH . '/refill/policy/mchannel.php');
 require_once(BASE_HELPER_PATH . '/refill/policy/third_helper.php');
 require_once(BASE_HELPER_PATH . '/refill/functional.php');
 require_once(BASE_HELPER_PATH . '/refill/chprice_helper.php');
+require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
 
 use Log;
 use StatesHelper;

+ 1 - 0
rdispatcher/codispatcher.php

@@ -80,6 +80,7 @@ function subscribe_message(&$quit, &$redis, $channels)
                     if($type == 'channel' || $type == 'merchant') {
                         refill\RefillFactory::instance()->load();
                         refill\transfer::instance()->load();
+                        refill\EventManager::instance()->load();
                     }
                     elseif($type == 'mch_profit_ratio') {
                         $ins = Cache::getInstance('cacheredis');

+ 11 - 4
test/TestRefillUtil.php

@@ -9,11 +9,13 @@ define('BASE_ROOT_PATH', str_replace('/test', '', dirname(__FILE__)));
 require_once(BASE_ROOT_PATH . '/global.php');
 require_once(BASE_CORE_PATH . '/lrlz.php');
 require_once(BASE_ROOT_PATH . '/fooder.php');
-require_once(BASE_HELPER_PATH . '/refill/util.php');
 
-require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
-require_once(BASE_HELPER_PATH . '/refill/event/test_crash.php');
-require_once(BASE_HELPER_PATH . '/refill/order.php');
+require_once(BASE_HELPER_PATH . '/refill/XYZRefillFactory.php');
+
+//require_once(BASE_HELPER_PATH . '/refill/util.php');
+//require_once(BASE_HELPER_PATH . '/refill/EventManager.php');
+//require_once(BASE_HELPER_PATH . '/refill/event/test_crash.php');
+//require_once(BASE_HELPER_PATH . '/refill/order.php');
 
 class TestRefillUtil extends TestCase
 {
@@ -22,6 +24,11 @@ class TestRefillUtil extends TestCase
         Base::run_util();
     }
 
+    public function testEventLoad()
+    {
+        refill\EventManager::instance()->load();
+    }
+
     public function testQueueOrder()
     {
         refill\util::push_queue_order(1092,'abcdefg',30);