This commit is contained in:
2025-10-20 10:02:41 +08:00
parent a4858d47fc
commit dc0a271adf
2805 changed files with 451240 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
<?php
namespace app\cron\controller;
use think\Db;
class FriendEnd
{
/*
* 运行函数
*/
function index()
{
echo "清除交友房过期未结束数据开始:\n";
$this->clearFriendingEndRoom();//清除交友房过期未结束数据
echo "清除结束 \n";
echo "清除私密小屋过期数据开始:\n";
$this->clear_room_end();//清除私密小屋过期数据
echo "清除私密小屋过期数据结束 \n";
}
//清除交友房过期未结束数据
public function clearFriendingEndRoom()
{
//清除交友房过期数据
$room_list = db::name('vs_room')->where(['type_id'=>7])->whereIn('step', [2,3])
->field(['id','step'])->select();
if(!empty($room_list)){
foreach ($room_list as $room) {
//查询交友信息
$friending_info = db::name('vs_user_friending')->where('room_id', $room['id'])->where('status', 1)->order('id', 'desc')->find();
if($friending_info){
//判断结束时间是否到期
if($friending_info['end_time'] <= time() || $room['step'] == 3){
model('Friend')->end_friend(0,$room['id'],$friending_info['id'],1);
}
}
}
}
}
//清除私密小屋过期数据
public function clear_room_end()
{
$room_list = db::name('vs_room_cp_movie')->where(['status' => 1,'type'=>1,'time_day' =>['<',time()]])->select();
if(!empty($room_list)){
foreach ($room_list as $room) {
model('Friend')->outRoom(0,$room['room_id']);
}
}
}
}

View File

