stanley-king 4 月之前
父节点
当前提交
14a08c1567
共有 2 个文件被更改,包括 116 次插入16 次删除
  1. 107 16
      helper/vendor/yifutongtax.php
  2. 9 0
      test/TestSSH2.php

+ 107 - 16
helper/vendor/yifutongtax.php

@@ -12,17 +12,22 @@ namespace vendor;
 
 
 use Log;
 use Log;
 use refill;
 use refill;
+use refill\util;
 
 
 class yifutongtax
 class yifutongtax
 {
 {
     const LocalPath = BASE_UPLOAD_PATH . "/YIFUTONG";
     const LocalPath = BASE_UPLOAD_PATH . "/YIFUTONG";
     public function handle()
     public function handle()
     {
     {
-//        $local_files = $this->down_files();
-        $local_files[] = static::LocalPath . "/repair.txt";
+        $local_files = $this->down_files();
+//        foreach ($local_files as $file) {
+//            Log::record("file=$file",Log::DEBUG);
+//            $this->parese_file($file);
+//        }
+
         foreach ($local_files as $file) {
         foreach ($local_files as $file) {
             Log::record("file=$file",Log::DEBUG);
             Log::record("file=$file",Log::DEBUG);
-            $this->parese_file($file);
+            $this->modify_time($file);
         }
         }
     }
     }
 
 
@@ -31,6 +36,92 @@ class yifutongtax
 
 
     }
     }
 
 
+
+    public function modify_time($file)
+    {
+        $reader = function ($file)
+        {
+            yield [0,''];
+            $handle = fopen($file, "r");
+
+            while (($line = fgets($handle)) !== false) {
+                yield [1,$line];
+            }
+
+            fclose($handle);
+            yield [2,''];
+        };
+
+        $matcher = function ($input)
+        {
+            $data = explode('|', $input);
+            $count = count($data);
+            if ($count === 8) {
+                return [
+                    'type' => 'order',
+                    'bank_card' => trim($data[0]),
+                    'mch_order' => trim($data[1]),
+                    'status' => 'SUCCESS',
+                    'amount' => 1,
+                    'quantity' => intval(trim($data[3])),
+                    'official_sn' => trim($data[4]),
+                    'card_no' => trim($data[5]),
+                    'order_time'  => strtotime(trim($data[6])),
+                    'finish_time' => strtotime(trim($data[7]))
+                ];
+            }
+            elseif($count === 2) {
+                return [
+                    'type' => 'check',
+                    'count' => intval(trim($data[0])),
+                    'total' => floatval(trim($data[1]))
+                ];
+            }
+            else {
+                return false;
+            }
+        };
+
+        $mod_refill = Model('refill_order');
+        $mod_order = Model('vr_order');
+
+        foreach ($reader($file) as $value)
+        {
+            $flag = $value[0];
+            $text = $value[1];
+
+            if ($flag === 1)
+            {
+                $val = $matcher($text);
+                if ($val === false) {
+                    continue;
+                }
+                elseif ($val['type'] == 'order')
+                {
+                    $mch_id = $this->get_mchid($val['bank_card']);
+                    $mch_order = $val['mch_order'];
+
+                    $refill_info = $mod_refill->getOrderInfo(['mchid' => $mch_id,'mch_order' => $mch_order]);
+                    if(empty($refill_info)) {
+                        Log::record("cannot find order when mchid=$mch_id mch_order=$mch_order", Log::DEBUG);
+                    }
+                    else
+                    {
+                        $order_sn = $refill_info['order_sn'];
+                        $order_time = $val['order_time'];
+                        $finish_time = $value['finish_time'];
+
+                        $mod_refill->table('refill_order')->where(['order_sn' => $order_sn])
+                            ->update(['order_time' => $order_time, 'commit_time' => $order_time, 'notify_time' => $finish_time]);
+                        $mod_order->table('vr_order')->where(['order_sn' => $order_sn])
+                            ->update(['add_time' => $order_time, 'payment_time' => $order_time, 'finnshed_time' => $finish_time]);
+
+                    }
+                }
+            }
+        }
+    }
+
     private function down_files()
     private function down_files()
     {
     {
         #北京业务的文件 sftp  221.122.92.145:10022    帐号 ylyw   密码 ylyw123
         #北京业务的文件 sftp  221.122.92.145:10022    帐号 ylyw   密码 ylyw123
@@ -196,18 +287,7 @@ class yifutongtax
             return ['mchid' => $mchid, 'buyer_id' => intval($mchinfo['admin_id'])];
             return ['mchid' => $mchid, 'buyer_id' => intval($mchinfo['admin_id'])];
         };
         };
 
 
-        $mchid_getter = function ($bank_card)
-        {
-            $card_mchids = [
-                '9629980601009991' => 10532, //同心
-                '9629980601009926' => 10530, //怡科
-                '9629980601009918' => 10530
-            ];
-
-            return $card_mchids[$bank_card] ?? false;
-        };
-
-        $order_adder = function ($file) use ($reader, $matcher, $mchid_getter, $mchinfo_getter)
+        $order_adder = function ($file) use ($reader, $matcher, $mchinfo_getter)
         {
         {
             foreach ($reader($file) as $value)
             foreach ($reader($file) as $value)
             {
             {
@@ -221,7 +301,7 @@ class yifutongtax
                     }
                     }
                     elseif ($val['type'] == 'order')
                     elseif ($val['type'] == 'order')
                     {
                     {
-                        $mchid = $mchid_getter($val['bank_card']);
+                        $mchid = $this->get_mchid($val['bank_card']);
                         if($mchid === false) {
                         if($mchid === false) {
                             Log::record("Cannot find merchant by bank_card={$val['bank_card']}", Log::DEBUG);
                             Log::record("Cannot find merchant by bank_card={$val['bank_card']}", Log::DEBUG);
                         }
                         }
@@ -262,4 +342,15 @@ class yifutongtax
             Log::record("Check is not pass.", Log::DEBUG);
             Log::record("Check is not pass.", Log::DEBUG);
         }
         }
     }
     }
+
+    private function get_mchid($bank_card)
+    {
+        $card_mchids = [
+            '9629980601009991' => 10532, //同心
+            '9629980601009926' => 10530, //怡科
+            '9629980601009918' => 10530
+        ];
+
+        return $card_mchids[$bank_card] ?? false;
+    }
 }
 }

+ 9 - 0
test/TestSSH2.php

@@ -55,6 +55,8 @@ class TestSSH2 extends TestCase
         $yft->handle();
         $yft->handle();
     }
     }
 
 
+
+
     private function down_file()
     private function down_file()
     {
     {
 
 
@@ -86,6 +88,13 @@ class TestSSH2 extends TestCase
         $yft->parese_file($file);
         $yft->parese_file($file);
     }
     }
 
 
+    public function testModifyTime()
+    {
+        $yft = new vendor\yifutongtax();
+        $file = BASE_ROOT_PATH . '/test/ssh/20241211_000110089970029.txt';
+        $yft->modify_time($file);
+    }
+
 
 
     //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestSSH2::testParase)( .*)?$/" --test-suffix TestSSH2.php /var/www/html/test
     //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestSSH2::testParase)( .*)?$/" --test-suffix TestSSH2.php /var/www/html/test