<?php
// function __autoload($class)
// {
// include("../zebra_cross/admin_login/classess/".$class.".php");
// }
spl_autoload_register(function($class) {
include("../zebra_cross/admin_login/classess/".$class.".php");
});
$sqlfun = new sqlfunction();
$admin = new admin_login();
date_default_timezone_set("Asia/kolkata");
$cur_date = date("Y-m-d");
$com_date = date('Y-m-d', strtotime("-1 day",strtotime($cur_date)));
$cur_datetime = date("Y-m-d H:i:s");
// $cur_date = date("2021-08-05");
$cnd1110 = "id= '1'";
$check1110 = $sqlfun->fetchdata("message",$cnd1110);
$row1110 = $check1110->fetch(PDO::FETCH_OBJ);
$default_commision_rate = $row1110->default_commision_rate;
// $kya = $row111->result_date;
// $open_time = $row111->open_time;
// $close_time = $row111->close_time;
// if($kya ==1){
// $end_date = date('Y-m-d H:i:s', strtotime("+".$kya." day",strtotime($cur_date."".$close_time)));
// $start_date = date('Y-m-d H:i:s', strtotime("+0 day",strtotime($cur_date."".$open_time)));
// }
// else
// {
// $end_date = date('Y-m-d H:i:s', strtotime("+".$kya." day",strtotime($cur_date."".$close_time)));
// $start_date = date('Y-m-d H:i:s', strtotime("+0 day",strtotime($cur_date."".$open_time)));
// }
$open_time = "6:30AM";
$close_time = "3:00AM";
$start_date = date('Y-m-d H:i:s', strtotime("-1 day",strtotime($cur_date."".$open_time)));
$end_date = date('Y-m-d H:i:s', strtotime("+0 day",strtotime($cur_date."".$close_time)));
//betting players
$cnd9 = "play_datetime BETWEEN '$start_date'AND '$end_date' && refer_id != ''";
$check9 = $sqlfun->distinct_fetchdata("manage_game_id",$cnd9);
if($check9->rowCount() > 0)
{
while($row9 = $check9->fetch(PDO::FETCH_OBJ))
{
$refer_id = $row9->refer_id;
//how many players are playing with this refer_id
$cnd101 = "play_datetime BETWEEN '$start_date'AND '$end_date' && refer_id = '$refer_id'";
$check101 = $sqlfun->fetchdata("manage_game_id",$cnd101);
$total_bidamount = $winning_amnt=0;
while($row101 = $check101->fetch(PDO::FETCH_OBJ))
{
$total_bidamount += $row101->amount;
if($row101->status == 'Paid')
{
$winning_amnt += $row101->winning_amnt;
}
}
// echo "total_bidamount = ".$total_bidamount."===";
// echo "winning_amnt = ".$winning_amnt."==";
// echo "refer_id = ".$refer_id."<br/>";
if(intval($total_bidamount) > intval($winning_amnt))
{
$total_profit = intval($total_bidamount) - intval($winning_amnt);
$findPidcnd = "p_id = '$refer_id'";
$checkpid = $sqlfun->fetchdata("player",$findPidcnd);
$rowpid = $checkpid->fetch(PDO::FETCH_OBJ);
$referidname = $rowpid->p_f_name;
$commsion_amnt = ceil($total_profit*$default_commision_rate/100);
//check if data already exists
$cndcom = "date = '$cur_date' && p_id = '$refer_id'";
$checkcom = $sqlfun->fetchdata("comission",$cndcom);
if($checkcom->rowCount() > 0)
{
$rowcom = $checkcom->fetch(PDO::FETCH_OBJ);
$p_g_a = $rowcom->play_game_amnt;
$c_amnt = $rowcom->c_amnt;
$total_profit = $p_g_a + $total_profit;
$commsion_amnt = $commsion_amnt + $c_amnt;
$array_update = array("play_game_amnt"=>$total_profit,"c_amnt"=>$commsion_amnt);
$sqlfun->updated("comission",$array_update,$cndcom);
}
else
{
$array_insert = array("date"=>$com_date,"p_id"=>$refer_id,"p_name"=>$referidname,"play_game_amnt"=>$total_profit,"c_amnt"=>$commsion_amnt,"status"=>"Pending");
$sqlfun->ins_data("comission",$array_insert);
}
}
}
}
$data_cron = array("date"=>$cur_datetime);
$sqlfun->ins_data("cron",$data_cron);
// }
?>