From 255841e3dc5312851be2b2066018414b1f8a024a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=92=8A?= Date: Thu, 9 Oct 2025 09:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=B5=8B=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/cron/controller/Test.php | 131 +++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 application/cron/controller/Test.php diff --git a/application/cron/controller/Test.php b/application/cron/controller/Test.php new file mode 100644 index 0000000..5152266 --- /dev/null +++ b/application/cron/controller/Test.php @@ -0,0 +1,131 @@ +blind_box_error(); + echo "\n"; + + } + + //统计盲盒转盘错误数据 + public function blind_box_error() + { + die("暂停"); + // 设置数据库查询超时时间 + Db::query("SET SESSION wait_timeout=600"); + Db::query("SET SESSION interactive_timeout=600"); + + // 使用连表查询,直接找出送给多人的数据 + echo "开始查询送给多人的数据...\n"; + + // 先查询所有有多个不同 gift_user_id 的 tid + $multipleGiftRecords = Db::name('vs_blind_box_turntable_results_log') + ->group('tid') + ->having('COUNT(DISTINCT gift_user_id) > 1') + ->field('tid, COUNT(DISTINCT gift_user_id) as user_count,gift_user_id') + ->select(); + + echo "找到 " . count($multipleGiftRecords) . " 条送给多人的记录\n"; + + // 输出详细信息 + foreach ($multipleGiftRecords as $record) { + echo "转盘ID: {$record['tid']}, 接收人数: {$record['user_count']}\n"; + // 获取该转盘的详细信息 + $turntableInfo = Db::name('vs_blind_box_turntable_log') + ->where('id', $record['tid']) + ->find(); + + if ($turntableInfo) { + echo " 开奖用户ID: {$turntableInfo['user_id']}, 礼包ID: {$turntableInfo['gift_bag_id']}\n"; + } + } + + echo "统计盲盒转盘错误数据完成\n"; + } + + //统计盲盒转盘错误数据 + public function blind_box_error1() + { + die("暂停"); + // 设置数据库查询超时时间 + Db::query("SET SESSION wait_timeout=600"); + Db::query("SET SESSION interactive_timeout=600"); + + // 分批处理数据,避免一次性加载大量数据到内存 + $batchSize = 1000; + $offset = 0; + $data_multiple = []; + $totalProcessed = 0; + + do { + // 分批获取数据 + $turntable_log = Db::name('vs_blind_box_turntable_log') + ->limit($offset, $batchSize) + ->select(); + + // 如果没有更多数据,退出循环 + if (empty($turntable_log)) { + break; + } + + foreach ($turntable_log as $key => $value) { + //查询本轮是否有多个接收礼物的人 + $turntable_results_log = Db::name('vs_blind_box_turntable_results_log') + ->where('tid', $value['id']) + ->group('gift_user_id') + ->select(); + + // 统计送给多人的数据 + if (count($turntable_results_log) > 1) { + $data_multiple[] = [ + 'turntable_id' => $value['id'], + 'recipient_count' => count($turntable_results_log), + 'data' => $value + ]; + } + + $totalProcessed++; + + // 每处理100条记录输出一次进度 + if ($totalProcessed % 100 == 0) { + echo "已处理 {$totalProcessed} 条记录...\n"; + // 每100条记录后清理内存 + gc_collect_cycles(); + } + } + + // 更新偏移量 + $offset += $batchSize; + + // 释放内存 + unset($turntable_log); + unset($turntable_results_log); + + } while ($totalProcessed <= 1400); + + echo "送给多人的数据共 " . count($data_multiple) . " 条记录\n"; + echo "统计盲盒转盘错误数据完成-共处理 " . $totalProcessed . " 条数据\n"; + + // 输出详细信息 + foreach ($data_multiple as $item) { + echo "转盘ID: {$item['turntable_id']}, 接收人数: {$item['recipient_count']}\n"; + } + } + +} \ No newline at end of file