PHP Integral Exchange interface Example _php tips

Source: Internet
Author: User

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.

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.