PHP turntable lottery interface instance _ PHP Tutorial

Source: Internet
Author: User
PHP turntable lottery interface instance. PHP turntable lottery interface instance this article mainly introduces the implementation method of the PHP turntable lottery interface. the instance analyzes the implementation principle of the random lottery interface and the corresponding database operation skills, required PHP turntable lottery interface instance

This article mainly introduces the implementation of the PHP turntable lottery interface. The example analyzes the implementation principle of the random lottery interface and the corresponding database operation skills. For more information, see

This article describes how to implement the PHP turntable lottery interface. Share it with you for your reference. The details are as follows:

The turntable lottery here returns a turntable angle at random, and the probability can be defined by yourself.

The lottery_get.php interface file is as follows:

The code is as follows:

/* Session_start ();
If (! Isset ($ _ SESSION ['zaszh _ user_id ']) {
Echo json_encode (array ('status' => 'error', 'MSG '=>' connection timeout. open the page again. '));
Exit;
}
$ User_id = $ _ SESSION ['zaszh _ user_id ']; */

$ User_id = 1; // used for testing

// Turntable area
$ Arr_area = array (
'0' => array ('min _ Ange' => 1, 'max _ Ange' => 45, 'prize' => 'Xiaomi '),
'1' => array ('min _ Ange' => 46, 'max _ Ange' => 90, 'prize' => 'Polaroid '),
'2' => array ('min _ Ange' => 91, 'max _ Ange' => 135, 'prize' => '10 yuan phone '),
'3' => array ('min _ Ange' => 136, 'max _ Ange' => 180, 'prize' => '5 yuan phone '),
'4' => array ('min _ Ange' => 181, 'max _ Ange' => 225, 'prize' => 'thank you for participating '),
'5' => array ('min _ Ange' => 226, 'max _ angs' => 270, 'prize' => 'thank you for participating '),
'6' => array ('min _ Ange' => 271, 'max _ Ange' => 315, 'prize' => 'thank you for participating '),
'7' => array ('min _ Ange' => 316, 'max _ angs' => 360, 'prize' => 'thank you for participating ')
);

// Select a region
$ Area_selected = array ();
// Random extraction
$ Num_rand = mt_rand (1, 10 );
Switch ($ num_rand ){
// Xiaomi
Case 1: $ area_selected = $ arr_area [0]; break;
// Stand out
Case 2: $ area_selected = $ arr_area [1]; break;
// Fee of 10 yuan
Case 3: $ area_selected = $ arr_area [2]; break;
// Fee of 5 yuan
Case 4: $ area_selected = $ arr_area [3]; break;
// Thank you for your participation
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 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 ){
// Points
// Record credit 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 = 'Xiaomi 'and surplus> 0 ");
If ($ mysqli-> affected_rows ){
// Remaining
$ Mysqli-> query ("insert into zaszh_award (user_id, prize, create_date) values ('{$ user_id}', 'Xiaomi ', unix_timestamp (now ()))");
If ($ mysqli-> affected_rows ){
Echo json_encode (array ('status' => 'success', 'MSG '=> 'Xiaomi '));
} Else {
// Failed to win
}
} Else {
// No surplus
}
Break;
Case 'Polaroid ':
$ Mysqli-> query ("update zaszh_prize_surplus set surplus = surplus-1 where prize = 'Polaroid 'and surplus> 0 ");
If ($ mysqli-> affected_rows ){
// Remaining
$ Mysqli-> query ("insert into zaszh_award (user_id, prize, create_date) values ('{$ user_id}', 'Polaroid ', unix_timestamp (now ()))");
If ($ mysqli-> affected_rows ){
Echo json_encode (array ('status' => 'success', 'MSG '=> 'snapshot '));
} Else {
// Failed to win
}
} Else {
// No surplus
}
Break;
Case '10 yuan phone ':
$ Mysqli-> query ("update zaszh_telephone_charge_surplus set charge_surplus = charge_surplus-10 where date = substring (now (),) and charge_surplus> = 10 ");
If ($ mysqli-> affected_rows ){
// Remaining
$ Mysqli-> query ("insert into zaszh_award (user_id, prize, create_date) values ('{$ user_id}', '10 yuan phone bill ', unix_timestamp (now ())) ");
If ($ mysqli-> affected_rows ){
Echo json_encode (array ('status' => 'success', 'MSG '=> '10 yuan phone '));
} Else {
// Failed to win
}
} Else {
// No surplus
}
Break;
Case '5 yuan phone ':
$ Mysqli-> query ("update zaszh_telephone_charge_surplus set charge_surplus = charge_surplus-5 where date = substring (now (),) and charge_surplus> = 5 ");
If ($ mysqli-> affected_rows ){
// Remaining
$ Mysqli-> query ("insert into zaszh_award (user_id, prize, create_date) values ('{$ user_id}', '5 yuan phone bill ', unix_timestamp (now ())) ");
If ($ mysqli-> affected_rows ){
Echo json_encode (array ('status' => 'success', 'MSG '=> '5 yuan phone '));
} Else {
// Failed to win
}
} Else {
// No surplus
}
Break;
Default:
Echo json_encode (array ('status' => 'success', 'MSG '=> 'Thank you for participating '));
}
} Else {
// No points
Echo json_encode (array ('status' => 'error', 'MSG '=>' your points are insufficient. '));
}
$ Mysqli-> close ();

I hope this article will help you with php programming.

This article introduces how to implement the PHP turntable lottery interface. the instance analyzes the implementation principle of the random lottery interface and the corresponding database operation skills...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.