提交测试脚本
This commit is contained in:
131
application/cron/controller/Test.php
Normal file
131
application/cron/controller/Test.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace app\cron\controller;
|
||||
|
||||
use think\Db;
|
||||
use Yzh\YunPay;
|
||||
|
||||
/*
|
||||
* 定时任务,每秒执行的方法
|
||||
*/
|
||||
class Test
|
||||
{
|
||||
/*
|
||||
* 运行函数
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
// 设置脚本执行时间无限
|
||||
set_time_limit(0);
|
||||
echo "统计盲盒转盘错误数据\n";
|
||||
$this->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";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user