PHP Carousel Draw Interface Example
This article mainly introduces the implementation of the PHP turntable draw interface, the example analysis of the random draw interface implementation principle and the corresponding database operation skills, the need for friends can refer to the next
This paper describes the implementation of the PHP Carousel draw interface. Share to everyone for your reference. Specific as follows:
Here the Carousel lottery randomly returns a turntable angle, the probability can be defined by itself
The lottery_get.php interface files are as follows:
The code is as follows:
/*session_start ();
if (!isset ($_session[' zaszh_user_id ')) {
echo json_encode (' status ' = ' error ', ' msg ' = ' + ' connection timeout, please reopen the page. '));
Exit
}
$user _id = $_session[' zaszh_user_id '];*/
$user _id = 1; For testing
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 Yuan '),
' 3 ' = = Array (' Min_angle ' =>136, ' max_angle ' =>180, ' prize ' = ' 5 Yuan '),
' 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.
Case 2: $area _selected = $arr _area[1]; Break
10 Yuan Phone call
Case 3: $area _selected = $arr _area[2]; Break
5 Yuan Phone call
Case 4: $area _selected = $arr _area[3]; Break
Thank you for participating
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 ');
Deduction of 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
Record points 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 ' Xiaomi ':
$mysqli->query ("Update zaszh_prize_surplus set surplus=surplus-1 where prize= ' millet ' and surplus>0");
if ($mysqli->affected_rows) {
Have 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{
Unsuccessful Award
}
}else{
No remaining
}
Break
Case ' Pat ':
$mysqli->query ("Update zaszh_prize_surplus set surplus=surplus-1 where prize= ' Pat ' and surplus>0 ');
if ($mysqli->affected_rows) {
Have 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{
Unsuccessful Award
}
}else{
No remaining
}
Break
Case ' $10 phone call ':
$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) {
Have surplus
$mysqli->query ("INSERT into Zaszh_award (user_id,prize,create_date) VALUES (' {$user _id} ', ' $10 phone call ', Unix_timestamp ( Now ())) ");
if ($mysqli->affected_rows) {
echo json_encode (' status ' = ' success ', ' msg ' = ' $10 phone ') ';
}else{
Unsuccessful Award
}
}else{
No remaining
}
Break
Case ' $5 phone call ':
$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) {
Have surplus
$mysqli->query ("INSERT into Zaszh_award (user_id,prize,create_date) VALUES (' {$user _id} ', ' $5 phone call ', Unix_timestamp ( Now ())) ");
if ($mysqli->affected_rows) {
echo json_encode (' status ' = ' success ', ' msg ' = ' $5 phone ') ';
}else{
Unsuccessful Award
}
}else{
No remaining
}
Break
Default
echo json_encode (' status ' = ' success ', ' msg ' = ' Thank you '));
}
}else{
No points
echo json_encode (' status ' = ' error ', ' msg ' = ' = ' your points are insufficient. '));
}
$mysqli->close ();
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/956403.html www.bkjia.com true http://www.bkjia.com/PHPjc/956403.html techarticle PHP Carousel Draw Interface Example This article mainly introduces the implementation of the PHP Carousel draw interface, the example analysis of the random draw interface implementation principle and the corresponding database operation skills, need ...