stanley-king пре 1 година
родитељ
комит
44cd35245a

+ 7 - 1
data/config/dev/refill.ini.php

@@ -6595,4 +6595,10 @@ $config['cancel_retry_time'] = [10120 => ["9:00",'10:00','11:00']];
 $third_jumps = [
     1092 => ['DY_XYZ_30_LOW' => 'DY_XYZ_30_HIGH','DY_XYZ_30_HIGH' => 'DY_XYZ_30_MAX']
 ];
-$config['third_jumps'] = $third_jumps;
+$config['third_jumps'] = $third_jumps;
+
+#用来配置一次只能提一单的通道
+$unique_channels = [
+    'channels' => ['a','b','c'],#有限制的通道名称
+    'succ_interval' => 900 #成功后多长时间不能提单
+];

+ 9 - 16
helper/refill/RefillBase.php

@@ -80,12 +80,12 @@ class RefillBase
             if ($order_id !== false) {
                 return $this->proc_notify($order_id, $success, $can_try, $chname, $input, $official_sn);
             } else {
-                Log::record("{$chname} callback 系统无此订单ID:{$order_id}", Log::ERR);
+                Log::record("$chname callback 系统无此订单ID.", Log::WARING);
             }
         }
         else {
             $orgdata = json_encode($input);
-            Log::record("{$chname} 签名失败:input={$orgdata}",Log::ERR);
+            Log::record("$chname 签名失败:input=$orgdata",Log::WARING);
         }
 
         return true;
@@ -108,7 +108,7 @@ class RefillBase
         };
 
         $card_type = intval($refill_info['card_type']);
