Procházet zdrojové kódy

debug speed control

stanley-king před 4 roky
rodič
revize
85e86e472b

+ 1 - 0
helper/refill/RefillBase.php

@@ -327,6 +327,7 @@ class RefillBase
                 'buyer_id' => $buyer_id,
                 'quality' => $quality,'order_id' => $order_id];
 
+            util::incr_commit_pre($channel_name,$card_type,$amount,$quality);
             [$state, $errmsg,$neterr] = $provider->add($card_no, $card_type, $amount, $params);
             if ($state)
             {

+ 1 - 1
helper/refill/policy/ctl_item.php

@@ -44,7 +44,7 @@ class ctl_item
     {
         $end = time();
         for($time = $start_time; $time <= $end; $time++) {
-            $val = util::hget_commit_sec($this->mName,$this->mCardType,$this->mAmount,$this->mQuality,$time,true);
+            $val = util::hget_commit_pre_sec($this->mName,$this->mCardType,$this->mAmount,$this->mQuality,$time);
             $this->mRecords[$time] = $val;
         }
         $this->mLastReadTime = $end;

+ 100 - 91
helper/refill/util.php

@@ -17,67 +17,61 @@ class util
 {
     static function make_mobile()
     {
-        static $prefix = ["139","138","137","136","135","134","159","158","157","150","151","152",
-            "188","187","182","183","184","178","130","131","132","156","155","186","185",
-            "176","133","153","189","180","181","177"];
+        static $prefix = ["139", "138", "137", "136", "135", "134", "159", "158", "157", "150", "151", "152",
+            "188", "187", "182", "183", "184", "178", "130", "131", "132", "156", "155", "186", "185",
+            "176", "133", "153", "189", "180", "181", "177"];
 
-        $pos = mt_rand(0,count($prefix) - 1);
+        $pos = mt_rand(0, count($prefix) - 1);
         $no = "{$prefix[$pos]}" . mt_rand(10000000, 99999999);
 
         return $no;
     }
 
-    public static function can_refill($card_no,$card_type)
+    public static function can_refill($card_no, $card_type)
     {
-        if($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard)
-        {
-            $result = rcache('card_expired','',"{$card_no}");
-            if(empty($result)) {
-                wcache("card_expired",[$card_no => time()],'');
-                return [true,0];
-            }
-            else {
+        if ($card_type == mtopcard\SinopecCard || $card_type == mtopcard\PetroChinaCard) {
+            $result = rcache('card_expired', '', "{$card_no}");
+            if (empty($result)) {
+                wcache("card_expired", [$card_no => time()], '');
+                return [true, 0];
+            } else {
                 $latest = current($result);
                 $cur = time();
                 $success = ($cur - $latest) > 120;
 
-                if($success) {
-                    wcache("card_expired",[$card_no => time()],'');
+                if ($success) {
+                    wcache("card_expired", [$card_no => time()], '');
                 }
 
-                return [$success, $latest +  120 - $cur];
+                return [$success, $latest + 120 - $cur];
             }
-        }
-        else {
-            return [true,0];
+        } else {
+            return [true, 0];
         }
     }
 
-    static function read_card($card_no,$card_type = 0)
+    static function read_card($card_no, $card_type = 0)
     {
-        if(empty($card_no)) return false;
+        if (empty($card_no)) return false;
 
         $data = rcache($card_no, 'cardrefill-');
-        if(empty($data))
-        {
+        if (empty($data)) {
             $mod_topcard = Model('topcard');
             $ret = $mod_topcard->get_card($card_no);
-            if(empty($ret))
-            {
-                if($card_type === 0) {
+            if (empty($ret)) {
+                if ($card_type === 0) {
                     $card_type = mtopcard\card_type($card_no);
                 }
                 $bind_phone = util::make_mobile();
-                $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
+                $mod_topcard->add($card_no, $card_type, time(), $bind_phone);
 
                 $data['bind_phone'] = $bind_phone;
                 $data['refill_time'] = time();
                 $data['times'] = 0;
                 $data['black_card'] = 0;
 
-                wcache($card_no,$data,'cardrefill-');
-            }
-            else {
+                wcache($card_no, $data, 'cardrefill-');
+            } else {
                 $val = $ret[0];
 
                 $data['bind_phone'] = $val['bind_phone'];
@@ -88,7 +82,7 @@ class util
         }
 
         //之前没加black_card处理,这个字段不存在.
-        if(!array_key_exists('black_card',$data)) {
+        if (!array_key_exists('black_card', $data)) {
             $data['black_card'] = 0;
         }
 
@@ -99,45 +93,43 @@ class util
     {
         $card_info['times'] += 1;
         $card_info['refill_time'] = time();
-        wcache($card_no,$card_info,'cardrefill-');
+        wcache($card_no, $card_info, 'cardrefill-');
     }
 
     public static function del_card($card_no)
     {
-        dcache($card_no,'cardrefill-');
+        dcache($card_no, 'cardrefill-');
     }
 
     public static function set_black($card_no)
     {
-        if(empty($card_no)) return false;
+        if (empty($card_no)) return false;
 
         $card_info = util::read_card($card_no);
-        if(!empty($card_info)) {
+        if (!empty($card_info)) {
             $card_info['black_card'] = 1;
             $mod_topcard = Model('topcard');
             $mod_topcard->table('topcard')->where(['card_no' => $card_no])->update(['black_card' => 1]);
-            wcache($card_no,$card_info,'cardrefill-');
+            wcache($card_no, $card_info, 'cardrefill-');
 
             return true;
-        }
-        else {
+        } else {
             return false;
         }
     }
 
-    private static function black_order($order_sn,$msg)
+    private static function black_order($order_sn, $msg)
     {
-        static $errMsgs = ["只能给主卡且卡状态正常的加油卡充值","加油卡卡号错误或不支持"];
+        static $errMsgs = ["只能给主卡且卡状态正常的加油卡充值", "加油卡卡号错误或不支持"];
 
-        if(empty($msg)) return false;
+        if (empty($msg)) return false;
 
-        if(in_array($msg,$errMsgs))
-        {
+        if (in_array($msg, $errMsgs)) {
 
             $refill = Model('refill_order');
             $order = $refill->getOrderInfo(['order_sn' => $order_sn]);
 
-            if(empty($order)) return false;
+            if (empty($order)) return false;
 
             $card_no = $order['card_no'];
             return util::set_black($card_no);
@@ -146,31 +138,30 @@ class util
 
     public static function black_from_log($file_name)
     {
-        $fn = fopen($file_name,"r");
-        if(empty($fn)) {
-            Log::record("Open File {$file_name} error.",Log::ERR);
+        $fn = fopen($file_name, "r");
+        if (empty($fn)) {
+            Log::record("Open File {$file_name} error.", Log::ERR);
             return false;
-        }
-        else {
-            Log::record("{$file_name} start woring",Log::DEBUG);
+        } else {
+            Log::record("{$file_name} start woring", Log::DEBUG);
         }
 
         $errs = [];
-        while(! feof($fn))  {
+        while (!feof($fn)) {
             $line = trim(fgets($fn));
-            $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u',$line,$matches);
-            if($ret) {
+            $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u', $line, $matches);
+            if ($ret) {
                 $order_sn = $matches['order_sn'];
                 $message = $matches['message'];
 
-                self::black_order($order_sn,$message);
+                self::black_order($order_sn, $message);
 
                 $errs[$message] = empty($errs[$message]) ? 1 : $errs[$message] + 1;
             }
         }
 
         foreach ($errs as $msg => $count) {
-            Log::record("msg:{$msg} count:{$count}",Log::DEBUG);
+            Log::record("msg:{$msg} count:{$count}", Log::DEBUG);
         }
 
         fclose($fn);
@@ -178,13 +169,12 @@ class util
         return true;
     }
 
-    public static function async_add($method,$params)
+    public static function async_add($method, $params)
     {
         try {
-            QueueClient::async_push("AysncAddDispatcher",['method' => $method,'params'=> $params],10);
+            QueueClient::async_push("AysncAddDispatcher", ['method' => $method, 'params' => $params], 10);
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
         }
     }
@@ -192,32 +182,29 @@ class util
     public static function push_add($params)
     {
         try {
-            queue\DispatcherClient::instance()->push('add',$params);
+            queue\DispatcherClient::instance()->push('add', $params);
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
         }
     }
 
-    public static function push_notify($chname,$params)
+    public static function push_notify($chname, $params)
     {
         try {
-            queue\DispatcherClient::instance()->push('notify',['channel' => $chname,'params' => $params]);
+            queue\DispatcherClient::instance()->push('notify', ['channel' => $chname, 'params' => $params]);
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
         }
     }
 
-    public static function push_notify_merchant($order_id,$manual)
+    public static function push_notify_merchant($order_id, $manual)
     {
         try {
-            queue\DispatcherClient::instance()->push('notify_mechant',['order_id' => $order_id,'manual' => $manual]);
+            queue\DispatcherClient::instance()->push('notify_mechant', ['order_id' => $order_id, 'manual' => $manual]);
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
         }
     }
@@ -225,35 +212,57 @@ class util
     public static function push_query($order_id)
     {
         try {
-            queue\DispatcherClient::instance()->push('query',['order_id' => $order_id]);
+            queue\DispatcherClient::instance()->push('query', ['order_id' => $order_id]);
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
         }
     }
+
     public static function manual_success($order_id)
     {
         try {
-            queue\DispatcherClient::instance()->push('manual_success',['order_id' => $order_id]);
+            queue\DispatcherClient::instance()->push('manual_success', ['order_id' => $order_id]);
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
         }
     }
+
     public static function manual_cancel($order_id)
     {
         try {
-            queue\DispatcherClient::instance()->push('manual_cancel',['order_id' => $order_id]);
+            queue\DispatcherClient::instance()->push('manual_cancel', ['order_id' => $order_id]);
             return true;
-        }
-        catch (Exception $ex) {
+        } catch (Exception $ex) {
             return false;
         }
     }
 
     //统计提交订单数据
+    public static function incr_commit_pre($chname, $card_type, $spec, $quality)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_commit';
+        $sec = time();
+        $key_sec = "pre-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
+
+        $val = $ins->hIncrBy($name, $key_sec, 1);
+        Log::record("incr_commit_pre sec name = {$name} key={$key_sec} val={$val}", Log::DEBUG);
+    }
+
+    public static function hget_commit_pre_sec($chname, $card_type, $spec, $quality, $time_stamp)
+    {
+        $ins = Cache::getInstance('cacheredis');
+
+        $name = 'channel_monitor_commit';
+        $key_sec = "pre-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
+        $value = $ins->hGet($name, '', $key_sec);
+
+        return intval($value);
+    }
+
     public static function incr_commit($chname, $card_type, $spec, $quality, $fsuccess = true)
     {
         $ins = Cache::getInstance('cacheredis');
@@ -270,10 +279,10 @@ class util
             $key_min = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
         }
 
-        $val = $ins->hIncrBy($name,$key_sec,1);
-        Log::record("incr_commit sec name = {$name} key={$key_sec} val={$val}",Log::DEBUG);
-        $val = $ins->hIncrBy($name,$key_min,1);
-        Log::record("incr_commit min name = {$name} key={$key_min} val={$val}",Log::DEBUG);
+        $val = $ins->hIncrBy($name, $key_sec, 1);
+        Log::record("incr_commit sec name = {$name} key={$key_sec} val={$val}", Log::DEBUG);
+        $val = $ins->hIncrBy($name, $key_min, 1);
+        Log::record("incr_commit min name = {$name} key={$key_min} val={$val}", Log::DEBUG);
     }
 
     public static function hget_commit_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
@@ -286,7 +295,7 @@ class util
         } else {
             $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
         }
-        $value = $ins->hGet($name,'',$key_sec);
+        $value = $ins->hGet($name, '', $key_sec);
 
         return intval($value);
     }
@@ -303,7 +312,7 @@ class util
         } else {
             $key_sec = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
         }
-        $value = $ins->hGet($name,'',$key_sec);
+        $value = $ins->hGet($name, '', $key_sec);
 
         return intval($value);
     }
@@ -325,10 +334,10 @@ class util
             $key_min = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
         }
 
-        $val = $ins->hIncrBy($name,$key_sec,1);
-        Log::record("incr_commit sec name = {$name} key={$key_sec} val={$val}",Log::DEBUG);
-        $val = $ins->hIncrBy($name,$key_min,1);
-        Log::record("incr_commit min name = {$name} key={$key_min} val={$val}",Log::DEBUG);
+        $val = $ins->hIncrBy($name, $key_sec, 1);
+        Log::record("incr_commit sec name = {$name} key={$key_sec} val={$val}", Log::DEBUG);
+        $val = $ins->hIncrBy($name, $key_min, 1);
+        Log::record("incr_commit min name = {$name} key={$key_min} val={$val}", Log::DEBUG);
     }
 
     public static function hget_notify_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
@@ -341,7 +350,7 @@ class util
         } else {
             $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
         }
-        $value = $ins->hGet($name,'',$key_sec);
+        $value = $ins->hGet($name, '', $key_sec);
 
         return intval($value);
     }
@@ -358,7 +367,7 @@ class util
         } else {
             $key_sec = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
         }
-        $value = $ins->hGet($name,'',$key_sec);
+        $value = $ins->hGet($name, '', $key_sec);
 
         return intval($value);
     }