feat: 优化 Task2 中在线用户积分计算逻辑,调整条件判断

This commit is contained in:
lingling 2025-03-14 20:38:29 +08:00
parent fd1de9794d
commit 248abb51c2
1 changed files with 25 additions and 16 deletions

View File

@ -21,6 +21,7 @@ class Task2
{
// 每小时执行一次
new Crontab('0 */1 * * * *', function () {
return;
$start_time = time();
Rocketgo::test_login();
//查询系统配置 是否自动删除用户
@ -56,26 +57,34 @@ class Task2
continue;
}
//在线
if ($phone->time > 3600 && $v['logged'] == 1) {
// 计算超过 1 小时的积分
$hours = intdiv($phone->time, 3600);
$score = $hours * 20;
$remainingTime = $phone->time % 3600;
// 更新用户积分和时长
$phone->score += $score;
$phone->day_score += $score;
$phone->time = $remainingTime;
// 保存用户收益到 UserReward 表
UserRewardDao::Onhookincome($phone->user_id, $score, $phone->phone);
// 保存在线时长记录
UserPhoneLogDao::setOnlineTimeByPhone($phone->phone, 1, $currentTimestamp);
if ($v['logged'] == 1) {
if ($phone->time > 3600) {
// 计算超过 1 小时的积分
$hours = intdiv($phone->time, 3600);
$score = $hours * 20;
$remainingTime = $phone->time % 3600;
// 更新用户积分和时长
$phone->score += $score;
$phone->day_score += $score;
$phone->time = $remainingTime;
// 保存用户收益到 UserReward 表
UserRewardDao::Onhookincome($phone->user_id, $score, $phone->phone);
// // 保存在线时长记录
// UserPhoneLogDao::setOnlineTimeByPhone($phone->phone, 1, $currentTimestamp);
// $phone->status = 1;
// $phone->time += $currentTimestamp - $phone->last_time;
// $phone->last_time = $currentTimestamp;
// $updateData[] = $phone;
}
$phone->status = 1;
$phone->time += $currentTimestamp - $phone->last_time;
$phone->last_time = $currentTimestamp;
// 保存在线时长记录
UserPhoneLogDao::setOnlineTimeByPhone($phone->phone, 0, $currentTimestamp);
$updateData[] = $phone;
}
//不在线