@@ -0,0 +1,405 @@
<?php
namespace app\cron\controller;
use app\common\controller\Push;
use think\Db;
use think\Log;
class RoomHourRanking
{
/*
* 运行函数
*/
function index()
{
echo "小时榜 开始发礼物:\n";
$this->send_gift();//小时榜 送礼物
echo "发礼物结束 \n";
}
public function send_gift()
{
//获取上一个小时的开始时间和结束时间
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
$end_time = strtotime(date('Y-m-d H:00:00'));
echo "开始时间:" .$start_time."\n";
echo "结束时间:" .$end_time."\n";
//当前小时的前一个小时24小时计时法0-23
$pre_hour = date('H', strtotime('-1 hour'));
echo "上个时间段:" .$pre_hour."\n";
$is_open_time = db::name('vs_hour_ranking_config')->where('id', 1)->value('open_time');
if ($is_open_time == 0) {
echo "未开启时间段:" .$is_open_time."\n";
return;
}
//是否全局飘瓶
$is_public_server = db::name('vs_hour_ranking_config')->where('id', 1)->value('is_public_server');
if ($is_public_server == 1) {
//全局飘瓶时间段
$xlh_time_range = db::name('vs_hour_ranking_config')->where('id', 1)->value('broadcast_times');
if($xlh_time_range){
if($xlh_time_range == 25){
$is_piao = 1;
}else{
//当前的前一个小时是否在 $xlh_time_range中
if (in_array($pre_hour, explode(',', $xlh_time_range))) {
$is_piao = 1;
} else {
$is_piao = 0;
}
}
}else{
$is_piao = 0;
}
}else{
$is_piao = 0;
}
//获取上一个时间段的配置
// $gift_list = db::name('vs_hour_ranking_gift_config')->where('time_id',$pre_hour)->group('ranking')->order('id', 'desc')->select();
$gift_list = $this->get_hour_ranking($pre_hour);
// echo "上个时间段的配置:" .json_encode($gift_list)."\n";
// 提取所有有奖励的内容
$allRewards = $this->extractAllRewards($gift_list);
// 按index分组
$groupedRewards = $this->groupRewardsByIndex($allRewards);
// 按名次顺序分配奖励
$distributionResult = $this->distributeByRank($groupedRewards);
//获取上个数组的个数,从而获取配置了多少个名次
$count = count($distributionResult);
echo "上个时间段的配置总数:" .$count."\n";
//获取前一个小时的 前$count名房间排行
$room_list = model('api/RoomHourRanking')->room_hour_ranking(1, $count, $start_time, $end_time);
$room_owner = [];
if ($room_list['code'] == 1) {
//获取房间排行奖励最低值
$min_price = db::name('vs_hour_ranking_config')->where('id', 1)->value('min_price');
if ($room_list['data']['lists']) {
echo "房间列表:" .json_encode($room_list['data']['lists'])."\n";
foreach ($room_list['data']['lists'] as $v){
if ($v['total_price'] >= $min_price) {
$room_owner[] = [
'user_id' => $v['user_id'],
'room_name' => $v['room_name'],
'room_id' => $v['room_id'],
'total_price' => $v['total_price']
];
}
}
}
}
if ($distributionResult && $room_owner) {
$text_list_new = [];
echo "礼物数:" .json_encode($distributionResult)."\n";
echo "房主:" .json_encode($room_owner)."\n";
foreach ($distributionResult as $k => $value) {
//礼物全部给他偷偷放在装扮表及金额 中
//有几个用户就发几个
if(count($room_owner) > $k){
// 为每个房间添加一个标志,表示是否已处理推送信息
$hasProcessedPush = false;
foreach ($value['rewards'] as $v){
if($v['type'] == 0){//1金币2礼物3头像4坐骑
echo "发金币:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
$res = $this->add_coin($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
}elseif ($v['type'] == 1){
echo "发礼物:" .$v['value'].'==>'.$room_owner[$k]['user_id']."\n";
$res = $this->add_gift($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao);
}elseif ($v['type'] == 2){
$res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,3);
}elseif ($v['type'] == 3){
$res = $this->add_decorate($v['value'], $room_owner[$k]['user_id'],$k + 1,$room_owner[$k]['room_id'],$room_owner[$k]['total_price'],$is_piao,4);
}
// 只有在第一次处理奖励时添加推送信息,避免重复推送
if(!$hasProcessedPush && $is_piao == 1) {
$room_name = $room_owner[$k]['room_name'];
//推送礼物横幅
if ($k == 0) {
$text = '新科状元!【' . $room_name . '】独占鳌头!';
} elseif ($k == 1) {
$text = '金榜榜眼!【' . $room_name . '】才气逼人!';
} elseif ($k == 2) {
$text = '风采探花!【' . $room_name . '】实力绽放!';
}
$text_list_new[] = [
'text' => $text ?? '恭喜【' . $room_name . '】获得礼物!',
'room_id' => $room_owner[$k]['room_id'],
'room_name' => $room_name,
'rank_number' => $k + 1,
];
$hasProcessedPush = true; // 标记已处理推送
}
}
}
}
if(!empty($text_list_new)){
$push = new Push();
$push->hourRanking($text_list_new);
}
}
echo "送礼-共" . count($room_owner) . "个房间房主获益\n";
}
//添加金币到钱包
public function add_coin($coin,$user_id,$ranking,$room_id,$total_price,$is_piao){
if($coin > 0){
$data = [
'user_id' => $user_id,
'change_value' => $coin,
// 'room_id' => $room_ids,
'money_type' => 1,
'change_type' => 27,
'from_id' => 0,
'remarks' => '小时榜获得',
'createtime' => time()
];
//开启事务
Db::startTrans();
$res = Db::name('vs_user_money_log')->insert($data);
if(!$res){
Db::rollback();
}
//增加用户金币
$res1 = Db::name('user_wallet')->where(['user_id'=>$user_id])->setInc('coin',$coin);
if(!$res1){
Db::rollback();
}
//添加到排行表
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
$end_time = strtotime(date('Y-m-d H:00:00')) - 1;
$res2 = db::name('vs_hour_ranking')->insert([
'ranking' => $ranking,
'room_id' => $room_id,
'flowing_water' => $total_price,
'coin' => $coin,
'time_id' => date('H', strtotime('-1 hour')),
'stime' => $start_time,
'etime' => $end_time,
'createtime' => time(),
'updatetime' => time(),
'is_public_server' => $is_piao
]);
if(!$res2){
Db::rollback();
}
Db::commit();
}
return true;
}
//添加礼物到背包
public function add_gift($gift_id,$user_id,$ranking,$room_id,$total_price,$is_piao){
$res = model('api/UserGiftPack')->change_user_gift_pack($user_id,$gift_id,1,model('UserGiftPack')::HOUR_RANK_GET,"小时榜获得");
if($res['code'] == 0){
Log::record("小时榜获取礼物失败:".$res['msg'],"info");
}
//添加到排行表
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
$end_time = strtotime(date('Y-m-d H:00:00')) - 1;
$res2 = db::name('vs_hour_ranking')->insert([
'ranking' => $ranking,
'room_id' => $room_id,
'flowing_water' => $total_price,
'gift_id' => $gift_id,
'gift_type' => 2,
'time_id' => date('H', strtotime('-1 hour')),
'stime' => $start_time,
'etime' => $end_time,
'createtime' => time(),
'updatetime' => time(),
'is_public_server' => $is_piao
]);
if(!$res2){
Log::record("小时榜礼物锁定失败","info");
}
return true;
}
//添加装扮到背包
public function add_decorate($avatar_id,$user_id,$ranking,$room_id,$total_price,$is_piao,$type){
$decorate_price_info = db::name('vs_decorate_price')->where(['id'=>$avatar_id])->find();
if(empty($decorate_price_info)){
Log::record("小时榜获取装扮失败:没有找到装扮!".$avatar_id,"info");
}
$res = model('api/Decorate')->pay_decorate($user_id,$decorate_price_info['did'],$decorate_price_info['day'],2);
if($res['code'] == 0){
Log::record("小时榜获取装扮失败:".$res['msg']."-".$avatar_id,"info");
}
//添加到排行表
$start_time = strtotime(date('Y-m-d H:00:00', strtotime('-1 hour')));
$end_time = strtotime(date('Y-m-d H:00:00')) - 1;
$res2 = db::name('vs_hour_ranking')->insert([
'ranking' => $ranking,
'room_id' => $room_id,
'flowing_water' => $total_price,
'gift_id' => $avatar_id,
'gift_type' => $type,
'time_id' => date('H', strtotime('-1 hour')),
'stime' => $start_time,
'etime' => $end_time,
'createtime' => time(),
'updatetime' => time(),
'is_public_server' => $is_piao,
]);
if(!$res2){
Log::record("小时榜咋装扮锁定失败","info");
}
return true;
}
/**
* 提取所有有奖励的内容
*/
private function extractAllRewards($responseData)
{
$allRewards = [];
foreach ($responseData as $timeSlot) {
foreach ($timeSlot['reward'] as $rewardItem) {
$index = $rewardItem['index'];
$content = $rewardItem['content'];
// 只处理有奖励内容的数据
if (!empty($content)) {
foreach ($content as $rewardContent) {
$allRewards[] = [
'index' => $index,
'type' => $rewardContent['type'],
'value' => $rewardContent['value'],
'name' => $rewardContent['name'] ?? ''
];
}
}
}
}
return $allRewards;
}
/**
* 按index分组奖励
*/
private function groupRewardsByIndex($allRewards)
{
$grouped = [];
foreach ($allRewards as $reward) {
$index = $reward['index'];
if (!isset($grouped[$index])) {
$grouped[$index] = [];
}
$grouped[$index][] = $reward;
}
// 按index排序
ksort($grouped);
return $grouped;
}
/**
* 按名次顺序分配奖励
*/
private function distributeByRank($groupedRewards)
{
$distribution = [];
$currentRank = 0; // 从第1名开始
// 按index顺序分配index 0 = 第1名index 1 = 第2名以此类推
foreach ($groupedRewards as $index => $rewards) {
// 确保名次连续,如果有空缺则填充空名次
while ($currentRank < $index) {
$distribution[] = [
'rank' => $currentRank + 1,
'rewards' => []
];
$currentRank++;
}
// 分配当前名次的奖励
$distribution[] = [
'rank' => $currentRank + 1,
'rewards' => $rewards
];
$currentRank++;
}
return $distribution;
}
public function get_hour_ranking($time){
// 先按时间段和排名索引分组查询
$timeRanges = db::name('vs_hour_ranking_gift_config')->distinct(true)
->where('time_id', '=', $time)
->order('time_id')
->column('time_id');
$result = [];
foreach ($timeRanges as $timeRange) {
// 查询该时间段的所有数据
$rewards = db::name('vs_hour_ranking_gift_config')->where('time_id', $timeRange)
->field('ranking, gift_type, gift_id,coin,name')
->order('ranking')
->select();
$rewardMap = [];
foreach ($rewards as $reward) {
$rankIndex = $reward['ranking'];
if (!isset($rewardMap[$rankIndex])) {
$rewardMap[$rankIndex] = [
'index' => $rankIndex,
// 'name' => $reward['rank_name'],
'content' => []
];
}
// 添加奖励内容到content数组
if ($reward['gift_id'] != 0 || $reward['coin'] != 0) {
if($reward['gift_id'] != 0){
$rewardMap[$rankIndex]['content'][] = [
'type' => $reward['gift_type'],
'value' => $reward['gift_id'],
// 'coin' => $reward['coin'],
'name' => $reward['name'],
];
}
if($reward['coin'] != 0){
$rewardMap[$rankIndex]['content'][] = [
'type' => $reward['gift_type'],
'value' => $reward['coin'],
'name' => $reward['name'],
];
}
}
}
// 按index排序
ksort($rewardMap);
$result[] = [
'time' => $timeRange,
'reward' => array_values($rewardMap)
];
}
return $result;
}
}

