Created
February 6, 2013 16:53
-
-
Save Fabax/4723950 to your computer and use it in GitHub Desktop.
traitementwinlose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// informations twitter | |
$consumerKey = '6232ltTfgbQobfF7KTw6Gg'; | |
$consumerSecret = 'OP5yeGLSgdmAB1JHerfgRkelFFSMxsWUIxz3oy0s'; | |
$oAuthToken = '621155088-GCelvA9yeTXRzdqp7QTcuO9DjKv0W7nqAqJNJb6Q'; | |
$oAuthSecret = 'NPW9TfOIR81kazfsmyoByDjfJAxdFaBqgEqVqKus'; | |
require_once('twitter/twitteroauth.php'); | |
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret); | |
//information de la DB | |
$server = ""; | |
$username = ""; | |
$password = ""; | |
$database = ""; | |
$today = date("Y-m-d H:i:s"); | |
$heure = date("H:i:s"); | |
$lots = array( | |
"0" => "22", | |
"1" => "10", | |
"2" => "3", | |
); | |
$lotGagne = rand(0,2); | |
$outro = array("Bravo", "Bon shopping", "Félicitations à toi"); | |
$soiree_debut = strtotime('2012-10-23 20:59:59'); | |
$soiree_fin = strtotime('2012-10-23 23:59:59'); | |
if(strtotime($today) < $soiree_fin && strtotime($today) > $soiree_debut) { | |
$periode = array( | |
//temps en heure | |
"debut" => "21", | |
"fin" => "24", | |
); | |
$table_name = "jackpot_lots_2"; | |
} else { | |
$periode = array( | |
//temps en heure | |
"debut" => "23", | |
"fin" => "24", | |
); | |
$table_name = "jackpot_lots"; | |
} | |
if(date("H") >= $periode["fin"] || date("H") < $periode["debut"]) { | |
echo 0; | |
return; | |
} | |
$tempsTotal = ($periode['fin'] - $periode['debut']) * 60; | |
$tempsPasse = ((date("H")*60)+date("i")) - ($periode['debut']*60); | |
//connection à la db | |
try{ | |
$bdd = new PDO('mysql:host='.$server.';dbname='.$database.'', $username, $password); | |
}catch (Exception $e){ | |
die('Erreur : ' . $e->getMessage()); | |
} | |
//fonction set up | |
$i = 0; | |
$j = 0; | |
while ($i < count($lots)) { | |
//calcul pour connaitre le temps entre chaque cadeaux | |
$intervals[$i] = round($tempsTotal/$lots[$i]); | |
//lots qu'il aurai fallut donné | |
$lotsDuOffrir[$i] = floor($tempsPasse/$intervals[$i]) + 1; | |
//temps restant avant le prochain cycle | |
$timeLeft[$i] = round($intervals[$i] * (1 - ($tempsPasse/$intervals[$i] - floor($tempsPasse/$intervals[$i])))); | |
$reponse = $bdd->query('SELECT COUNT(*) FROM '.$table_name.' WHERE date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 DAY) AND type = '.$i); | |
//lots deja offert | |
$lotsOfferts[$i]= $reponse->fetchColumn(); | |
//lots à offrir | |
$lotAOffrir[$i] = $lotsDuOffrir[$i] - $lotsOfferts[$i]; | |
if($lotAOffrir[$i]>0){ | |
//On a des choses à donner | |
if($lotAOffrir[$i] > 1){ | |
//on donne tout de suite car on en a en rab | |
$gainsPossibles[$j] = $i; | |
$j++; | |
}else{ | |
//On fait un petit random | |
$percent = rand(1, $timeLeft[$i]); | |
if($percent == 1){ | |
$gainsPossibles[$j] = $i; | |
$j++; | |
} | |
} | |
} | |
$i++; | |
} | |
//determiner le numero du gagnant | |
$reponseGagants = $bdd->query('SELECT COUNT(*) FROM '.$table_name); | |
$numeroGagnant = $reponseGagants->fetchColumn(); | |
// echo 'nombre de gagnants : '; | |
// echo $numeroGagnant; | |
// echo '<br>'; | |
// On définit le lot gagné (ou pas) | |
$lotsDispos = count($gainsPossibles); | |
if ($lotsDispos == 0) { | |
echo 0; | |
} else { | |
$lotGagne = rand(0, $lotsDispos-1); | |
$req = $bdd->prepare('INSERT INTO '.$table_name.'(type, date) VALUES(:type, :date)'); | |
$req->execute(array('type' => $gainsPossibles[$lotGagne],'date' => $today)); | |
// if($gainsPossibles[$lotGagne] == 0){ | |
// $message = ": Notre ".$numeroGagnant."e gagnant vient de remporter un bon d'achat de 15€ chez ".$outro[$lotGagne]." !"; | |
// }else if($gainsPossibles[$lotGagne] == 1){ | |
// $message = ": Notre ".$numeroGagnant."e gagnant vient de remporter un bon d'achat de 20€ chez ".$outro[$lotGagne]." !"; | |
// }else if($gainsPossibles[$lotGagne] == 2){ | |
// $message = ": Notre ".$numeroGagnant."e gagnant vient de remporter un bon d'achat de 40€ chez ".$outro[$lotGagne]." !"; | |
// } | |
// $tweet->post('statuses/update', array('status' => '#Test '.$message)); | |
echo $gainsPossibles[$lotGagne]+1; | |
} | |
//$message = ": Hey notre ".$numeroGagnant."e gagnant vient de remporter un bon d'achat de 15€ chez @CITADIUM avec Motorola ".$outro[$random]." !"; | |
// echo '<br>'; | |
// echo 'temps passé '; echo $tempsPasse; | |
// echo '<br>'; | |
// echo 'temps total '; echo $tempsTotal; | |
// echo '<br>'; | |
// echo 'intervals '; print_r($intervals); | |
// echo '<br>'; | |
// echo 'lotsDuOffrir '; print_r($lotsDuOffrir); | |
// echo '<br>'; | |
// echo 'timeLeft '; print_r($timeLeft); | |
// echo '<br>'; | |
// echo 'lotsOfferts '; print_r($lotsOfferts); | |
// echo '<br>'; | |
// echo 'lotAOffrir '; print_r($lotAOffrir); | |
// echo '<br>'; | |
// echo 'gainsPossibles '; print_r($gainsPossibles); | |
// echo '<br>'; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment