ソースを参照

Merge branch 'rstanley' into raccount

stanley-king 1 年間 前
コミット
f2bc5a3c1a

+ 1 - 1
data/config/dev/base.ini.php

@@ -46,7 +46,7 @@ $config['gip'] 		= 0;
 $config['dbdriver'] = 'mysqli';
 $config['tablepre']	= 'lrlz_';
 
-//define('SSH_TUNEL_PROD','local');
+define('SSH_TUNEL_PROD','local');
 //define('SSH_TUNEL_PROD','xyz');
 //define('SSH_TUNEL_PROD','lingzh');
 //define('SSH_TUNEL_PROD','xyztest');

+ 5 - 0
helper/mtopcard/mtopcard.php

@@ -335,6 +335,11 @@ function is_validate($status)
 
 function valid_phone($card_no)
 {
+//    $open = new open_query();
+//    [$succ,$result] = $open->validate($card_no);
+//    if($succ) {
+//        return $result;
+//    }
     $query = new card_query();
     return $query->validate($card_no);
 }

+ 22 - 0
helper/mtopcard/open_query.php

@@ -14,7 +14,17 @@ class open_query
         $params['sign'] = $this->sign($params);
 
         $resp = http_request(self::OPENAPI_URL,$params);
+        if(empty($resp)) {
+            return [false,[]];
+        }
 
+        $resp = json_decode($resp, true);
+        if ($resp['code'] == 200) {
+            $result = $resp['data'];
+            return [true, $result];
+        } else {
+            return [false, []];
+        }
     }
 
     private function sign($input)
@@ -25,6 +35,18 @@ class open_query
         return md5($body);
     }
 
