Лотерея Stalkers 5 из 30

mess = 'Не хватает денег
'; } else { mysql_query("update users set money = money - 1 where id = '".mysql_real_escape_string($user['id'])."';"); mysql_query("insert into inventory (`owner`,`name`,`maxdur`,`img`,`letter`,`type`) values ('".mysql_real_escape_string($user['id'])."','Лотерейный билет','1','loto.gif','".mysql_real_escape_string($txt)."','210');"); } } function pay_for_5($summ){ // оплата если 5 из 5 угадано global $user; mysql_query("update users set money = money + '".mysql_real_escape_string($summ)."' where id = '".mysql_real_escape_string($user['id'])."';"); } function pay_for_4($summ){ // оплата если 4 из 5 угадано global $user; mysql_query("update users set money = money + '".mysql_real_escape_string($summ)."' where id = '".mysql_real_escape_string($user['id'])."';"); } function pay_for_3($summ){ // оплата если 3 из 5 угадано global $user; mysql_query("update users set money = money + '".mysql_real_escape_string($summ)."' where id = '".mysql_real_escape_string($user['id'])."';"); } function pay_for_klan($summ){ // 10% клану // хуй global $user; mysql_query("update users set money = money + '".mysql_real_escape_string($summ)."' where id = 7014;"); } function buy_ticket($selected_str){ $selected_str = substr($selected_str,0,strlen($selected_str)-1); $selected_array = explode(',',$selected_str); sort($selected_array); $id_user = $this->get_this_user_id(); if (sizeof($selected_array) > 5){ $sql_ins_cheat = "insert into lottery_cheaters(`id_user`,`values`,`date`) values('".mysql_real_escape_string($id_user)."','".mysql_real_escape_string($selected_str)."','".date('Y-m-d H:i:s')."')"; mysql_query($sql_ins_cheat); } for($i=0;$i<5;$i++){ $values .= $selected_array[$i].','; } $sql = "select id from lottery where end='0'"; $res = mysql_query($sql); while($result_lottery = mysql_fetch_assoc($res)){ $id_lottery = $result_lottery['id']; } $this->buy("Тираж № ".$id_lottery."
Выбраные номера: ".$values); if($this->mess != null) { return "".$this->mess.""; } echo "Билет куплен.
"; $date = date('Y-m-d H:i:s'); $sql = "insert into lottery_log(`id_user`,`values`,`date`,`id_lottery`) values('".mysql_real_escape_string($id_user)."','".mysql_real_escape_string($values)."','".mysql_real_escape_string($date)."','".mysql_real_escape_string($id_lottery)."')"; $res = mysql_query($sql); $jackpot = 0; $sql = "select * from `lottery` where end=0 limit 1"; $res = mysql_query($sql); while($result = mysql_fetch_assoc($res)){ $id = $result['id']; $jackpot = $result['jackpot']; $fond = $result['fond']; } $fond += 0.7; $sql = "update lottery set fond='".mysql_real_escape_string($fond)."' where id='".mysql_real_escape_string($id)."' "; mysql_query($sql); } function get_result(){ $array = range(1,30); shuffle($array); for($i=0;$i<5;$i++){ $result[] = $array[$i]; } return $result; } function get_count($win_combination,$user_combination){ $user_array = explode(',',$user_combination); $count = 0; for($i=0;$i<5;$i++){ if (strpos(",".$win_combination,",".$user_array[$i].",") !== FALSE){ $count ++; //echo substr($win_combination,$z,1)." "; } } return $count; } function get_win_combination(){ $win_combination = $this->get_result(); for($i=0;$i<5;$i++){ $win_combination_str .= $win_combination[$i].','; } $sql = "select id,jackpot,fond from lottery where end='0'"; $res = mysql_query($sql); while($result = mysql_fetch_assoc($res)){ $id_lottery = $result['id']; $jackpot = $result['jackpot']; $fond = $result['fond']; } $sql = "insert into lottery_win_combination(`values`,`date`,`id_lottery`) values('".mysql_real_escape_string($win_combination_str)."','".date('Y-m-d H:i:s')."','".mysql_real_escape_string($id_lottery)."') "; mysql_query($sql); $people_5 = 0; $people_4 = 0; $people_3 = 0; $sql = "select * from lottery_log where id_lottery='".mysql_real_escape_string($id_lottery)."' "; $res = mysql_query($sql); while($result = mysql_fetch_assoc($res)){ $count = $this->get_count($win_combination_str,$result['values']); if ($count == 5){ $people_5 ++; } if ($count == 4){ $people_4 ++; } if ($count == 3){ $people_3 ++; } } $klan_pay = $fond*0.05; $this->pay_for_klan($klan_pay); $fond = $fond - $klan_pay; if ($people_5 > 0 ){ $summ_5 = ($jackpot+($fond*0.3))/$people_5; $jackpot = 0; } else{ $summ_5 = ($fond*0.3); $jackpot += $fond*0.3; } if ($people_4 > 0){ $summ_4 = ($fond*0.3)/$people_4; } else{ $summ_4 = ($fond*0.3); $jackpot += $fond*0.3; } if ($people_3 > 0){ $summ_3 = ($fond*0.4)/$people_3; } else{ $summ_3 = $fond*0.4; $jackpot += $fond*0.4; } $sql_upd = "update lottery set end='1' , fond='".mysql_real_escape_string($fond)."' , summ_5='".mysql_real_escape_string($summ_5)."' , summ_4='".mysql_real_escape_string($summ_4)."' , summ_3='".mysql_real_escape_string($summ_3)."' , count_5='".mysql_real_escape_string($people_5)."' , count_4='".mysql_real_escape_string($people_4)."' , count_3='".mysql_real_escape_string($people_3)."' where id='".mysql_real_escape_string($id_lottery)."'"; mysql_query($sql_upd); $sql_ins = "insert into lottery(`date`,`jackpot`,`fond`,`end`,`summ_5`,`summ_4`,`summ_3`,`count_5`,`count_4`,`count_3`) values('".date('Y-m-d H:i:s',strtotime("+1 week"))."','".mysql_real_escape_string($jackpot)."','0','0','0','0','0','0','0','0')"; mysql_query($sql_ins); } function check($id_lottery){ $id_user = $this->get_this_user_id(); //$sql_comb = "select values from lottery_win_combination where id_lottery='".$id_lottery."'"; if ($id_lottery < 1) { $sql_comb = "select * from lottery where end=1 order by id DESC LIMIT 1;"; $res_comb = mysql_fetch_array(mysql_query($sql_comb)); $id_lottery = $res_comb['id']; } $sql_comb = "select * from lottery_win_combination where id_lottery='".mysql_real_escape_string($id_lottery)."'"; $res_comb = mysql_query($sql_comb); while($result_comb = mysql_fetch_assoc($res_comb)){ $win_combination_str = $result_comb['values']; } $sql_summ = "select * from lottery where id='".mysql_real_escape_string($id_lottery)."'"; $res_summ = mysql_query($sql_summ); while($result_summ = mysql_fetch_assoc($res_summ)){ $summ_5 = $result_summ['summ_5']; $summ_4 = $result_summ['summ_4']; $summ_3 = $result_summ['summ_3']; $jackpot = $result_summ['jackpot']; } $sql = "select * from lottery_log where id_lottery='".mysql_real_escape_string($id_lottery)."' and id_user='".mysql_real_escape_string($id_user)."' and send='0' "; $res = mysql_query($sql); while($result = mysql_fetch_assoc($res)){ $count = $this->get_count($win_combination_str,$result['values']); if ($count == 5){ $this->pay_for_5($jackpot); echo "Билет № ".$result['id']." выиграл ".$jackpot." кр. Выбраные номера: ".$result['values']."
"; $zz = 1; } if ($count == 4){ $this->pay_for_4($summ_4); echo "Билет № ".$result['id']." выиграл ".$summ_4." кр. Выбраные номера: ".$result['values']."
"; $zz = 1; } if ($count == 3){ $this->pay_for_3($summ_3); echo "Билет № ".$result['id']." выиграл ".$summ_3." кр. Выбраные номера: ".$result['values']."
"; $zz = 1; } $sql_upd = "update lottery_log set send='1' where id='".mysql_real_escape_string($result['id'])."'"; mysql_query($sql_upd); } if (!$zz) { echo "Нет выигрышных билетов
"; } } function view_results($id_lottery = 0){ $str = ''; if ($id_lottery > 0) { $sql = "select * from lottery where id='".$id_lottery."' and end=1;"; } else { $sql = "select * from lottery where end=1 order by id DESC LIMIT 1;"; } $res = mysql_query($sql); while ($result = mysql_fetch_assoc($res)){ $id_lottery = $result['id']; $date = $result['date']; $jackpot = $result['jackpot']; $fond = $result['fond']; $summ_5 = $result['summ_5']; $summ_4 = $result['summ_4']; $summ_3 = $result['summ_3']; $count_5 = $result['count_5']; $count_4 = $result['count_4']; $count_3 = $result['count_3']; } $summ = $summ_5 + $summ_4 + $summ_3; $count = $count_5 + $count_4 + $count_3; $sql_combination = "select * from lottery_win_combination where id_lottery='".mysql_real_escape_string($id_lottery)."'"; $res_combination = mysql_query($sql_combination); while($result_combination = mysql_fetch_assoc($res_combination)){ $combination = $result_combination['values']; } $sql = "select * from lottery_log where id_lottery='".mysql_real_escape_string($id_lottery)."'"; $res = mysql_query($sql); $allbillets = mysql_num_rows($res); $str .= '

  Итоги тиража номер

