PHP Points Redemption Interface instance, PHP Redeem Example _php Tutorial

Source: Internet
Author: User

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 ...

  • 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.