This article mainly introduces the PHP point redemption interface. The instance analyzes the logic processing and database operation skills of the Point redemption interface. For more information, see
This article mainly introduces the PHP point redemption interface. The instance analyzes the logic processing and database operation skills of the Point redemption interface. For more information, see
This article describes how to implement the PHP point redemption interface. Share it with you for your reference. The specific implementation method is as follows:
The content of the exchange. php interface is as follows:
The Code is as follows:
<? Php
/* Session_start ();
If (! Isset ($ _ SESSION ['zaszh _ user_id ']) {
Echo json_encode (array ('status' => 'error', 'msg '=>' the connection times out. Open the page again. '));
Exit;
}
$ User_id = $ _ SESSION ['zaszh _ user_id ']; */
$ User_id = 1; // used for testing
$ Exchange_points = intval ($ _ GET ['exchange _ points ']);
Require ('connect _ database. php ');
// Deduct answer points
$ Mysqli-> query ("update zaszh_user set answer_points = answer_points-{$ exchange_points} where and answer_points >={ $ exchange_points }");
If ($ mysqli-> affected_rows ){
// Points
Switch ($ exchange_points ){
// Fee of 5 yuan
Case 200:
$ 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
// Restore the answer points
$ Mysqli-> query ("update zaszh_user set answer_points = answer_points + {$ exchange_points} where ");
}
Break;
// Fee of 10 yuan
Case 400:
$ 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
// Restore the answer points
$ Mysqli-> query ("update zaszh_user set answer_points = answer_points + {$ exchange_points} where ");
}
Break;
}
// Record credit 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 (array ('status' => 'error', 'msg '=>' Your points are insufficient. '));
}
$ Mysqli-> close ();
I hope this article will help you with php programming.