|
@@ -11,6 +11,7 @@ require_once(BASE_CORE_PATH . '/lrlz.php');
|
|
require_once(BASE_ROOT_PATH . '/fooder.php');
|
|
require_once(BASE_ROOT_PATH . '/fooder.php');
|
|
|
|
|
|
require_once(BASE_HELPER_PATH . '/refill/ops/order_clear.php');
|
|
require_once(BASE_HELPER_PATH . '/refill/ops/order_clear.php');
|
|
|
|
+require_once(BASE_HELPER_PATH . '/refill/ops/pdlog_clear.php');
|
|
|
|
|
|
class TestRefillClear extends TestCase
|
|
class TestRefillClear extends TestCase
|
|
{
|
|
{
|
|
@@ -28,6 +29,15 @@ class TestRefillClear extends TestCase
|
|
$clear->clear($start_date,$end_date);
|
|
$clear->clear($start_date,$end_date);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public function testPdlogClear()
|
|
|
|
+ {
|
|
|
|
+ $start_date = strtotime('2021-09-11');
|
|
|
|
+ $end_date = strtotime('2021-09-13');
|
|
|
|
+
|
|
|
|
+ $clear = new refill\pdlog_clear();
|
|
|
|
+ $clear->clear($start_date,$end_date);
|
|
|
|
+ }
|
|
|
|
+
|
|
//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testClearFirstDay)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
//docker-compose run phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testClearFirstDay)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
public function testClearFirstDay()
|
|
public function testClearFirstDay()
|
|
{
|
|
{
|
|
@@ -81,314 +91,15 @@ class TestRefillClear extends TestCase
|
|
/// 以下代码为清除pdlog
|
|
/// 以下代码为清除pdlog
|
|
// const pdlog_table_name = 'pd_log_bak';
|
|
// const pdlog_table_name = 'pd_log_bak';
|
|
const pdlog_table_name = 'pd_log';
|
|
const pdlog_table_name = 'pd_log';
|
|
- //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(74224997,strtotime('2021-09-01'));
|
|
|
|
- }
|
|
|
|
|
|
|
|
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLogNine)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
|
|
- public function testLogNine()
|
|
|
|
- {
|
|
|
|
- $this->delete_log(127113184,strtotime('2021-10-01'));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLogTen)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
|
|
- public function testLogTen()
|
|
|
|
- {
|
|
|
|
- $this->delete_log(306132968,strtotime('2021-11-01'));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLogEleven)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
|
|
- public function testLogEleven()
|
|
|
|
- {
|
|
|
|
- $this->delete_log(619026072,strtotime('2021-12-01'));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLogDec20)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
|
|
- public function testLogDec20()
|
|
|
|
- {
|
|
|
|
- $this->delete_log(1079138574,strtotime('2021-12-20'));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLogDec29)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
|
|
- public function testLogDec29()
|
|
|
|
- {
|
|
|
|
- $this->delete_log(2147483648,strtotime('2022-01-01'));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLog202201)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
|
|
- public function testLog202201()
|
|
|
|
- {
|
|
|
|
- $this->delete_log(3423291013,strtotime('2022-02-01'));
|
|
|
|
- }
|
|
|
|
|
|
|
|
//docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLog202202)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
//docker-compose run -d phpcli php /var/www/html/phpunit-9.2.5.phar --filter "/(TestRefillClear::testLog202202)( .*)?$/" --test-suffix TestRefillClear.php /var/www/html/test
|
|
public function testLog202202()
|
|
public function testLog202202()
|
|
{
|
|
{
|
|
- $this->delete_log(4749026118,strtotime('2022-02-18'));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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);
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $maxid_getter = function () {
|
|
|
|
- $items = Model()->table(self::pdlog_table_name)->field('max(lg_id) as maxid')->select();
|
|
|
|
- return intval($items['0']['maxid']);
|
|
|
|
- };
|
|
|
|
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
- $mod_refill = Model('refill_order');
|
|
|
|
- $pd_log = Model();
|
|
|
|
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
- /// 一条一条的删除日志
|
|
|
|
- $finder = function ($start_id, $endtime, $maxid)
|
|
|
|
- {
|
|
|
|
- $start = $start_id;
|
|
|
|
- $quit = false;
|
|
|
|
-
|
|
|
|
- while (!$quit)
|
|
|
|
- {
|
|
|
|
- if($start >= $maxid) break;
|
|
|
|
-
|
|
|
|
- $end = $start + 1000;
|
|
|
|
- $cond = ['lg_id' => [['egt', $start], ['lt',$end], 'and']];
|
|
|
|
-
|
|
|
|
- $items = Model()->table(self::pdlog_table_name)
|
|
|
|
- ->field('*')
|
|
|
|
- ->where($cond)
|
|
|
|
- ->order('lg_id asc')->select();
|
|
|
|
-
|
|
|
|
- foreach ($items as $item)
|
|
|
|
- {
|
|
|
|
- $add_time = intval($item['lg_add_time']);
|
|
|
|
- if($add_time >= $endtime){
|
|
|
|
- $quit = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- yield $item;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $start = $end;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $checker = function ($log) use ($mod_refill)
|
|
|
|
- {
|
|
|
|
- $sdate = date('Y-m-d H:i:s',$log['lg_add_time']);
|
|
|
|
- Log::record("{$sdate} lgid={$log['lg_id']},type={$log['lg_type']},sn={$log['lg_order_sn']}",Log::DEBUG);
|
|
|
|
-
|
|
|
|
- $logid = intval($log['lg_id']);
|
|
|
|
- $lgtype = $log['lg_type'];
|
|
|
|
- if (in_array($lgtype, ['bonus_add_money','hand_out_bonus', 'bonus_refund', 'bonus_expire'])) {
|
|
|
|
- return [$logid,false];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $order_sn = $log['lg_order_sn'];
|
|
|
|
- if(empty($order_sn) && strlen($order_sn) < 16) {
|
|
|
|
- return [false,false];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!in_array($lgtype, ['order_pay', 'order_freeze', 'order_cancel'])) {
|
|
|
|
- return [false,false];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $order = $mod_refill->table('refill_order')->field('*')->where(['order_sn' => $order_sn])->master(true)->find();
|
|
|
|
- if(empty($order)) {
|
|
|
|
- return [$logid,true];
|
|
|
|
- } else {
|
|
|
|
- return [false,false];
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $delter = function ($logid) use ($pd_log)
|
|
|
|
- {
|
|
|
|
- if ($logid > 0) {
|
|
|
|
- $result = $pd_log->table(self::pdlog_table_name)->where(['lg_id' => $logid])->delete();
|
|
|
|
- return $result;
|
|
|
|
- } else {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $onebyone_handler = function ($start_id,$endtime,$maxid,$fLog) use($finder,$checker,$delter)
|
|
|
|
- {
|
|
|
|
- $logs = $finder($start_id,$endtime,$maxid);
|
|
|
|
- foreach ($logs as $item)
|
|
|
|
- {
|
|
|
|
- [$logid,$save] = $checker($item);
|
|
|
|
- if($logid !== false) {
|
|
|
|
- $delter($logid);
|
|
|
|
- }
|
|
|
|
- if($save) {
|
|
|
|
- fputcsv($fLog,$item);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
- /// 一批一批的删除日志
|
|
|
|
- $batch_finder = function ($start_id, $endtime, $maxid)
|
|
|
|
- {
|
|
|
|
- $start = $start_id;
|
|
|
|
- $quit = false;
|
|
|
|
- while (!$quit)
|
|
|
|
- {
|
|
|
|
- if($start >= $maxid) break;
|
|
|
|
-
|
|
|
|
- $end = $start + 200;
|
|
|
|
- $cond = ['lg_id' => [['egt', $start], ['lt',$end], 'and']];
|
|
|
|
-
|
|
|
|
- $items = Model()->table(self::pdlog_table_name)
|
|
|
|
- ->field('*')
|
|
|
|
- ->where($cond)
|
|
|
|
- ->order('lg_id asc')->select();
|
|
|
|
-
|
|
|
|
- $logs = [];
|
|
|
|
- foreach ($items as $item)
|
|
|
|
- {
|
|
|
|
- $add_time = intval($item['lg_add_time']);
|
|
|
|
- if($add_time >= $endtime){
|
|
|
|
- $quit = true;
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
- $logs[] = $item;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(!empty($logs)) {
|
|
|
|
- yield $logs;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $start = $end;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- //return:1,可以直接删除,不需要存储; 2,不可以删除,3,检查后可以删除
|
|
|
|
- $batch_check_log = function ($log)
|
|
|
|
- {
|
|
|
|
- $sdate = date('Y-m-d H:i:s',$log['lg_add_time']);
|
|
|
|
- Log::record("{$sdate} lgid={$log['lg_id']},type={$log['lg_type']},sn={$log['lg_order_sn']}",Log::DEBUG);
|
|
|
|
-
|
|
|
|
- $logid = intval($log['lg_id']);
|
|
|
|
- $order_sn = $log['lg_order_sn'];
|
|
|
|
- $lgtype = $log['lg_type'];
|
|
|
|
-
|
|
|
|
- if (in_array($lgtype, ['bonus_add_money','hand_out_bonus', 'bonus_refund', 'bonus_expire'])) {
|
|
|
|
- return [1,$logid,$order_sn];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(empty($order_sn) && strlen($order_sn) < 16) {
|
|
|
|
- return [2,false,false];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (!in_array($lgtype, ['order_pay', 'order_freeze', 'order_cancel'])) {
|
|
|
|
- return [2,false,false];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return [3,$logid,$order_sn];
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $batch_checker = function ($logs) use ($mod_refill,$batch_check_log)
|
|
|
|
- {
|
|
|
|
- $del_ids = [];
|
|
|
|
- $savers = [];
|
|
|
|
-
|
|
|
|
- $exist_logs = [];
|
|
|
|
- $sns = [];
|
|
|
|
- foreach ($logs as $log)
|
|
|
|
- {
|
|
|
|
- [$type,$logid,$order_sn] = $batch_check_log($log);
|
|
|
|
- if($type === 1) {
|
|
|
|
- $del_ids[] = $logid;
|
|
|
|
- }
|
|
|
|
- elseif($type === 3) {
|
|
|
|
- $exist_logs[$logid] = $log;
|
|
|
|
- $sns[] = $order_sn;
|
|
|
|
- }
|
|
|
|
- else {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if(!empty($sns))
|
|
|
|
- {
|
|
|
|
- $sns = array_unique($sns);
|
|
|
|
- $orders = $mod_refill->table('refill_order')->field('order_sn')->where(['order_sn' => ['in', $sns]])->master(true)->select();
|
|
|
|
-
|
|
|
|
- $sn_sns = [];
|
|
|
|
- foreach ($orders as $item) {
|
|
|
|
- $sn = $item['order_sn'];
|
|
|
|
- $sn_sns[$sn] = $sn;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- foreach ($exist_logs as $logid => $log)
|
|
|
|
- {
|
|
|
|
- $sn = $log['lg_order_sn'];
|
|
|
|
- if(!array_key_exists($sn,$sn_sns)) {
|
|
|
|
- $del_ids[] = $logid;
|
|
|
|
- $savers[] = $log;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return [$del_ids,$savers];
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $batch_delter = function ($logids) use ($pd_log)
|
|
|
|
- {
|
|
|
|
- if (!empty($logids)) {
|
|
|
|
- $result = $pd_log->table(self::pdlog_table_name)->where(['lg_id' => ['in',$logids]])->delete();
|
|
|
|
- return $result;
|
|
|
|
- } else {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $batch_handler = function ($start_id,$endtime,$maxid,$fLog) use($batch_finder,$batch_checker,$batch_delter)
|
|
|
|
- {
|
|
|
|
- $lgid = $start_id;
|
|
|
|
- $logs = $batch_finder($start_id,$endtime,$maxid);
|
|
|
|
- foreach ($logs as $batch)
|
|
|
|
- {
|
|
|
|
- [$logids,$savers] = $batch_checker($batch);
|
|
|
|
-
|
|
|
|
- $batch_delter($logids);
|
|
|
|
- foreach ($savers as $item) {
|
|
|
|
- fputcsv($fLog,$item);
|
|
|
|
- }
|
|
|
|
- $lgid = max($logids);
|
|
|
|
- }
|
|
|
|
- return $lgid;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
- if($start_id === 0) {
|
|
|
|
- $start_id = $lgid_getter();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- $cur_time = time();
|
|
|
|
- $sdate = date('Y-m-d',time());
|
|
|
|
- $filename = BASE_DATA_PATH . "/log/pdlog/{$sdate}-{$cur_time}.csv";
|
|
|
|
- $fLog = fopen($filename,'w+');
|
|
|
|
-
|
|
|
|
- $maxid = $maxid_getter();
|
|
|
|
-
|
|
|
|
-// $onebyone_handler($start_id,$endtime,$maxid,$fLog);
|
|
|
|
- $logid = $batch_handler($start_id,$endtime,$maxid,$fLog);
|
|
|
|
- $lgid_writter($logid);
|
|
|
|
|
|
+ $start_date = strtotime('2022-02-18');
|
|
|
|
+ $end_date = strtotime('2022-02-19');
|
|
|
|
+ $clear = new refill\pdlog_clear();
|
|
|
|
+ $clear->clear($start_date,$end_date);
|
|
}
|
|
}
|
|
|
|
|
|
public function testImport()
|
|
public function testImport()
|