This paper illustrates the implementation method of PHP turntable draw interface. Share to everyone for your reference. Specifically as follows:
The turntable lottery here randomly returns a turntable angle, the probability can be defined by itself
The lottery_get.php interface file is as follows:
Copy Code code as follows:
<?php
/*session_start ();
if (!isset ($_session[' zaszh_user_id ')) {
echo json_encode (' status ' => ' Error ', ' msg ' => ' connection timed out, please reopen the page.) '));
Exit
}
$user _id = $_session[' zaszh_user_id '];*/
$user _id = 1; Test with
Turntable area
$arr _area = Array (
' 0 ' => array (' Min_angle ' =>1, ' max_angle ' =>45, ' prize ' => ' Millet '),
' 1 ' => array (' Min_angle ' =>46, ' max_angle ' =>90, ' Prize ' => ' Pat "),
' 2 ' => array (' Min_angle ' =>91, ' max_angle ' =>135, ' Prize ' => ' 10 dollars '),
' 3 ' => array (' Min_angle ' =>136, ' max_angle ' =>180, ' Prize ' => ' 5 dollars '),
' 4 ' => array (' Min_angle ' =>181, ' max_angle ' =>225, ' prize ' => ' Thank you for participating '),
' 5 ' => array (' Min_angle ' =>226, ' max_angle ' =>270, ' prize ' => ' Thank you for participating '),
' 6 ' => array (' Min_angle ' =>271, ' max_angle ' =>315, ' prize ' => ' Thank you for participating '),
' 7 ' => Array (' Min_angle ' =>316, ' max_angle ' =>360, ' prize ' => ' Thank you for participating ')
);
Selected area
$area _selected = Array ();
Random extraction
$num _rand = Mt_rand (1,10);
Switch ($num _rand) {
Millet
Case 1: $area _selected = $arr _area[0]; Break
Pat-Li
Case 2: $area _selected = $arr _area[1]; Break
10 Yuan phone bill
Case 3: $area _selected = $arr _area[2]; Break
5 Yuan phone bill
Case 4: $area _selected = $arr _area[3]; Break
Thanks for joining.
Default
Switch (Mt_rand (1,4)) {
Case 1: $area _selected = $arr _area[4]; Break
Case 2: $area _selected = $arr _area[5]; Break
Case 3: $area _selected = $arr _area[6]; Break
Case 4: $area _selected = $arr _area[7]; Break
}
Break
}
echo $area _selected[' Prize '];
Require (' connect_database.php ');
Deduct the answer points
$mysqli->query ("Update zaszh_user set answer_points=answer_points-5 where id= ' {$user _id} ' and answer_points>=5" );
if ($mysqli->affected_rows) {
Have points
Recording integral consumption
$mysqli->query ("INSERT into Zaszh_answer_points_consume (user_id,points_consume,consume_for,create_date) values (' {$user _id} ', 5, ' lottery ', Unix_timestamp (now)) ");
Switch ($area _selected[' Prize ']) {
Case ' millet ':
$mysqli->query ("Update zaszh_prize_surplus set surplus=surplus-1 where prize= ' millet ' and surplus>0");
if ($mysqli->affected_rows) {
There are surplus
$mysqli->query (INSERT into Zaszh_award (user_id,prize,create_date) VALUES (' {$user _id} ', ' Millet ', Unix_timestamp (now ()))");
if ($mysqli->affected_rows) {
echo json_encode (' status ' => ' success ', ' msg ' => ' millet '));
}else{
Award failure
}
}else{
No surplus
}
Break
Case ' Pat ':
$mysqli->query ("Update zaszh_prize_surplus set surplus=surplus-1 where prize= ' Pat ' and surplus>0");
if ($mysqli->affected_rows) {
There are surplus
$mysqli->query (INSERT into Zaszh_award (user_id,prize,create_date) VALUES (' {$user _id} ', ' Pat ', Unix_timestamp ( Now ()));
if ($mysqli->affected_rows) {
echo json_encode (' status ' => ' success ', ' msg ' => ' Pat '));
}else{
Award failure
}
}else{
No surplus
}
Break
Case ' 10 Yuan charge ':
$mysqli->query ("Update zaszh_telephone_charge_surplus set charge_surplus=charge_surplus-10 where Date=substring ( Now (), 1,10) and charge_surplus>=10 ");
if ($mysqli->affected_rows) {
There are surplus
$mysqli->query ("INSERT INTO Zaszh_award" (user_id,prize,create_date) VALUES (' {$user _id} ', ' $10 bill ', Unix_timestamp ( Now ()));
if ($mysqli->affected_rows) {
echo json_encode (' status ' => ' success ', ' msg ' => ' 10 Yuan Bill '));
}else{
Award failure
}
}else{
No surplus
}
Break
Case ' 5 yuan charge ':
$mysqli->query ("Update zaszh_telephone_charge_surplus set charge_surplus=charge_surplus-5 where Date=substring ( Now (), 1,10) and charge_surplus>=5 ");
if ($mysqli->affected_rows) {
There are surplus
$mysqli->query ("INSERT INTO Zaszh_award" (user_id,prize,create_date) VALUES (' {$user _id} ', ' $5 Bill ', Unix_timestamp ( Now ()));
if ($mysqli->affected_rows) {
echo json_encode (' status ' => ' success ', ' msg ' => ' 5 Yuan Bill '));
}else{
Award failure
}
}else{
No surplus
}
Break
Default
echo json_encode (' status ' => ' success ', ' msg ' => ' Thank you for Participation '));
}
}else{
No points
echo json_encode (' status ' => ' Error ', ' msg ' => ') your points are insufficient. '));
}
$mysqli->close ();
I hope this article will help you with your PHP program design.