This article describes the implementation of the PHP integral Exchange interface. Share to everyone for your reference. The implementation methods are as follows:
Exchange.php interface contents are 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
$exchange _points = intval ($_get[' exchange_points '));
Require (' connect_database.php ');
Deduct the 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 bill
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) {
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
Restore Answer points
$mysqli->query ("Update zaszh_user set answer_points=answer_points+{$exchange _points} where id= ' {$user _id} '");
}
Break
10 Yuan phone bill
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) {
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
Restore Answer points
$mysqli->query ("Update zaszh_user set answer_points=answer_points+{$exchange _points} where id= ' {$user _id} '");
}
Break
}
Recording integral 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 will help you with your PHP program design.