A lot of sites have this function of points, when the points accumulated to a certain amount, you can use these points to redeem some things, This article mainly introduces the PHP integral Exchange interface, the example analyzes the integration of the conversion interface logic processing andDatabase operations skills that need a friend can refer to the next, The implementation method is as follows:
The exchange.php interface contents are 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 '); 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 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) {//has the remaining $mysqli->query ("INSERT INTO Zaszh_award (user_id , prize,create_date) VALUES (' {$user _id} ', ' 5 dollars ', Unix_timestamp (now ())); if ($mysqli->aFfected_rows) {echo json_encode (' status ' = ' success ', ' msg ' = ' $5 phone ') '); }else{//Award failed}}else{//No surplus//recovery answer The problem integral $mysqli->query ("Update zaszh_user set answer_points=answer_points+{$exchange _points} where id= ' {$u SER_ID} ' "); } break; 10 Yuan Phone Case: $mysqli->query ("Update zaszh_telephone_charge_surplus set Charge_surplus=charg E_SURPLUS-10 where Date=substring (now (), 1,10) and charge_surplus>=10 "); if ($mysqli->affected_rows) {//has the remaining $mysqli->query ("INSERT INTO Zaszh_award (user_id , prize,create_date) VALUES (' {$user _id} ', ' 10 dollars ', Unix_timestamp (now ())); if ($mysqli->affected_rows) {echo json_encode (' status ' = ' success ', ' msg ' = ' $10 phone ') '); }else{ Award failed}}else{//No remaining//recovery answer points $ Mysqli->query ("Update zaszh_user set answer_points=answer_points+{$exchange _points} where id= ' {$user _id} '"); } break; }//Record integral consumption $mysqli->query ("INSERT INTO Zaszh_answer_points_consume (User_id,points_consume,consume_for,crea Te_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 ();