Home > Backend Development > PHP Tutorial > PHP points redemption interface example, php points redemption example_PHP tutorial

PHP points redemption interface example, php points redemption example_PHP tutorial

WBOY
Release: 2016-07-13 10:07:27
Original
918 people have browsed it

PHP points redemption interface example, php points redemption example

The example in this article describes the implementation method of the PHP points redemption interface. Share it with everyone for your reference. The specific implementation method is as follows:

The exchange.php interface content is as follows:

Copy code The code is as follows:
 
/*session_start();
if(!isset($_SESSION['zaszh_user_id'])){
    echo json_encode(array('status'=>'error','msg'=>'连接超时,请重新打开页面。'));
    exit;
}
$user_id = $_SESSION['zaszh_user_id'];*/ 
 
$user_id = 1; // 测试用 
$exchange_points = intval($_GET['exchange_points']); 
 
require('connect_database.php'); 
// 扣除答题积分 
$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){ 
    // 有积分 
    switch($exchange_points){ 
        // 5元话费 
        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){ 
                // 有剩余 
                $mysqli->query("insert into zaszh_award(user_id,prize,create_date) values('{$user_id}','5元话费',unix_timestamp(now()))"); 
                if($mysqli->affected_rows){ 
                    echo json_encode(array('status'=>'success','msg'=>'5元话费')); 
                }else{ 
                    // 获奖失败 
                } 
            }else{ 
                // 无剩余 
                // 恢复答题积分 
                $mysqli->query("update zaszh_user set answer_points=answer_points+{$exchange_points} where id='{$user_id}'"); 
            } 
            break; 
        // 10元话费 
        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){ 
                // 有剩余 
                $mysqli->query("insert into zaszh_award(user_id,prize,create_date) values('{$user_id}','10元话费',unix_timestamp(now()))"); 
                if($mysqli->affected_rows){ 
                    echo json_encode(array('status'=>'success','msg'=>'10元话费')); 
                }else{ 
                    // 获奖失败 
                } 
            }else{ 
                // 无剩余 
// Restore the 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(array('status'=>'error','msg'=>'You have insufficient points.'));
}
$mysqli->close();
I hope this article will be helpful to everyone’s PHP programming design.

http://www.bkjia.com/PHPjc/955397.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/955397.htmlTechArticlePHP points redemption interface example, php points redemption example This article describes the implementation method of the PHP points redemption interface. Share it with everyone for your reference. The specific implementation method is as follows: exchang...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template