Home > Backend Development > PHP Tutorial > PHP points redemption interface example_php skills

PHP points redemption interface example_php skills

怪我咯
Release: 2023-03-13 22:08:02
Original
3381 people have browsed it

Many websites have this function of points. When the points accumulate to a certain amount, you can use these points to redeem something. This article mainly introduces the PHP points redemption interface and analyzes the points redemption interface with examples. Logical processing and database operation tips, friends in need can refer to it,The specific implementation method is as follows:

exchange.php The interface content is as follows:

<?php  
  
/*session_start(); 
if(!isset($_SESSION[&#39;zaszh_user_id&#39;])){ 
    echo json_encode(array(&#39;status&#39;=>&#39;error&#39;,&#39;msg&#39;=>&#39;连接超时,请重新打开页面。&#39;)); 
    exit; 
} 
$user_id = $_SESSION[&#39;zaszh_user_id&#39;];*/  
  
$user_id = 1; // 测试用  
$exchange_points = intval($_GET[&#39;exchange_points&#39;]);  
  
require(&#39;connect_database.php&#39;);  
// 扣除答题积分  
$mysqli->query("update zaszh_user set answer_points=answer_points-{$exchange_points} where id=&#39;{$user_id}&#39; 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(&#39;{$user_id}&#39;,&#39;5元话费&#39;,unix_timestamp(now()))");  
                if($mysqli->affected_rows){  
                    echo json_encode(array(&#39;status&#39;=>&#39;success&#39;,&#39;msg&#39;=>&#39;5元话费&#39;));  
                }else{  
                    // 获奖失败  
                }  
            }else{  
                // 无剩余  
                // 恢复答题积分  
                $mysqli->query("update zaszh_user set answer_points=answer_points+{$exchange_points} where id=&#39;{$user_id}&#39;");  
            }  
            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(&#39;{$user_id}&#39;,&#39;10元话费&#39;,unix_timestamp(now()))");  
                if($mysqli->affected_rows){  
                    echo json_encode(array(&#39;status&#39;=>&#39;success&#39;,&#39;msg&#39;=>&#39;10元话费&#39;));  
                }else{  
                    // 获奖失败  
                }  
            }else{  
                // 无剩余  
                // 恢复答题积分  
                $mysqli->query("update zaszh_user set answer_points=answer_points+{$exchange_points} where id=&#39;{$user_id}&#39;");  
            }  
            break;  
    }  
  
    // 记录积分消耗  
    $mysqli->query("insert into zaszh_answer_points_consume(user_id,points_consume,consume_for,create_date) values(&#39;{$user_id}&#39;,&#39;{$exchange_points}&#39;,&#39;exchange&#39;,unix_timestamp(now()))");  
}else{  
    // 无积分  
    echo json_encode(array(&#39;status&#39;=>&#39;error&#39;,&#39;msg&#39;=>&#39;您的积分不足。&#39;));  
}  
$mysqli->close();
Copy after login

The above is the detailed content of PHP points redemption interface example_php skills. For more information, please follow other related articles on the PHP Chinese website!

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