View File

@@ -0,0 +1,195 @@
<?php
namespace app\cron\controller;
use app\common\controller\Push;
use think\Cache;
use think\Db;
/*
* 定时任务,每秒执行的方法
*/
class RoomPan
{
/*
* 运行函数
*/
function index()
{
echo "巡乐会礼物发放开始:\n";
$this->xlh_gift_send();//拍卖房结束提醒
echo "礼物发放结束 \n";
echo "盲盒转盘礼物补发:\n";
$this->blind_box_turntable_gift_send();//盲盒转盘礼物补发
echo "盲盒转盘礼物补发结束 \n";
}
/*
* 盲盒转盘礼物推送补发
*/
public function blind_box_turntable_gift_send(){
$blind_box_turntable = db('vs_blind_box_turntable_log')->where(['is_sued'=>0,'createtime'=>['>=',time()-60*30]])->limit(1000)->select();
if(empty($blind_box_turntable)){
echo "没有需要发放的礼物 \n";
}
echo "开始发放".count($blind_box_turntable)." \n";
foreach ($blind_box_turntable as $k => $v) {
$blind_box_turntable_results_log = db('vs_blind_box_turntable_results_log')->where('tid',$v['id'])->select();
if(empty($blind_box_turntable_results_log)){
echo $v['id']." 没有需要发放的礼物 \n";
continue;
}
$room_id = $v['room_id'];
$room_name = Db::name('vs_room')->where(['id' => $room_id, 'apply_status' => 2])->value('room_name');
$FromUserInfo = Db::name('user')->where(['id'=>$v['user_id']])->find();
$FromUserInfo['user_id'] = $FromUserInfo['id'];
$FromUserInfo['icon'][0] = model('UserData')->user_wealth_icon($v['user_id']);//财富图标
$FromUserInfo['icon'][1] = model('UserData')->user_charm_icon($v['user_id']);//魅力图标
$user_nickname = $FromUserInfo['nickname'];
$textMessage = $user_nickname;
$text_message = $user_nickname;
foreach ($blind_box_turntable_results_log as $key => $value) {
$ToUserInfo = Db::name('user')->where(['id' => $value['gift_user_id']])->field('id as user_id,nickname,avatar,sex')->find();
$draw_gift = Db::name('vs_gift')->where(['gid'=>$value['gift_id']])->find();
$textMessage = $textMessage . ' 送给 ' . $ToUserInfo['nickname']. ' 盲盒转盘礼物 ' . $draw_gift['gift_name'].' x ' .$value['count']."\n";
$play_image[] = $draw_gift['play_image'];
$gift_names[] = $draw_gift['gift_name'];
$text_message = $text_message . '在' . $room_name . '房间送给了' . $ToUserInfo['nickname'] . $draw_gift['gift_name'] . 'X' . $value['count']."\n";
if($draw_gift['is_public_server'] == 1) {
$text_list_new[] = [
'text' => $text_message,
'gift_picture' => $draw_gift['base_image'],
'room_id' => $room_id,
'fromUserName' => $FromUserInfo['nickname'],
'toUserName' => $ToUserInfo['nickname'],
'giftName' => $draw_gift['gift_name'],
'roomId' => $room_id,
'number' => $value['count'],
];
}
$ToUserInfosList[$value['gift_user_id']] = $ToUserInfo;
}
foreach($ToUserInfosList as &$userInfo) {
$userInfo['icon'][0] = model('UserData')->user_wealth_icon($userInfo['user_id']);//财富图标
$userInfo['icon'][1] = model('UserData')->user_charm_icon($userInfo['user_id']);//魅力图标
$userInfo['charm'] = db::name('vs_room_user_charm')->where(['user_id' => $userInfo['user_id'],'room_id' => $room_id])->value('charm');//魅力
$ToUserInfos[] = $userInfo;
}
$text = [
'FromUserInfo' => $FromUserInfo,
'ToUserInfos' => $ToUserInfos,
'GiftInfo' => [
'play_image' => implode(',',$play_image),
'gift_name' => implode(',',$gift_names),
],
'text' => rtrim($textMessage, "\n")
];
//聊天室推送系统消息
model('Chat')->sendMsg(1005,$room_id,$text);
$roomtype = Db::name('vs_room')->where(['id' => $room_id])->value('type_id');
if($roomtype == 6){
//推送消息
$hot_value = db::name('vs_give_gift')->where('from_id', $room_id)->where('from',6)
->sum('total_price');
$text1 = [
'room_id' => $room_id,
'hot_value' => $hot_value * 10,
'text' => '房间心动值变化'
];
//聊天室推送系统消息
model('Chat')->sendMsg(1028,$room_id,$text1);
}else{
if(!empty($text_list_new)){
//推送礼物横幅
$push = new Push($v['user_id'], $room_id);
$push->giftBanner($text_list_new);
}
}
db::name('vs_blind_box_turntable_log')->where('id', $v['id'])->update(['is_sued' => 1, 'updatetime' => time()]);
}
}
/*
* 巡乐会结束 礼物发放 【定时脚本】
*/
public function xlh_gift_send(){
$xlh_list = db::name('vs_room_pan_xlh')->where(['send_time'=>0,'end_time'=>['<=',time()]])->select();
if(empty($xlh_list)){
echo "没有需要发放的礼物 \n";
}
foreach ($xlh_list as $key=>$value){
try{
if($value['user_id'] == 0){
echo "第.".$value['periods']." 巡乐会结束 没有中奖用户 \n";
$res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([
'send_time' => time()
]);
// db::name("vs_room")->where('id',$value['room_id'])->update([
// 'xlh_periods_num' => 0
// ]);
Cache::set("xlh_periods_num", 0, 0);
//推送礼物横幅
$text = "本轮巡乐会已结束,请大家重新开始下一轮巡乐会";
$push = new Push(0, $value['room_id']);
$text_list_new = [
'text' => $text,
'room_id' => $value['room_id'],
'from_type' => 104
];
$push->xunlehui($text_list_new);
continue;
}
//发放
//抽中礼物落包
$res = [];
$res = model('api/UserGiftPack')->change_user_gift_pack($value['user_id'],$value['gift_id'],$value['num'],model('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖发放");
if ($res['code'] != 1) {
echo $res['msg']."\n";
continue;
}
echo "巡乐会中奖礼物发放成功 用户Id".$value['user_id']."\n";
//房主礼物落包
$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('UserGiftPack')::XLH_DRAW_GIFT_GET,"巡乐会中奖后房主礼物发放");
if ($res['code'] != 1) {
echo $res['msg']."\n";
continue;
}
echo "巡乐会中奖后房主礼物发放成功 房主Id".$user_id."\n";
//处理发放记录
$res = [];
$res = db::name('vs_room_pan_xlh')->where('id',$value['id'])->update([
'send_time' => time()
]);
$xlh_log = db::name('vs_room_pan_xlh_log')->where(['xlh_id'=>$value['id'],'user_id'=>$value['user_id']])->order('id desc')->find();
$res = db::name('vs_room_pan_xlh_log')->where('id',$xlh_log['id'])->update([
'is_send' => 1
]);
if ($res === false) {
echo "处理发放记录失败 \n";
continue;
}
Cache::set("xlh_periods_num", 0, 0);
//推送
$FromUserInfo = db::name('user')->field('nickname,avatar')->where(['id'=>$value['user_id']])->find();
$gift_name = db::name('vs_gift')->where(['gid'=>$value['gift_id']])->value('gift_name');
$text = $FromUserInfo['nickname'] . ' 用户在巡乐会中 ' .$gift_name.'礼物 x ' .$value['num']." 已收入背包";
//推送礼物横幅
$push = new Push(0, $value['room_id']);
$text_list_new = [
'text' => $text,
'room_id' => $value['room_id'],
'from_type' => 104
];
$push->xunlehui($text_list_new);
}catch (\Exception $e){
echo $e->getMessage()."\n";
}
}
}
}

View File

@@ -0,0 +1,158 @@
<?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";
}
}
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);
}
}