|
@@ -11,46 +11,67 @@ use Log;
|
|
|
use Exception;
|
|
|
use Cache;
|
|
|
use QueueClient;
|
|
|
+use function PHPUnit\Framework\returnArgument;
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
- static function read_card($card_no,$card_type = 0)
|
|
|
+ public static function can_refill($card_no, $card_type)
|
|
|
{
|
|
|
- if(empty($card_no)) return false;
|
|
|
+ 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()], '');
|
|
|
+ }
|
|
|
+
|
|
|
+ return [$success, $latest + 120 - $cur];
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return [true, 0];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static function read_card($card_no, $card_type = 0)
|
|
|
+ {
|
|
|
+ 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'];
|
|
@@ -61,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;
|
|
|
}
|
|
|
|
|
@@ -72,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);
|
|
@@ -119,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);
|
|
@@ -151,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;
|
|
|
}
|
|
|
}
|
|
@@ -165,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;
|
|
|
}
|
|
|
}
|
|
@@ -198,56 +212,158 @@ 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_order($chname,$card_type,$amout,$quality)
|
|
|
+ //统计提交订单数据
|
|
|
+ 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}";
|
|
|
+
|
|
|
+ $ins->hIncrBy($name, $key_sec, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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');
|
|
|
|
|
|
+ $name = 'channel_monitor_commit';
|
|
|
$sec = time();
|
|
|
$min = $sec - $sec % 60;
|
|
|
|
|
|
- $key = "storge-push-{$chname}-{$quality}-{$card_type}-{$amout}-{$min}";
|
|
|
- $ins->incr($key);
|
|
|
+ if ($fsuccess) {
|
|
|
+ $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
|
|
|
+ $key_min = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ } else {
|
|
|
+ $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
|
|
|
+ $key_min = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ }
|
|
|
|
|
|
- $key = "speed-{$chname}-{$quality}-{$card_type}-{$amout}-{$sec}";
|
|
|
- $ins->incr($key);
|
|
|
+ $ins->hIncrBy($name, $key_sec, 1);
|
|
|
+ $ins->hIncrBy($name, $key_min, 1);
|
|
|
}
|
|
|
|
|
|
- public static function decr_order($chname,$card_type,$amout,$quality)
|
|
|
+ public static function hget_commit_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
|
|
|
{
|
|
|
$ins = Cache::getInstance('cacheredis');
|
|
|
|
|
|
+ $name = 'channel_monitor_commit';
|
|
|
+ if ($fsuccess) {
|
|
|
+ $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
|
|
|
+ } else {
|
|
|
+ $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
|
|
|
+ }
|
|
|
+ $value = $ins->hget($name, '', $key_sec);
|
|
|
+
|
|
|
+ return intval($value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function hget_commit_min($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
|
|
|
+ {
|
|
|
+ $ins = Cache::getInstance('cacheredis');
|
|
|
+
|
|
|
+ $name = 'channel_monitor_commit';
|
|
|
+ $min = $time_stamp - $time_stamp % 60;
|
|
|
+
|
|
|
+ if ($fsuccess) {
|
|
|
+ $key_sec = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ } else {
|
|
|
+ $key_sec = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ }
|
|
|
+ $value = $ins->hget($name, '', $key_sec);
|
|
|
+
|
|
|
+ return intval($value);
|
|
|
+ }
|
|
|
+
|
|
|
+ //统计回调通知数据
|
|
|
+ public static function incr_notify($chname, $card_type, $spec, $quality, $fsuccess = true)
|
|
|
+ {
|
|
|
+ $ins = Cache::getInstance('cacheredis');
|
|
|
+
|
|
|
+ $name = 'channel_monitor_notify';
|
|
|
$sec = time();
|
|
|
$min = $sec - $sec % 60;
|
|
|
|
|
|
- $key = "storge-pop-{$chname}-{$quality}-{$card_type}-{$amout}-{$min}";
|
|
|
- $ins->decr($key);
|
|
|
+ if ($fsuccess) {
|
|
|
+ $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
|
|
|
+ $key_min = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ } else {
|
|
|
+ $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$sec}";
|
|
|
+ $key_min = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ }
|
|
|
+
|
|
|
+ $ins->hIncrBy($name, $key_sec, 1);
|
|
|
+ $ins->hIncrBy($name, $key_min, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function hget_notify_sec($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
|
|
|
+ {
|
|
|
+ $ins = Cache::getInstance('cacheredis');
|
|
|
+
|
|
|
+ $name = 'channel_monitor_notify';
|
|
|
+ if ($fsuccess) {
|
|
|
+ $key_sec = "succ-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
|
|
|
+ } else {
|
|
|
+ $key_sec = "fail-{$chname}-{$quality}-{$card_type}-{$spec}-{$time_stamp}";
|
|
|
+ }
|
|
|
+ $value = $ins->hget($name, '', $key_sec);
|
|
|
+
|
|
|
+ return intval($value);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function hget_notify_min($chname, $card_type, $spec, $quality, $time_stamp, $fsuccess = true)
|
|
|
+ {
|
|
|
+ $ins = Cache::getInstance('cacheredis');
|
|
|
+
|
|
|
+ $name = 'channel_monitor_notify';
|
|
|
+ $min = $time_stamp - $time_stamp % 60;
|
|
|
+
|
|
|
+ if ($fsuccess) {
|
|
|
+ $key_sec = "succm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ } else {
|
|
|
+ $key_sec = "failm-{$chname}-{$quality}-{$card_type}-{$spec}-{$min}";
|
|
|
+ }
|
|
|
+ $value = $ins->hget($name, '', $key_sec);
|
|
|
+
|
|
|
+ return intval($value);
|
|
|
}
|
|
|
}
|