PHP Points Redemption interface Example _php tips

Source: Internet
Author: User
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 ();

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.