+    private function check_empty($value)
+    {
+        if (!isset($value))
+            return true;
+        if ($value === null)
+            return true;
+        if (trim($value) === "")
+            return true;
+
+        return false;
+    }
+
     private function body($params)
     {
         ksort($params);

+ 7 - 1
helper/refill/RefillBase.php

@@ -203,7 +203,6 @@ class RefillBase
             $commit_time = intval($refill_info['commit_time']);
             $period = time() - $commit_time;
 
-
             util::monitor_notify($chname,$spec,$card_type,$refill_info['channel_amount'],$period,$success,$commit_time,$refill_info['mch_amount']);
 
             if ($success) {
@@ -706,6 +705,12 @@ class RefillBase
             return [false, "无此订单"];
         }
 
+        if($refill_info['mch_notify_times'] == 0) {
+            $card_no = $refill_info['card_no'];
+            $spec = $refill_info['refill_amount'];
+            util::loop_order_dec($card_no,$spec);
+        }
+
         //手动通知,之所以不做尝试,是担心客户方状态处理不当
         if (!$manual && $refill_info['mch_notify_state'] != 0) {
             return [false, "已经通知客户方"];
@@ -715,6 +720,7 @@ class RefillBase
         $order_time = intval($refill_info['order_time']);
         $part = util::part_refill($order_time);
 
+
         if (empty($notify_url)) {
             $mod_refill->partition($part)->edit($order_id, ['mch_notify_state' => 1, 'mch_notify_times' => 0]);
             return [false, "回调地址为空"];

+ 40 - 0
helper/refill/util.php

@@ -535,6 +535,46 @@ class util
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    public static function loop_order_inc($card_no, $spec)
+    {
+        if(defined('COMPANY_NAME') && in_array(COMPANY_NAME,['ZY_COMPANY']))
+        {
+            $ins = Cache::getInstance('cacheredis');
+
+            $name = 'loop_order_check_query';
+            $key = "{$card_no}-{$spec}";
+
+            $count = $ins->hget($name, '', $key);
+            $count = intval($count);
+
+            if($count < 0) {
+                $ins->hset($name, '', [$key => 0]);
+                return false;
+            }
+            elseif($count === 0) {
+                $ins->hIncrBy($name, $key, 1);
+                return false;
+            }
+            else {
+                $ins->hIncrBy($name, $key, 1);
+                return true;
+            }
+        }
+        else {
+            return false;
+        }
+    }
+
+    public static function loop_order_dec($card_no, $spec)
+    {
+        if (defined('COMPANY_NAME') && in_array(COMPANY_NAME, ['ZY_COMPANY'])) {
+            $ins = Cache::getInstance('cacheredis');
+            $name = 'loop_order_check_query';
+            $key = "{$card_no}-{$spec}";
+            $ins->hIncrBy($name, $key, -1);
+        }
+    }
+    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     public static function push_queue_order($mchid,$mch_order,$order_state)
     {
         if(empty($mch_order)) return;

+ 20 - 3
rdispatcher/proxy.php

@@ -8,6 +8,17 @@ require_once(BASE_HELPER_PATH . '/refill/policy/transfer.php');
 
 class proxy
 {
+    private function is_loop_order(refill\order $order)
+    {
+        if($order->is_third()) {
+            return false;
+        }
+
+        $card_no = $order->card_no();
+        $spec = $order->sepc();
+        return util::loop_order_inc($card_no,$spec);
+    }
+
     private function onEerror(refill\order $order,$need_callback,$errmsg)
     {
         $mod_refill = Model('refill_order');
@@ -121,9 +132,15 @@ class proxy
         $order_time = $order->order_time();
 
         $mod_refill = Model('refill_order');
-        if($order->first_commit()) {
-            refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_SEND);
-            $mod_refill->partition(util::part_refill($order_time))->edit_detail($mchid,$mch_order,['order_state' => ORDER_STATE_SEND]);
+        if($order->first_commit())
+        {
+            if($this->is_loop_order($order)) {
+                return $this->onEerror($order, $need_callback,'疑似循环单,提前结束.');
+            }
+            else {
+                refill\util::push_queue_order($mchid,$mch_order,ORDER_STATE_SEND);
+                $mod_refill->partition(util::part_refill($order_time))->edit_detail($mchid,$mch_order,['order_state' => ORDER_STATE_SEND]);
+            }
         }
         Log::record("proxy::add times={$order->commit_times()} mch_order={$mch_order} card_no = {$order->card_no()} regin_no={$order->region_no()} org_quality={$order->org_quality()} quality={$order->cur_quality()}",Log::DEBUG);
 

+ 6 - 2
test/TestCardNo.php

@@ -23,8 +23,12 @@ class TestCardNo extends TestCase
 
     public function testQueryCardInfo()
     {
-        $query = new mtopcard\open_query();
-        $query->validate('13911129867');
+        for ($i = 0; $i < 200; $i++) {
+            $query = new mtopcard\open_query();
+            [$succ,$ret] = $query->validate('13911129867');
+            Log::record("$i succ=$succ",Log::DEBUG);
+            sleep(1);
+        }
     }
 
     public function testTransfer()

+ 15 - 0
test/TestRefillMonitor.php

@@ -24,6 +24,21 @@ class TestRefillMonitor extends TestCase
         Base::run_util();
     }
 
+    public function testLooperChecker()
+    {
+//        refill\util::loop_order_dec('13911129867',10);
+//        refill\util::loop_order_dec('13911129867',10);
+//        refill\util::loop_order_dec('13911129867',20);
+//        refill\util::loop_order_dec('13911129867',30);
+
+        refill\util::loop_order_inc('13911129867',10);
+        refill\util::loop_order_inc('13911129867',10);
+        refill\util::loop_order_dec('13911129867',10);
+        refill\util::loop_order_dec('13911129867',10);
+        refill\util::loop_order_inc('13911129867',20);
+        refill\util::loop_order_inc('13911129867',30);
+    }
+
 //docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillMonitor::testPushMessage)( .*)?$/" --test-suffix TestRefillMonitor.php /var/www/html/test
     public function testPushMessage()
     {