123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- namespace refill\event;
- use refill\order;
- use refill\util;
- use mtopcard;
- use Log;
- # 规避相同手机卡号撞单问题解
- class card_crash extends IEventRefill
- {
- use crash;
- public const cache_name = 'card_crash';
- protected $mChannels = [];
- protected $mSuccInterval = 900;
- protected $mExMchids = [];
- public function __construct()
- {
- }
- public function load($cfgs)
- {
- $channels = $cfgs['channels'] ?? '';
- Log::record("card_crash load channels={$cfgs['channels']} succ_interval={$cfgs['succ_interval']}.", Log::DEBUG);
- $channels = explode(',',$channels);
- $this->mChannels = [];
- foreach ($channels as $item) {
- $this->mChannels[] = trim($item);
- }
- $this->mSuccInterval = intval($cfgs['succ_interval'] ?? 900);
- //读取撞单排除机构
- $mchids = $cfgs['mchids'] ?? '';
- $mchids = explode(',',$mchids);
- $this->mExMchids = [];
- foreach ($mchids as $item)
- {
- $mchid = intval($item);
- if($mchid > 0) {
- $this->mExMchids[] = $mchid;
- }
- }
- }
- public function onBeforeSubmit(order $order) : bool
- {
- if(!$order->is_phone()) {
- return true;
- }
- $card_no = $order->card_no();
- $ret = $this->can_submit($card_no);
- if(!$ret)
- {
- $mchid = $order->mchid();
- $mch_order = $order->mch_order();
- $mod_refill = Model('refill_order');
- $val = $mod_refill->get_detail($mchid, $mch_order);
- if(!empty($val))
- {
- $params = json_decode($val['params'],true);
- //在排除队列,这时可以提单,后面需要尽快失败返回.
- if (in_array($mchid, $this->mExMchids)) {
- // util::async_add_zero($params, 5);
- // Log::record("card_crash mchid=$mchid,mch_order $mch_order add zero order.", Log::DEBUG);
- return true;
- } else {
- util::async_add($params, 60);
- Log::record("card_crash mchid=$mchid,mch_order $mch_order sleep one minute.", Log::DEBUG);
- }
- return false;
- }
- }
- return true;
- }
- public function onSubmit(order $order)
- {
- if(!$order->is_phone()) {
- return;
- }
- $card_no = $order->card_no();
- $oid = $order->unique_id();
- $this->submit($card_no,$oid);
- }
- public function onBeforeCommit(order $order, $ch_name): bool
- {
- if(!$order->is_phone()) {
- return true;
- }
- $mchid = $order->mchid();
- $card_no = $order->card_no();
- $oid = $order->unique_id();
- return $this->can_commit($card_no, $oid, $ch_name);
- }
- public function onCommit(order $order, $ch_name)
- {
- if(!$order->is_phone()) {
- return;
- }
- $card_no = $order->card_no();
- $oid = $order->unique_id();
- $this->commit($card_no, $oid, $ch_name);
- }
- public function onNeterror(order $order, $ch_name)
- {
- if(!$order->is_phone()) {
- return;
- }
- $card_no = $order->card_no();
- $oid = $order->unique_id();
- $this->submit($card_no,$oid);
- }
- public function onNotify($refill_info, $order_info, $success)
- {
- $card_type = intval($refill_info['card_type']);
- if (!in_array($card_type, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
- return;
- }
- $oid = "{$refill_info['mchid']}-{$refill_info['mch_order']}";
- $ch_name = $refill_info['channel_name'];
- $card_no = $refill_info['card_no'];
- $this->notify($card_no, $oid, $ch_name, $success);
- }
- public function onComplete($refill_info, $order_info, $success)
- {
- $card_type = intval($refill_info['card_type']);
- if (!in_array($card_type, [mtopcard\ChinaMobileCard, mtopcard\ChinaUnicomCard, mtopcard\ChinaTelecomCard])) {
- return;
- }
- $oid = "{$refill_info['mchid']}-{$refill_info['mch_order']}";
- $ch_name = $refill_info['channel_name'];
- $card_no = $refill_info['card_no'];
- $this->complete($card_no, $oid, $ch_name, $success);
- }
- }
|