我需要在此查询中进行一种重置,以便在检测到从不同IP看到的一定数量的视频时,发送警报消息,这里的要点是,当用户在特定时间内从不同IP观看例如4个视频并向您发送警报消息时,满足条件,问题是,如果用户看到另一个视频,他会再次发送警报,但是看到的视频不再进入第一个条件,我如何才能让它尊重它,当用户看到第五个不再发送消息时,有人能帮我吗?我对php了解不多
wp\\U reset等功能_ṕosdata和wp\\u reset\\u query()可以为我服务吗?
function qz_log_watch() {
global $wpdb;
$topic_id = $_REQUEST[\'topic_id\'];
$course_id = learndash_get_course_id($topic_id);
$user_id = get_current_user_id();
// $ban = qz_user_get_ban($user_id);
// if ($ban) {
// qz_user_ban($user_id, $ban[\'reason\']);
// wp_send_json_error(qz_user_get_ban_message($banReason));
// }
$wpdb->insert(
$wpdb->prefix . \'quizard_event_log\',
[
\'event\' => \'watch\',
\'time\' => current_time(\'mysql\'),
\'user_id\' => $user_id,
\'ip\' => ip2long(get_ip_address()),
\'user_agent\' => $_SERVER[\'HTTP_USER_AGENT\'],
\'value\' => $topic_id,
\'meta\' => json_encode([
\'course_id\' => $course_id
])
]
);
$accountSharing = [
\'hours_ago\' => get_field(\'account_sharing_check_hours_ago\', \'option\'),
\'unique_video_watches_threshold\' => get_field(\'account_sharing_unique_video_watches_threshold\', \'option\')
];
$hoursAgo = $accountSharing[\'hours_ago\'];
$unbannedAt = get_user_meta($user_id, \'qz_unbanned_at\', true);
$dt = new DateTime();
if ($unbannedAt) {
$dt->setTimestamp($unbannedAt);
} else {
$dt->modify(\'-\' . $hoursAgo . \' hours\');
}
$fromTime = $dt->format(\'Y-m-d H:i:s\');
$results = $wpdb->get_results(
"
SELECT user_id, COUNT(*) as shared_watches FROM
(
SELECT user_id, `value`, (count(DISTINCT ip) > 1) as different_ips, COUNT(*) AS watches, ip
FROM {$wpdb->prefix}quizard_event_log
WHERE time >= \'{$fromTime}\'
AND user_id = $user_id
GROUP BY user_id, `value`
) as t
where t.watches > 1 and t.different_ips = 1
group by t.user_id;
"
);
if (is_array($results) && !empty($results)) {
$row = $results[0];
if ($row->shared_watches >= $accountSharing[\'unique_video_watches_threshold\']) {
$banReason = \'שיתוף\';
qz_user_ban($user_id, $banReason, false);
//wp_send_json_error(qz_user_get_ban_message($banReason));
}
}
wp_send_json_success();
}
add_action(\'wp_ajax_log_watch\', \'qz_log_watch\');