linpc
Гуру форума
- Регистрация
- 6 Апр 2012
- Сообщения
- 178
- Реакции
- 55
- Автор темы
- #1
Взялся переписывать из БК лотерейный зал, для сборки guild-honor.
Скрипт вроде нормально переписал. Но возник вопрос.
Эта функция не срабатывает попытался поискать ее в функционале БК, не нашел.
function buy_ticket($selected_str){
$selected_str = substr($selected_str,0,strlen($selected_str)-1);
$selected_array = explode(',',$selected_str);
sort($selected_array);
За что отвечает этот код работы. Может кто подскажет.
PHP:
<?php
//w70-тип билета стоит.
$Buy = mysql_fetch_assoc(mysql_query("SELECT * FROM `items` WHERE `id` = '1230'"));
class Lottery{
function get_this_user_id(){
// определеить id пользователя
global $pers;
return $pers['id'];
}
function buy($txt = ''){
global $pers;
// списать сумму билета
if ($pers['nv'] < '100') {
$this->mess = 'Не хватает денег<BR>';
} else {
mysql_query("UPDATE `user` SET `nv` = `nv`-100 WHERE `id` = '".$pers['id']."'");
mysql_query("INSERT INTO `invent` (`ItemName`,`img`,`protype`,`pl_id`,`dolg`,`price`,`i_param`,`i_need`,`letter`) VALUES ('Лотерейный билет','loto.gif','1230','".$pers['id']."','1','100','2@1','71|72','".$txt."');");
}
}
function pay_for_5($summ){// оплата если 5 из 5 угадано
mysql_query("UPDATE `user` SET `nv` = `nv`+'".$summ."' WHERE `id` = '".$pers['id']."'");
}
function pay_for_4($summ){// оплата если 4 из 5 угадано
mysql_query("UPDATE `user` SET `nv` = `nv`+'".$summ."' WHERE `id` = '".$pers['id']."'");
}
function pay_for_3($summ){// оплата если 3 из 5 угадано
mysql_query("UPDATE `user` SET `nv` = `nv`+'".$summ."' WHERE `id` = '".$pers['id']."'");
}
function pay_for_klan($summ){
mysql_query("UPDATE `user` SET `nv` = `nv`+'".$summ."' WHERE `id` = '10000'");
}
function buy_ticket($selected_str){
$selected_str = substr($selected_str,0,strlen($selected_str)-1);
$selected_array = explode(',',$selected_str);
sort($selected_array);
if (sizeof($selected_array)> 5){
mysql_query("INSERT INTO `lottery_cheaters` (`id_user`,`values`,`date`) VALUES ('1','1','1');");
}
for($i=0;$i<5;$i++){
$values .= $selected_array[$i].',';
}
$res = mysql_query("SELECT `id` FROM `lottery` WHERE `end` = '0'");
while($result_lottery = mysql_fetch_assoc($res)){
$id_lottery = $result_lottery['id'];
}
$this->buy("Тираж № ".$id_lottery."<BR>Выбраные номера: ".$values);
if($this->mess != null) {
return "<font color=red><B>".$this->mess."</font></b>";
}
echo "<font color=red><B>Билет куплен.<BR></font></b>";
$date = date('Y-m-d H:i:s');
mysql_query("INSERT INTO `lottery_log` (`id_user`,`values`,`date`,`id_lottery`) VALUES ('".$id_user."','".$values."','".$date."','".$id_lottery."');");
$jackpot = 0;
$sql = mysql_query("SELECT * FROM `lottery` WHERE `end` = '0' LIMIT 1;");
while($result = mysql_fetch_assoc($res)){
$id = $result['id'];
$jackpot = $result['jackpot'];
$fond = $result['fond'];
}
$fond += 0.7;
mysql_query("UPDATE `lottery` SET `fond` = '".$fond."' WHERE `id` = '".$id."'");
}
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].',';
}
$res = mysql_query("SELECT * FROM `lottery` WHERE `end` = '0'");
while($result = mysql_fetch_assoc($res)){
$id_lottery = $result['id'];
$jackpot = $result['jackpot'];
$fond = $result['fond'];
}
mysql_query("INSERT INTO `lottery_win_combination` (`values`,`date`,`id_lottery`) VALUES ('".$win_combination_str."','".date('Y-m-d H:i:s')."','".$id_lottery."');");
$people_5 = 0;
$people_4 = 0;
$people_3 = 0;
$res = mysql_query("SELECT * FROM `lottery_log` WHERE `id_lottery` = '".$id_lottery."'");
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;
}
mysql_query("UPDATE `lottery` SET `end` = '1' and `fond` = '".$fond."' and `summ_5` = '".$summ_5."' and `summ_4` = '".$summ_4."' and `summ_3` = '".$summ_3."' and `count_5` = '".$people_5."' and `count_4` = '".$people_4."' and `count_3` = '".$people_3."' WHERE `id` = '".$id_lottery."'");
$sql = mysql_query("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"))."','".$jackpot."','0','0','0','0','0','0','0','0');");
}
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) {
$res_comb = mysql_fetch_array(mysql_query("SELECT * FROM `lottery` WHERE `end` = '1' order by id DESC LIMIT 1;"));
$id_lottery = $res_comb['id'];
}
$res_comb = mysql_query("SELECT * FROM `lottery_win_combination` WHERE `id_lottery` = '".$id_lottery."'");
while($result_comb = mysql_fetch_assoc($res_comb)){
$win_combination_str = $result_comb['values'];
}
$res_summ = mysql_query("SELECT * FROM `lottery` WHERE `id` = '".$id_lottery."'");
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'];
}
$res = mysql_query("SELECT * FROM `lottery_log` WHERE `id_lottery` = '".$id_lottery."' and `id_user`='".$id_user."' and `send`='0'");
while($result = mysql_fetch_assoc($res)){
$count = $this->get_count($win_combination_str,$result['values']);
if ($count == 5){
$this->pay_for_5($jackpot);
echo "Билет <B>№ ".$result['id']."</B> выиграл <b>".$jackpot." кр.</b> Выбраные номера: ".$result['values']."<BR>";
$zz = 1;
}
if ($count == 4){
$this->pay_for_4($summ_4);
echo "Билет <B>№ ".$result['id']."</B> выиграл <b>".$summ_4." кр.</b> Выбраные номера: ".$result['values']."<BR>";
$zz = 1;
}
if ($count == 3){
$this->pay_for_3($summ_3);
echo "Билет <B>№ ".$result['id']."</B> выиграл <b>".$summ_3." кр.</b> Выбраные номера: ".$result['values']."<BR>";
$zz = 1;
}
mysql_query("UPDATE `lottery_log` SET `send`='1' WHERE `id` = '".$result['id']."'");
}
if (!$zz) {
echo "<font color=red><B>Нет выигрышных билетов</b></font><BR>";
}
}
function view_results($id_lottery = 0){
$str = '';
if ($id_lottery > 0) {
$res = mysql_query("SELECT * FROM `lottery` WHERE `id` = '".$id_lottery."' and `end`='1'");
}
else {
$res = mysql_query("SELECT * FROM `lottery` WHERE `end`='1' order by id DESC LIMIT 1;");
}
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;
$res_combination = mysql_query("SELECT * FROM `lottery_win_combination` WHERE `id_lottery`='".$id_lottery."'");
while($result_combination = mysql_fetch_assoc($res_combination)){
$combination = $result_combination['values'];
}
$res = mysql_query("SELECT * FROM `lottery_log` WHERE `id_lottery` = '".$id_lottery."'");
$allbillets = mysql_num_rows($res);
$str .= '<form method="post" style="margin:0px;"><h4> Итоги тиража номер <input type="text" value="'.$id_lottery.'" size=4 name="tiraj"> <input type=submit value="посмотреть"></h4></form>';
if (!$date) {
return $str.'Лотерея не проводилась.';
}
$str .= 'Тираж номер: <B>'.$id_lottery.'</B> <br />
Дата: <span class=date>'.$date.'</span> <br />
Призовой фонд: <b>'.$fond.' ER</b> <br />
Джекпот: <b>'.$jackpot.' ER</b> <br />
Всего было продано билетов: <B>'.$allbillets.'</B><br />
Выпала комбинация : <span style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; COLOR: #8f0000; FONT-FAMILY: Arial;">'.substr($combination,0,strlen($combination)-1).'</span> <br />
<table border=1 cellspacing=0>
<tr>
<td align=center style="width:150px;"><b>Угадано номеров</b></td>
<td align=center style="width:150px;"><b>Выиграно билетов</b></td>
<td align=center style="width:150px;"><b>Сумма выиграша</b></td>
</tr>
<tr>
<td align=center>5</td>
<td align=center>'.$count_5.'</td>
<td align=center>
';
if ($count_5 == 0){
$str .= 'Не выиграл ни один билет <BR>'.$summ_5.' ER идут в джекпот';
}
else{
$str .= $summ_5.' ER';
}
$str .= '
</td>
</tr>
<tr>
<td align=center>4</td>
<td align=center>'.$count_4.'</td>
<td align=center>
';
if ($count_4 == 0){
$str .= 'Не выиграл ни один билет <BR>'.$summ_4.' ER идут в джекпот';
}
else{
$str .= $summ_4.' кр.';
}
$str .= '
</td>
</tr>
<tr>
<td align=center>3</td>
<td align=center>'.$count_3.'</td>
<td align=center>
';
if ($count_3 == 0){
$str .= 'Не выиграл ни один билет <BR>'.$summ_3.' ER идут в джекпот';
}
else{
$str .= $summ_3.' кр.';
}
$str .= '
</td>
</tr>
</table>
<br />
Всего победителей: <b>'.$count.'</b> <br />
Всего выиграно: <b>'.$summ.' ER</b> <br />
';
return $str;
}
function view_buy_ticket(){
$str = '';
$str .= '
<style>
td.select{ width: 20px; text-align: center; background-color: #999; cursor: pointer; }
td.unselect{ width: 20px; text-align: center; background-color: none; cursor: pointer; }
</style>
<script>
function add(name){
var array = new Array();
var test = document.getElementById(\'value\').value;
if (test.indexOf(",") > 0){
array = test.split(",");
//alert(array.lenght);
if (array[5] != \'\'){
document.getElementById(name).className=\'select\';
document.getElementById(name).onclick = function() { del(name) };
test = test + name + ",";
document.getElementById(\'value\').value = test;
}
else{
alert(\'Вы выбрали уже 5 номеров. Снимите выделение с любого номера.\');
}
}
else{
document.getElementById(name).className=\'select\';
document.getElementById(name).onclick = function() { del(name) };
test = test + name + ",";
document.getElementById(\'value\').value = test;
}
}
function del(name){
var array = new Array();
var test = document.getElementById(\'value\').value;
document.getElementById(name).className=\'unselect\';
document.getElementById(name).onclick = function() { add(name) };
test = test.replace(name+",","");
document.getElementById(\'value\').value = test;
}
</script>
<table style="background-color: #ccc">
<tr>
<td class="unselect" id="1" onclick="add(\'1\')">1</td>
<td class="unselect" id="2" onclick="add(\'2\')">2</td>
<td class="unselect" id="3" onclick="add(\'3\')">3</td>
<td class="unselect" id="4" onclick="add(\'4\')">4</td>
<td class="unselect" id="5" onclick="add(\'5\')">5</td>
</tr>
<tr>
<td class="unselect" id="6" onclick="add(\'6\')">6</td>
<td class="unselect" id="7" onclick="add(\'7\')">7</td>
<td class="unselect" id="8" onclick="add(\'8\')">8</td>
<td class="unselect" id="9" onclick="add(\'9\')">9</td>
<td class="unselect" id="10" onclick="add(\'10\')">10</td>
</tr>
<tr>
<td class="unselect" id="11" onclick="add(\'11\')">11</td>
<td class="unselect" id="12" onclick="add(\'12\')">12</td>
<td class="unselect" id="13" onclick="add(\'13\')">13</td>
<td class="unselect" id="14" onclick="add(\'14\')">14</td>
<td class="unselect" id="15" onclick="add(\'15\')">15</td>
</tr>
<tr>
<td class="unselect" id="16" onclick="add(\'16\')">16</td>
<td class="unselect" id="17" onclick="add(\'17\')">17</td>
<td class="unselect" id="18" onclick="add(\'18\')">18</td>
<td class="unselect" id="19" onclick="add(\'19\')">19</td>
<td class="unselect" id="20" onclick="add(\'20\')">20</td>
</tr>
<tr>
<td class="unselect" id="21" onclick="add(\'21\')">21</td>
<td class="unselect" id="22" onclick="add(\'22\')">22</td>
<td class="unselect" id="23" onclick="add(\'23\')">23</td>
<td class="unselect" id="24" onclick="add(\'24\')">24</td>
<td class="unselect" id="25" onclick="add(\'25\')">25</td>
</tr>
<tr>
<td class="unselect" id="26" onclick="add(\'26\')">26</td>
<td class="unselect" id="27" onclick="add(\'27\')">27</td>
<td class="unselect" id="28" onclick="add(\'28\')">28</td>
<td class="unselect" id="29" onclick="add(\'29\')">29</td>
<td class="unselect" id="30" onclick="add(\'30\')">30</td>
</tr>
</table>
Выбраные Вами номера : <input style="border: 0px solid #000; background:transparent;" type="text" readonly="true" id="value" name="value" />
';
return $str;
}
}
$Lottery = new Lottery();
if ($_GET['startlotery'] == '648gjn6f6734h798h2q398fgsdhnit734whf784whfy7w8jfyw8hg745g3y75h7f23785yh382') {
$Lottery->get_win_combination();
}
if ($_POST['value']) {
echo $Lottery->buy_ticket($_POST['value']);
}
$res = mysql_query("SELECT * FROM `lottery` WHERE `end`='0' order by id DESC LIMIT 1;");
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'];
}
?>
Следующий тираж <B>№ <?=$id_lottery?></B> состоится <span class=date><?=$date?></span> <BR>
Призовой фонд: <b><?=$fond?> ER.</b> <br />
Джекпот: <b><?=$jackpot?> ER.</b> <br />
Стоимость лотерейного билета: <B>100.00 ER.</B><BR><BR>
<input type="button" value="Купить лотерейный билет" onClick="document.all['adde'].style.visibility='visible';document.all['adde'].style.display='block';">
<div style="display:none;visivility:hidden;" id="adde">
<h4>Выберите 5 номеров</h4>
<form method='post' style="margin:0px;">
<? echo $Lottery->view_buy_ticket(); ?>
<BR><input type=submit value='Купить билет'></form></div>
<BR>
<input type="button" value="Проверить лотерейные билеты" onClick="location.href='?check=1';">
<BR>
<?
if($_GET['check']) {
$Lottery->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")
?>
Скрипт вроде нормально переписал. Но возник вопрос.
PHP:
function buy_ticket($selected_str){
$selected_str = substr($selected_str,0,strlen($selected_str)-1);
$selected_array = explode(',',$selected_str);
sort($selected_array);
if (sizeof($selected_array)> 5){
mysql_query("INSERT INTO `lottery_cheaters` (`id_user`,`values`,`date`) VALUES ('1','1','1');");
}
for($i=0;$i<5;$i++){
$values .= $selected_array[$i].',';
}
$res = mysql_query("SELECT `id` FROM `lottery` WHERE `end` = '0'");
while($result_lottery = mysql_fetch_assoc($res)){
$id_lottery = $result_lottery['id'];
}
$this->buy("Тираж № ".$id_lottery."<BR>Выбраные номера: ".$values);
if($this->mess != null) {
return "<font color=red><B>".$this->mess."</font></b>";
}
echo "<font color=red><B>Билет куплен.<BR></font></b>";
$date = date('Y-m-d H:i:s');
mysql_query("INSERT INTO `lottery_log` (`id_user`,`values`,`date`,`id_lottery`) VALUES ('".$id_user."','".$values."','".$date."','".$id_lottery."');");
$jackpot = 0;
$sql = mysql_query("SELECT * FROM `lottery` WHERE `end` = '0' LIMIT 1;");
while($result = mysql_fetch_assoc($res)){
$id = $result['id'];
$jackpot = $result['jackpot'];
$fond = $result['fond'];
}
$fond += 0.7;
mysql_query("UPDATE `lottery` SET `fond` = '".$fond."' WHERE `id` = '".$id."'");
}
function buy_ticket($selected_str){
$selected_str = substr($selected_str,0,strlen($selected_str)-1);
$selected_array = explode(',',$selected_str);
sort($selected_array);
За что отвечает этот код работы. Может кто подскажет.