PHP point redemption interface instance

Source: Internet
Author: User
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 about how to implement the PHP point redemption interface, see the example in this article. 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 '=>' connection timeout. 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 id = '{$ user_id}' 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 id = '{$ user_id }'");
}
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 id = '{$ user_id }'");
}
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.

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.