|
@@ -2,15 +2,16 @@
|
|
|
|
|
|
namespace refill\event;
|
|
|
|
|
|
-use Log;
|
|
|
use refill\order;
|
|
|
+use refill\util;
|
|
|
|
|
|
# 规避相同手机卡号撞单问题解
|
|
|
-class card_crash implements IEverntRefill
|
|
|
+class card_crash implements IEventRefill
|
|
|
{
|
|
|
- private const cache_name = 'card_crash';
|
|
|
- private $mChannels = [];
|
|
|
- private $mSuccInterval = 900;
|
|
|
+ use crash;
|
|
|
+ public const cache_name = 'card_crash';
|
|
|
+ protected $mChannels = [];
|
|
|
+ protected $mSuccInterval = 900;
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
@@ -28,132 +29,77 @@ class card_crash implements IEverntRefill
|
|
|
$this->mSuccInterval = intval($cfgs['succ_interval'] ?? 900);
|
|
|
}
|
|
|
|
|
|
- public static function onBeforeSubmit(order $order)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- public function onSubmit(order $order)
|
|
|
+ public function onBeforeSubmit(order $order)
|
|
|
{
|
|
|
$card_no = $order->card_no();
|
|
|
- $oid = $order->unique_id();
|
|
|
- $org_val = [
|
|
|
- 'sc' => '', //succ ch_name
|
|
|
- 'st' => 0, //succ time
|
|
|
- 'cc' => [] //正在提交的通道
|
|
|
- ];
|
|
|
-
|
|
|
- $val = $this->read($card_no) ?? $org_val;
|
|
|
- $val['cc'][$oid] = '';
|
|
|
- $this->write($card_no,$val);
|
|
|
- }
|
|
|
-
|
|
|
+ $ret = $this->can_submit($card_no);
|
|
|
|
|
|
+ if(!$ret)
|
|
|
+ {
|
|
|
+ $mchid = $order->mchid();
|
|
|
+ $mch_order = $order->mch_order();
|
|
|
|
|
|
- public function onBeforeCommit(order $order, $ch_name): bool
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- public function onCommit(order $order, $ch_name)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public function onNeterror(order $order, $ch_name)
|
|
|
- {
|
|
|
- }
|
|
|
-
|
|
|
- public function onNotify($refill_info, $order_info, $success)
|
|
|
- {
|
|
|
- $uid = "{$refill_info['mchid']}-{$refill_info['mch_order']}";
|
|
|
- $ch_name = $refill_info['channel_name'];
|
|
|
-
|
|
|
- Log::record("onEvent notify uid=$uid channel=$ch_name success=$success", Log::DEBUG);
|
|
|
- }
|
|
|
+ $mod_refill = Model('refill_order');
|
|
|
+ $val = $mod_refill->get_detail($mchid,$mch_order);
|
|
|
|
|
|
- public function onComplete($refill_info, $order_info, $success)
|
|
|
- {
|
|
|
- $uid = "{$refill_info['mchid']}-{$refill_info['mch_order']}";
|
|
|
- $ch_name = $refill_info['channel_name'];
|
|
|
+ if(!empty($val)) {
|
|
|
+ $params = json_decode($val['params'],true);
|
|
|
+ util::async_add($params, 60);
|
|
|
|
|
|
- Log::record("onEvent complete uid=$uid channel=$ch_name success=$success", Log::DEBUG);
|
|
|
- }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- public function can_commit($card_no, $ch_name)
|
|
|
- {
|
|
|
- Log::record("card_crash can_commit $card_no $ch_name",Log::DEBUG);
|
|
|
return true;
|
|
|
}
|
|
|
- private function can_add($card_no, $ch_name)
|
|
|
+ public function onSubmit(order $order)
|
|
|
{
|
|
|
- if (!in_array($ch_name, card_crash::$stChannelNames)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- $ret = $this->read($card_no);
|
|
|
- if ($ret === false) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- [$ch_name, $time, $state] = $ret;
|
|
|
- if (!in_array($ch_name, card_crash::$stChannelNames)) {
|
|
|
- //如果限制的通道发生变化了,过去的数据无效处理。
|
|
|
- dcache(card_crash::cache_name, 'refill-', $card_no);
|
|
|
- return true;
|
|
|
- }
|
|
|
+ $card_no = $order->card_no();
|
|
|
+ $oid = $order->unique_id();
|
|
|
|
|
|
- if ($state === card_crash::SUCC)
|
|
|
- {
|
|
|
- if (time() - $time >= card_crash::SUCC_INTERVAL_SECS) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- elseif ($state === card_crash::SENDING) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- else {
|
|
|
- return true;
|
|
|
- }
|
|
|
+ $this->submit($card_no,$oid);
|
|
|
}
|
|
|
|
|
|
- public function commit($card_no, $ch_name)
|
|
|
- {
|
|
|
- Log::record("card_crash commit $card_no $ch_name",Log::DEBUG);
|
|
|
- }
|
|
|
|
|
|
- public function notify($card_no, $ch_name, $fsucc)
|
|
|
+ public function onBeforeCommit(order $order, $ch_name): bool
|
|
|
{
|
|
|
- Log::record("card_crash commit $card_no $ch_name succ=$fsucc",Log::DEBUG);
|
|
|
+ $card_no = $order->card_no();
|
|
|
+ $oid = $order->unique_id();
|
|
|
+
|
|
|
+ return $this->can_commit($card_no, $oid, $ch_name);
|
|
|
}
|
|
|
|
|
|
- private function add($card_no, $chname)
|
|
|
+ public function onCommit(order $order, $ch_name)
|
|
|
{
|
|
|
+ $card_no = $order->card_no();
|
|
|
+ $oid = $order->unique_id();
|
|
|
|
|
|
+ $this->commit($card_no, $oid, $ch_name);
|
|
|
}
|
|
|
|
|
|
- private function success($card_no, $chname)
|
|
|
+ public function onNeterror(order $order, $ch_name)
|
|
|
{
|
|
|
+ $card_no = $order->card_no();
|
|
|
+ $oid = $order->unique_id();
|
|
|
|
|
|
+ $this->submit($card_no,$oid);
|
|
|
}
|
|
|
|
|
|
- private function fail($card_no, $chname)
|
|
|
+ public function onNotify($refill_info, $order_info, $success)
|
|
|
{
|
|
|
- }
|
|
|
+ $oid = "{$refill_info['mchid']}-{$refill_info['mch_order']}";
|
|
|
+ $ch_name = $refill_info['channel_name'];
|
|
|
+ $card_no = $refill_info['card_no'];
|
|
|
|
|
|
- private function write($card_no, $val)
|
|
|
- {
|
|
|
- $data = [$card_no => json_encode($val)];
|
|
|
- wcache(card_crash::cache_name, $data, 'refill-');
|
|
|
+ $this->notify($card_no, $oid, $ch_name, $success);
|
|
|
}
|
|
|
|
|
|
- private function read($card_no)
|
|
|
+ public function onComplete($refill_info, $order_info, $success)
|
|
|
{
|
|
|
- $ret = rcache(card_crash::cache_name, 'refill-', $card_no);
|
|
|
- if (empty($ret)) {
|
|
|
- return false;
|
|
|
- }
|
|
|
+ $oid = "{$refill_info['mchid']}-{$refill_info['mch_order']}";
|
|
|
+ $ch_name = $refill_info['channel_name'];
|
|
|
+ $card_no = $refill_info['card_no'];
|
|
|
|
|
|
- $values = $ret[$card_no];
|
|
|
- return json_decode($values, true);
|
|
|
+ $this->complete($card_no, $oid, $ch_name, $success);
|
|
|
}
|
|
|
}
|