| Server IP : 45.152.65.97 / Your IP : 216.73.217.140 Web Server : Apache/2.4.54 (Win64) OpenSSL/1.1.1p mod_fcgid/2.3.9a System : Windows NT C20260123164925 10.0 build 20348 (Windows Server 2016) AMD64 User : SYSTEM ( 0) PHP Version : 7.4.33 Disable Function : passthru,system,chroot,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,putenv,exec MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/wwwroot/shujupai.cn/wp-content/plugins/jingcaizuqiu/includes/ |
Upload File : |
<?php
if (!defined('ABSPATH')) {
exit;
}
class JCZP_Scheduler {
public function __construct() {
add_action('jczp_daily_predict', array($this, 'run_daily_predict'));
add_action('jczp_check_results', array($this, 'check_match_results'));
add_filter('cron_schedules', array($this, 'add_custom_cron_schedule'));
}
public function add_custom_cron_schedule($schedules) {
$schedules['jczp_twice_daily'] = array(
'interval' => 43200,
'display' => '每日两次(12小时)'
);
return $schedules;
}
public function run_daily_predict() {
if (get_option('jczp_automode') != 1) {
return;
}
$today = date('Y-m-d');
$last_run_date = get_option('jczp_last_run_date', '');
if ($last_run_date === $today) {
return;
}
$predictor = new JCZP_Predictor();
$results = $predictor->get_today_matches();
if (empty($results)) {
return;
}
$post_creator = new JCZP_Post_Creator();
$post_id = $post_creator->create_post($results);
if (!is_wp_error($post_id)) {
update_option('jczp_last_run_date', $today);
}
}
public function check_match_results() {
$args = array(
'post_type' => 'post',
'meta_key' => 'jczp_predict_date',
'posts_per_page' => 10,
'orderby' => 'meta_value',
'order' => 'DESC'
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$api = new JCZP_API();
while ($query->have_posts()) {
$query->the_post();
$post_id = get_the_ID();
$matches_data = get_post_meta($post_id, 'jczp_matches_data', true);
if (!empty($matches_data)) {
$updated_matches = array();
$all_updated = true;
foreach ($matches_data as $match) {
$result = $api->get_match_result($match['id']);
if ($result && $result['status'] === 'FINISHED') {
$match['actual_result'] = $this->determine_result($result['home_score'], $result['away_score']);
$match['is_correct'] = ($match['prediction'] === $match['actual_result']);
} else {
$all_updated = false;
}
$updated_matches[] = $match;
}
if (!empty($updated_matches)) {
update_post_meta($post_id, 'jczp_matches_data', $updated_matches);
}
}
}
wp_reset_postdata();
}
}
private function determine_result($home_score, $away_score) {
if ($home_score > $away_score) {
return '胜';
} elseif ($home_score < $away_score) {
return '负';
} else {
return '平';
}
}
}