'; if (!$date) { return $str.'Лотерея не проводилась.'; } $str .= 'Тираж номер: '.$id_lottery.'
Дата: '.$date.'
Призовой фонд: '.$fond.' кр.
Джекпот: '.$jackpot.' кр.
Всего было продано билетов: '.$allbillets.'
Выпала комбинация : '.substr($combination,0,strlen($combination)-1).'
Угадано номеров Выиграно билетов Сумма выиграша
5 '.$count_5.' '; if ($count_5 == 0){ $str .= 'Не выиграл ни один билет
'.$summ_5.' кр. идут в джекпот'; } else{ $str .= $summ_5.' кр.'; } $str .= '
4 '.$count_4.' '; if ($count_4 == 0){ $str .= 'Не выиграл ни один билет
'.$summ_4.' кр. идут в джекпот'; } else{ $str .= $summ_4.' кр.'; } $str .= '
3 '.$count_3.' '; if ($count_3 == 0){ $str .= 'Не выиграл ни один билет
'.$summ_3.' кр. идут в джекпот'; } else{ $str .= $summ_3.' кр.'; } $str .= '

Всего победителей: '.$count.'
Всего выиграно: '.$summ.' кр.
'; return $str; } function view_buy_ticket(){ $str = ''; $str .= ')">30 Выбраные Вами номера : \''; return $str; } } $Lottery = new Lottery(); if ($_GET['startlotery'] == '648gjn6f6734h798h2q398fgsdhnit734whf784whfy7w8jfyw8hg745g3y75h7f23785yh38259') { $Lottery->get_win_combination(); } if ($_POST['value']) { echo $Lottery->buy_ticket($_POST['value']); } $sql = "select * from lottery where end=0 order by id DESC LIMIT 1;"; $res = mysql_query($sql); while ($result = mysql_fetch_assoc($res)){ $id_lottery = $result['id']; $date = $result['date']; $jackpot = $result['jackpot']; $fond = $result['fond']; $summ_5 = $result['summ_5']; $summ_4 = $result['summ_4']; $summ_3 = $result['summ_3']; $count_5 = $result['count_5']; $count_4 = $result['count_4']; $count_3 = $result['count_3']; } ?> Следующий тираж состоится
Призовой фонд: кр.
Джекпот: кр.
Стоимость лотерейного билета: 1.00 кр.



check($_POST['tiraj']); } echo $Lottery->view_results($_POST['tiraj']); //echo $Lottery->check(8); //echo $Lottery->get_count("1,2,3,4,5,","1,2,3,4,5") ?>