PHP Points Redemption Interface example, PHP point redemption Example
This paper gives an example of how to implement PHP integral conversion interface. Share to everyone for your reference. The implementation method is as follows:
The exchange.php interface contents are as follows:
Copy CodeThe code is as follows: <?php
/*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
$exchange _points = intval ($_get[' exchange_points ');
Require (' connect_database.php ');
Deduction of answer points
$mysqli->query ("Update zaszh_user set answer_points=answer_points-{$exchange _points} where id= ' {$user _id} ' and answer_points>={$exchange _points} ");
if ($mysqli->affected_rows) {
Have points
Switch ($exchange _points) {
5 Yuan Phone call
Case 200:
$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
Restore Answer points
$mysqli->query ("Update zaszh_user set answer_points=answer_points+{$exchange _points} where id= ' {$user _id} ');
}
Break
10 Yuan Phone call
Case 400:
$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
Restore Answer points
$mysqli->query ("Update zaszh_user set answer_points=answer_points+{$exchange _points} where id= ' {$user _id} ');
}
Break
}
Record points consumption
$mysqli->query ("INSERT into Zaszh_answer_points_consume (user_id,points_consume,consume_for,create_date) values (' {$user _id} ', ' {$exchange _points} ', ' Exchange ', ' Unix_timestamp (now ()) ');
}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/955397.html www.bkjia.com true http://www.bkjia.com/PHPjc/955397.html techarticle PHP point Conversion Interface example, PHP point Redemption Example This article describes the implementation of the PHP integral conversion interface. Share to everyone for your reference. The concrete implementation method is as follows: Exchang ...