Files
yusheng-php/application/cron/controller/Test.php

191 lines
6.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\cron\controller;
use app\common\controller\Push;
use think\Cache;
use think\Db;
use Yzh\YunPay;
/*
* 定时任务,每秒执行的方法
*/
class Test
{
/* https://vespa.qxyushen.top/api/Cron/Test
* 运行函数
*/
function index()
{
// 设置脚本执行时间无限
set_time_limit(0);
echo "统计盲盒转盘错误数据\n";
// $this->blind_box_error();
$this->xlh_gift_send();
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";
}
}
public function RoomOwners()
{
$room = Db::name('vs_room')->where(['room_status' => 1,'apply_status' => 2])->select();
$arr = [];
foreach ($room as $key => $value) {
$liushui = Db::name('vs_give_gift')->where(['from_id' => $value['id'],'from' => 2])->sum('total_price');
$usercode = Db::name('user')->where(['id' => $value['user_id']])->value('user_code');
$nickname = Db::name('user')->where(['id' => $value['user_id']])->value('nickname');
$arr[] = [
'room_id' => $value['id'],
'user_id' => $value['user_id'],
'user_code' => $usercode,
'nickname' => $nickname,
'liushui' => $liushui
];
}
//房主的收益
foreach ($arr as $key => $v){
$shouyi = db::name('vs_user_money_log')->where(['user_id' => $v['user_id'],'change_type' => 18,'money_type' =>2,'createtime'=>['<',1759585380]])->sum('change_value');
$arr[$key]['shouyi'] = $shouyi;
$arr[$key]['duibi'] = $shouyi.'-'.$v['liushui']/10/10;
$arr[$key]['chazhi'] = $v['liushui']/10/10 - $shouyi;
}
var_dump($arr);
}
/*
* 巡乐会中奖后房主礼物补发放
*/
public function xlh_gift_send(){
die("暂停");
echo "开始补发巡乐会中奖后房主礼物 \n";
$xlh_list = db::name('vs_room_pan_xlh')->where(['id'=>['in',[279]]])->select();
echo "共有".count($xlh_list)."个需要发放的礼物 \n";
if(empty($xlh_list)){
echo "没有需要发放的礼物 \n";
}
foreach ($xlh_list as $key=>$value){
try{
//发放
//房主礼物落包
$res = [];
//获取房主id
$user_id = db::name('vs_room')->where(['id'=>$value['room_id']])->value('user_id');
$res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$value['homeowner_gift_id'],1,model('api/UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖后房主礼物发放-补发");
if ($res['code'] != 1) {
echo $res['msg']."\n";
continue;
}
echo "巡乐会中奖后房主礼物发放成功 房主Id".$user_id."\n";
}catch (\Exception $e){
echo $e->getMessage()."\n";
}
}
}
}