Explorar o código

add remove pdlog

stanley-king %!s(int64=3) %!d(string=hai) anos
pai
achega
640c6c7ae8
Modificáronse 3 ficheiros con 100 adicións e 2 borrados
  1. 0 2
      core/framework/function/core.php
  2. 4 0
      test/TestRedis.php
  3. 96 0
      test/TestRefillClear.php

+ 0 - 2
core/framework/function/core.php

@@ -1770,7 +1770,6 @@ function array_under_reset($array, $key, $type = 1)
  */
 function rkcache($key, $callback = false)
 {
-	$start = microtime(true);
     if (C('cache_open')) {
         $cacher = Cache::getInstance('cacheredis');
     } else {
@@ -1807,7 +1806,6 @@ function rkcache($key, $callback = false)
  */
 function wkcache($key, $value, $expire = null)
 {
-    $start = microtime(true);
     if (C('cache_open')) {
         $cacher = Cache::getInstance('cacheredis');
     } else {

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 4 - 0
test/TestRedis.php


+ 96 - 0
test/TestRefillClear.php

@@ -286,4 +286,100 @@ class TestRefillClear extends TestCase
     {
         $time = $this->earlist_orderday();
     }
+
+    //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLogSeventh)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
+    public function testLogSeventh()
+    {
+        $this->delete_log(0,strtotime('2021-08-01'));
+    }
+
+    private function delete_log($start_id,$endtime)
+    {
+        $lgid_getter = function ()
+        {
+            $lgid = rkcache('lastest_lgid');
+            $lgid = intval($lgid);
+            return $lgid;
+        };
+
+        $lgid_writter = function ($lgid)
+        {
+            wkcache('lastest_lgid',$lgid);
+        };
+
+        $finder = function ($start_id,$endtime)
+        {
+            $start = $start_id;
+            $i = 0;
+            while (true)
+            {
+                $cond = ['lg_id' => ['gt', $start],'lg_add_time' => ['lt', $endtime]];
+
+                $start = $i * 1000;
+                $items = Model()->table('pd_log')
+                    ->field('*')
+                    ->where($cond)
+                    ->order('lg_id asc')->limit("{$start},1000")->select();
+                $i++;
+
+                if(empty($items)) break;
+                foreach ($items as $item) {
+                    yield $item;
+                }
+                $start = intval($item['lg_id']);
+            }
+        };
+
+        $mod_refill = Model('refill_order');
+        $checker = function ($log) use ($mod_refill)
+        {
+            $order_sn = $log['lg_order_sn'];
+            if(empty($order_sn) && strlen($order_sn) < 16) {
+                return false;
+            }
+
+            $order = $mod_refill->table('refill_order')->field('*')->where(['order_sn' => $order_sn])->find();
+            if(empty($order)) {
+                return intval($log['lg_id']);
+            } else {
+                return false;
+            }
+        };
+
+        $pd_log = Model();
+        $delter = function ($logid) use ($pd_log)
+        {
+            if ($logid > 0) {
+                $result = $pd_log->table('pd_log')->where(['lg_id' => $logid])->delete();
+                return $result;
+            } else {
+                return false;
+            }
+        };
+
+        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//        if($start_id === 0) {
+//            $start_id = $lgid_getter();
+//        }
+
+        $logid = $start_id;
+        $logs = $finder($start_id,$endtime);
+
+        $cur_time = time();
+        $sdate = date('Y-m-d',time());
+        $filename = BASE_DATA_PATH . "/log/order/{$sdate}-{$cur_time}-pdlog.csv";
+        $fLog = fopen($filename,'w+');
+
+        foreach ($logs as $item)
+        {
+            $logid = intval($item['lg_id']);
+            $fDel = $checker($item);
+            if($fDel !== false) {
+                fputcsv($fLog,$item);
+//                $delter($logid);
+            }
+        }
+
+//        $lgid_writter($logid);
+    }
 }