-        $chk_types = [mtopcard\ChinaMobileCard , mtopcard\ChinaUnicomCard , mtopcard\ChinaTelecomCard];
+        $chk_types = [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard];
 
         $store_id = intval($order_info['store_id']);
         if($in_exclude($store_id)) {
@@ -158,7 +158,7 @@ class RefillBase
 
     private function proc_notify($order_id, $success, $can_try, $chname, $input = [], $official_sn = false)
     {
-        $monitor = function ($order_info,$state)
+        $monitor_notify = function ($order_info,$state)
         {
             $card_type = intval($order_info['card_type']);
             if (!in_array($card_type, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
@@ -168,12 +168,8 @@ class RefillBase
             $card_no = $order_info['card_no'];
             $ch_name = $order_info['channel_name'];
 
-            $mon = new sending_monitor();
-            if($state) {
-                $mon->success($card_no,$ch_name);
-            } else {
-                $mon->fail($card_no,$ch_name);
-            }
+            $monitor = new sending_monitor();
+            $monitor->notify($card_no, $ch_name, $state);
         };
 
         $mod_order = Model('vr_order');
@@ -242,20 +238,19 @@ class RefillBase
             $period = time() - $commit_time;
 
             util::monitor_notify($chname,$spec,$card_type,$refill_info['channel_amount'],$period,$success,$commit_time,$refill_info['mch_amount']);
+            $monitor_notify($order_info,$success);
 
             if ($success) {
                 $logic_vr_order->changeOrderStateSuccess($order_id,true);
                 $tran->commit();
                 util::onOrderSuccess($refill_info,$order_info);
                 util::monitor_callback($mchid, $spec, $card_type, $refill_info['mch_amount'], $refill_info['channel_amount'], true, $order_time);
-                $monitor($order_info, true);
             }
             elseif ($can_try)
             {
                 $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,正在重试", true, true);
                 $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['is_retrying' => 1,'notify_time' => time()]);
                 $tran->commit();
-                $monitor($order_info, false);
 
                 if ($card_type == mtopcard\ThirdRefillCard) {
                     $thrid_refill = Model('thrid_refill');
@@ -285,7 +280,6 @@ class RefillBase
                 $logic_vr_order->changeOrderStateCancel($order_info, '', "{$chname}接口回调通知失败,不可重试.",true,true);
                 $tran->commit();
                 util::monitor_callback($mchid, $spec, $card_type, $refill_info['mch_amount'], 0, false, $order_time);
-                $monitor($order_info, false);
             }
 
             $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['notify_time' => time(), 'is_retrying' => 0,'notify_state' => 1]);
@@ -503,7 +497,7 @@ class RefillBase
         foreach ($providers as $provider)
         {
             $channel_name = $provider->name();
-            if ($order->is_phone() and $monitor->can_add($order->card_no(), $channel_name) == false) {
+            if ($order->is_phone() and $monitor->can_commit($order->card_no(), $channel_name) == false) {
                 continue;
             }
 
@@ -549,7 +543,7 @@ class RefillBase
                 $commit_time = time();
                 $chfilters->add_channel($channel_name,true);
                 util::monitor_commit($channel_name, $spec, $card_type, $channel_amount, $commit_time);
-                $monitor->add($card_no,$channel_name);
+                $monitor->commit($card_no,$channel_name);
 
                 $trade_no = $errmsg;
                 $refill_type = $provider->refill_type();
@@ -589,7 +583,6 @@ class RefillBase
                 if(!empty($neterr) && util::need_check($net_errno)) {
                     $mod_refill->partition(util::part_refill($order_time))->edit($order_id, ['commit_time' => time(),'neterr' => 1,'err_msg' => "neterr=$net_errno"]);
                     util::monitor_netchk($channel_name,false);
-                    $monitor->add($card_no,$channel_name);
                     return [errcode::MERCHANT_REFILL_NETERROR, "充值失败", $last_orderid, $neterr, $net_errno];
                 }
 

+ 32 - 11
helper/refill/sending_monitor.php

@@ -2,17 +2,31 @@
 
 namespace refill;
 
+use Log;
+
 //监控,手机卡号在指定的多个通道中,保持充值中唯一性
 //如果订单成功,在指定时间段里面,不能继续充值
 class sending_monitor
 {
+    private const cache_name = 'unique_sending_monitor';
     private static $stChannelNames = [];//beirui_nation
 
     private const SENDING = 1;
     private const SUCC = 2;
     private const SUCC_INTERVAL_SECS = 900;
 
-    public function can_add($card_no, $ch_name)
+    public function __construct()
+    {
+
+    }
+
+
+    public function can_commit($card_no, $ch_name)
+    {
+        Log::record("sending_monitor can_commit $card_no $ch_name",Log::DEBUG);
+        return true;
+    }
+    private function can_add($card_no, $ch_name)
     {
         if (!in_array($ch_name, sending_monitor::$stChannelNames)) {
             return true;
@@ -26,7 +40,7 @@ class sending_monitor
         [$ch_name, $time, $state] = $ret;
         if (!in_array($ch_name, sending_monitor::$stChannelNames)) {
             //如果限制的通道发生变化了,过去的数据无效处理。
-            dcache('unique_sending_monitor', 'refill-', $card_no);
+            dcache(sending_monitor::cache_name, 'refill-', $card_no);
             return true;
         }
 
@@ -46,7 +60,17 @@ class sending_monitor
         }
     }
 
-    public function add($card_no, $chname)
+    public function commit($card_no, $ch_name)
+    {
+        Log::record("sending_monitor commit $card_no $ch_name",Log::DEBUG);
+    }
+
+    public function notify($card_no, $ch_name, $fsucc)
+    {
+        Log::record("sending_monitor commit $card_no $ch_name succ=$fsucc",Log::DEBUG);
+    }
+
+    private function add($card_no, $chname)
     {
         if (!in_array($chname, sending_monitor::$stChannelNames)) {
             return;
@@ -55,7 +79,7 @@ class sending_monitor
         $this->write($card_no, $chname, sending_monitor::SENDING);
     }
 
-    public function success($card_no, $chname)
+    private function success($card_no, $chname)
     {
         if (!in_array($chname, sending_monitor::$stChannelNames)) {
             return;
@@ -64,27 +88,24 @@ class sending_monitor
         $this->write($card_no, $chname, sending_monitor::SENDING);
     }
 
-    public function fail($card_no, $chname)
+    private function fail($card_no, $chname)
     {
         if (!in_array($chname, sending_monitor::$stChannelNames)) {
             return;
         }
 
-        $name = 'unique_sending_monitor';
-        dcache($name, 'refill-', $card_no);
+        dcache(sending_monitor::cache_name, 'refill-', $card_no);
     }
 
     private function write($card_no, $chname, $state)
     {
-        $name = 'unique_sending_monitor';
         $data = [$card_no => json_encode([$chname, time(), $state])];
-        wcache($name, $data, 'refill-');
+        wcache(sending_monitor::cache_name, $data, 'refill-');
     }
 
     private function read($card_no)
     {
-        $name = 'unique_sending_monitor';
-        $ret = rcache($name, 'refill-', $card_no);
+        $ret = rcache(sending_monitor::cache_name, 'refill-', $card_no);
 
         if (empty($ret)) {
             return false;

+ 6 - 6
test/TestRefillUtil.php

@@ -44,13 +44,13 @@ class TestRefillUtil extends TestCase
 
     public function testMonitor()
     {
-        $card_no = 13911129867;
+        $card_no =  13911129867;
         $card_no1 = 13911129868;
         $monitor = new refill\sending_monitor();
-        $ret = $monitor->can_add($card_no,'beirui_nation');
-        $monitor->add($card_no,'beirui_nation');
-        $ret = $monitor->can_add($card_no1,'beirui_nation');
-        $monitor->add($card_no1,'beirui_nation');
-        $monitor->fail($card_no,'beirui_nation');
+        $ret = $monitor->can_commit($card_no,'beirui_nation');
+        $monitor->notify($card_no,'beirui_nation',true);
+        $ret = $monitor->can_commit($card_no1,'beirui_nation');
+        $monitor->commit($card_no1,'beirui_nation');
+        $monitor->notify($card_no,'beirui_nation',false);
     }
 }