首页 > 其他 > 详细

原生的签到功能实现

时间:2022-05-27 22:00:10      阅读:6      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>sign</title>
</head>
<body>
<center>
    <input type="text" name="username">
    <button>签到</button><span id=span></span>
    <div>
        <table id="box" border="1"></table>
    </div>
</center>
</body>
</html>
<script src="jquery.1.12.min.js"></script>
<script>
    $(function(){
        $(button).click(function(){
            var username=$(:text).val();
            $.ajax({
                type:post,
                url:admin.php,
                data:{username:username},
                dataType:json,
                success:function(res){
                    if(res.success==1){
                        $(#span).html(签到成功);
                        var str=<tr><td>用户名</td><td>连续签到天数</td><td>总积分</td></tr>;
                        str+=<tr><td>+res.msg.username+</td><td>+res.msg.count+</td><td>+res.msg.point+</td></tr>;
                        $(#box).html(str);
                    }
                }
            })
        });
    })
</script>
<?php


require_once (./pdo.php);
$username=1;
$param = [
];
$mypdo = Mypdo::getInstance($param);
//var_dump($mypdo);die;
$sqlQuery="select * from `user_point` where uid={$username}";
$row=$mypdo->fetchRow($sqlQuery);
//var_dump($row);
if($row){
    $sign_time=$row[sign_time];
    $sign_time=strtotime($sign_time);
    $int=date(Y-m-d);
    $int=strtotime($int);//5
    $ints=$int+86400;  //6
    $int_s=$int-86400;  //4
    //当天已签到
    if($int<$sign_time&&$sign_time<$ints){
        // echo ‘您已签到‘;
    }
    //昨天未签到,积分,天数在签到修改为1
    if($sign_time<$int_s) {
        $count = 1;
        $point = 1;
        $sign_time = date(Y-m-d H:s:i);
        $sqlRow = "update user set count=‘$count‘,point=‘$point‘,sign_time=‘$sign_time‘ where username=‘$username‘";
        $res = $mypdo->exec($sqlRow);
        // echo ‘签到成功修改为1‘;
    }
    //请签到
    if($int_s<$sign_time&&$sign_time<$int){
        $count=$row[count]+1;
        $point=$row[point]+1;
        $sign_time=date(Y-m-d H:s:i);
        $sqlupdate="update user set count=‘$count‘,point=‘$point‘,sign_time=‘$sign_time‘ where username=‘$username‘";
        $res=$pdo->exec($sqlupdate);
        // echo ‘签到成功+1‘;
    }
}else{
    $count=1;
    $point=1;
    $sign_time=date(Y-m-d H:s:i);
    $sqlAdd="insert into user_point values (null,‘$username‘,‘$count‘,‘$point‘,‘$sign_time‘)";
    $res=$mypdo->exec($sqlAdd);
    // echo ‘恭喜你签到成功----1‘;
}
$sqlEnd="select * from user where username=‘$username‘";
$info=$pdo->query($sqlEnd)->fetch(PDO::FETCH_ASSOC);
echo json_encode(array(success=>1,msg=>$info));die;

 

原生的签到功能实现

原文:https://www.cnblogs.com/xiaoyantongxue/p/15343310.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!