|
@@ -1,14 +1,13 @@
|
|
|
<?php
|
|
|
|
|
|
-namespace refill;
|
|
|
+namespace refill\event;
|
|
|
|
|
|
use Log;
|
|
|
|
|
|
-//监控,手机卡号在指定的多个通道中,保持充值中唯一性
|
|
|
-//如果订单成功,在指定时间段里面,不能继续充值
|
|
|
-class sending_monitor
|
|
|
+# 规避相同手机卡号撞单问题解
|
|
|
+class card_crash
|
|
|
{
|
|
|
- private const cache_name = 'unique_sending_monitor';
|
|
|
+ private const cache_name = 'card_crash';
|
|
|
private static $stChannelNames = [];//beirui_nation
|
|
|
|
|
|
private const SENDING = 1;
|
|
@@ -17,18 +16,20 @@ class sending_monitor
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
|
-
|
|
|
}
|
|
|
+ public function load($cfgs)
|
|
|
+ {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
public function can_commit($card_no, $ch_name)
|
|
|
{
|
|
|
- Log::record("sending_monitor can_commit $card_no $ch_name",Log::DEBUG);
|
|
|
+ Log::record("card_crash 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)) {
|
|
|
+ if (!in_array($ch_name, card_crash::$stChannelNames)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -38,21 +39,21 @@ class sending_monitor
|
|
|
}
|
|
|
|
|
|
[$ch_name, $time, $state] = $ret;
|
|
|
- if (!in_array($ch_name, sending_monitor::$stChannelNames)) {
|
|
|
+ if (!in_array($ch_name, card_crash::$stChannelNames)) {
|
|
|
//如果限制的通道发生变化了,过去的数据无效处理。
|
|
|
- dcache(sending_monitor::cache_name, 'refill-', $card_no);
|
|
|
+ dcache(card_crash::cache_name, 'refill-', $card_no);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- if ($state === sending_monitor::SUCC)
|
|
|
+ if ($state === card_crash::SUCC)
|
|
|
{
|
|
|
- if (time() - $time >= sending_monitor::SUCC_INTERVAL_SECS) {
|
|
|
+ if (time() - $time >= card_crash::SUCC_INTERVAL_SECS) {
|
|
|
return true;
|
|
|
} else {
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
- elseif ($state === sending_monitor::SENDING) {
|
|
|
+ elseif ($state === card_crash::SENDING) {
|
|
|
return false;
|
|
|
}
|
|
|
else {
|
|
@@ -62,50 +63,50 @@ class sending_monitor
|
|
|
|
|
|
public function commit($card_no, $ch_name)
|
|
|
{
|
|
|
- Log::record("sending_monitor commit $card_no $ch_name",Log::DEBUG);
|
|
|
+ Log::record("card_crash 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);
|
|
|
+ Log::record("card_crash commit $card_no $ch_name succ=$fsucc",Log::DEBUG);
|
|
|
}
|
|
|
|
|
|
private function add($card_no, $chname)
|
|
|
{
|
|
|
- if (!in_array($chname, sending_monitor::$stChannelNames)) {
|
|
|
+ if (!in_array($chname, card_crash::$stChannelNames)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- $this->write($card_no, $chname, sending_monitor::SENDING);
|
|
|
+ $this->write($card_no, $chname, card_crash::SENDING);
|
|
|
}
|
|
|
|
|
|
private function success($card_no, $chname)
|
|
|
{
|
|
|
- if (!in_array($chname, sending_monitor::$stChannelNames)) {
|
|
|
+ if (!in_array($chname, card_crash::$stChannelNames)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- $this->write($card_no, $chname, sending_monitor::SENDING);
|
|
|
+ $this->write($card_no, $chname, card_crash::SENDING);
|
|
|
}
|
|
|
|
|
|
private function fail($card_no, $chname)
|
|
|
{
|
|
|
- if (!in_array($chname, sending_monitor::$stChannelNames)) {
|
|
|
+ if (!in_array($chname, card_crash::$stChannelNames)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- dcache(sending_monitor::cache_name, 'refill-', $card_no);
|
|
|
+ dcache(card_crash::cache_name, 'refill-', $card_no);
|
|
|
}
|
|
|
|
|
|
private function write($card_no, $chname, $state)
|
|
|
{
|
|
|
$data = [$card_no => json_encode([$chname, time(), $state])];
|
|
|
- wcache(sending_monitor::cache_name, $data, 'refill-');
|
|
|
+ wcache(card_crash::cache_name, $data, 'refill-');
|
|
|
}
|
|
|
|
|
|
private function read($card_no)
|
|
|
{
|
|
|
- $ret = rcache(sending_monitor::cache_name, 'refill-', $card_no);
|
|
|
+ $ret = rcache(card_crash::cache_name, 'refill-', $card_no);
|
|
|
|
|
|
if (empty($ret)) {
|
|
|
return false;
|