PHP连续签到
require "./global.php";
$act = isset($_GET['act']) ? $_GET['act'] : "error";
// d($act);
switch($act){
case "qiandao":
$uid = intval($_POST['uid']);
$res = $db -> get('qian_dao','*',array('uid'=>$uid));
// last_query();
$time = time();
//判断今天是否签到
$todayBegin=strtotime(date('Y-m-d')." 00:00:00");
$todayEnd= strtotime(date('Y-m-d')." 23:59:59"); $isexit = $db -> get('qian_dao','id',array('AND'=>array('uid'=>$uid,'qian_dao_time[>=]'=>$todayBegin,'qian_dao_time[<=]'=>$todayEnd)));
// last_query();
if($isexit){
// echo "今天已签到!";
Log::writeLog(print_r(array('state'=>'stop','msg'=>'今天已签到!'),true));
echo json_encode(array('state'=>'stop','msg'=>'今天已签到!'));
exit;
}
if($res){
//存在签到
if((time() - $res['qian_dao_time'] > 24*60*60)){ // 判断时间是否大于24小时
// 让字段归0
$addInfo = $db -> update('qian_dao',array('qian_dao_num'=>1,'qian_dao_time'=>$time),array('uid'=>$uid));
}else{
// 更新签到的天数
$addInfo = $db -> update('qian_dao',array('qian_dao_num[+]'=>1,'qian_dao_time'=>$time),array('uid'=>$uid));
}
}else{
// echo '您还没有签到过';
//没有签到过
$db -> insert('qian_dao',array('uid'=>$uid,'qian_dao_num'=>1,'qian_dao_time'=>$time));
// echo $db ->last_query();
}
// 插入签到记录
$db -> insert('sign',array(
'uid'=>$uid,
'dateline'=>$time,
));
// 获取连续签到的天数
$info = $db -> get('qian_dao','qian_dao_num',array('uid'=>$uid)); echo json_encode(array('state'=>'success','msg'=>"您是第".$info."天签到"));
break;
default :
echo json_encode(array("ret"=>0,"msg"=>"操作不存在!"));
break;
}
sql:
CREATE TABLE IF NOT EXISTS `qian_dao` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`uid` int(1) NOT NULL COMMENT '用户id',
`qian_dao_num` int(11) NOT NULL COMMENT '签到次数',
`qian_dao_time` int(11) NOT NULL COMMENT '签到时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; CREATE TABLE IF NOT EXISTS `sign` (
`uid` int(11) NOT NULL,
`dateline` varchar(10) COLLATE utf8_bin NOT NULL,
KEY `uid` (`uid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
html:
<?php
include './global.php';
$uid = 1;
$todayBegin=strtotime(date('Y-m-d')." 00:00:00");
$todayEnd= strtotime(date('Y-m-d')." 23:59:59");
$isexit = $db -> get('qian_dao','id',array('AND'=>array('uid'=>$uid,'qian_dao_time[>=]'=>$todayBegin,'qian_dao_time[<=]'=>$todayEnd))); $flag = '';
if($isexit){
$flag = 'current';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery制作每天或每日打卡签到特效</title>
<meta name="description" content="jquery制作论坛或社交网站的每日或每天打卡签到特效,点击打卡标签显示打卡签到效果。jquery下载" />
</head> <body> <style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;text-decoration:none;}
/*今日签到*/
.singer{border:1px solid #DCDBDB;padding:10px;height:45px;line-height:45px;width:290px;margin:20px auto;}
.ul{border:1px solid #DCDBDB;padding:0 10px 10px 10px;;width:290px;margin:20px auto;}
.li{border:1px solid #DCDBDB;padding-left:10px;height:25px;line-height:25px;width:280px;margin:10px 0 0 0;}
.singer_l_cont, .singer_r_img{float:left;}
.singer_l_cont{width:145px;background:url(images/sing_per.gif) no-repeat left 12px;text-indent:23px;font-size:12px;}
.singer_r_img{display:block;width:114px;height:52px;background:url(images/sing_week.gif) right 2px no-repeat;vertical-align:middle;float:right;*margin-bottom:-10px;}
.singer_r_img:hover{background-position:right -53px;text-decoration:none;}
.singer_r_img span{margin-left:14px;font-size:16px;font-family:'Hiragino Sans GB','Microsoft YaHei',sans-serif !important;font-weight:700;color:#165379;}
.singer_r_img.current{background:url(images/sing_sing.gif) no-repeat 0 2px;}
</style> <div class="singer">
<div class="singer_l_cont">
<span>每天签到赢取PK币</span>
</div>
<div class="singer_r_r">
<a class="singer_r_img <?php echo $flag;?>" href="#">
<span id="sing_for_number"></span>
</a>
</div>
</div><!--singer end-->
<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript">
/*签到模块日期捕捉:*/
function week(){
var objDate= new Date();
var week = objDate.getDay();
switch(week)
{
case 0:
week="周日";
break;
case 1:
week="周一";
break;
case 2:
week="周二";
break;
case 3:
week="周三";
break;
case 4:
week="周四";
break;
case 5:
week="周五";
break;
case 6:
week="周六";
break;
}
$("#sing_for_number").html( week );
} $(document).ready(function(){
week();
var cache=new Array(); // 缓存变量,当数据被访问过之后放置在缓存中,加快访问速度
$(".singer_r_img").click(function(){
// 如果缓存中存在数据,那么直接从缓存中读取;如果不存在数据,那么就从数据库中读取,并把数据存入缓存
if (typeof(cache['stop'])=='undefined') {
$.ajax({
url:"action.php?act=qiandao",
type:"post",
dataType:'json',
data:{
uid:1,
},
async:false,
success:function(data){
// alert(data.msg);
switch(data.state){
case 'success':
alert(data.msg);
break
case 'stop':
cache['stop'] = data.msg;
alert(data.msg);
break;
}
$(".singer_r_img").addClass("current");
}
})
}else{
alert(cache['stop'])
}
})
})
</script>
</body>
</html>
<?php
// 获取签到记录
$sign = $db -> select('sign','*',array('uid'=>$uid,'ORDER'=>'dateline DESC'));
?>
<ul class='ul'>
<?php
if(empty($sign)){
?>
<li class="li">暂无签到信息</li>
<?php
}else{
foreach($sign as $k=>$v){
?>
<li class="li"><span><?php echo ($k + 1);?></span> <?php echo date('Y-m-d H:i:s',$v['dateline']);?></li>
<?php
}
}
?>
</ul>
PHP连续签到的更多相关文章
- PHP每日签到及连续签到奖励实现示例
数据库字段 num 记录已经连续签到次数 times 记录签到的日期 格式年月日 如 20160101 PHP代码如下 <?php //获取今天的日期 $today = date('Ymd'); ...
- PHP计算连续签到天数以及累计签到天数
代码如下: /** * 统计连续签到天数以及累计签到天数 * @param string $user_long_id 用户ID * @return array 一维数组 */ function sig ...
- sqlserver查询连续签到天数
create table #t(keyId int identity,actionDate datetime)insert into #t(actionDate) select distinct Cr ...
- sql -- 获取连续签到的用户列表
签到表: 需求:统计连续签到的 用户 1.根据用户和日期分组 select user_name, sign_date from user_sign group by user_name, sign_d ...
- msql 计算连续签到天数
刚刚写了一个签到计算天数的sql, 记录下来. 思路如下: 获取当前签到的最后时间(今天或昨天), 定义一个变量@i 对签到时间进行天数自减, 然后查询出当前记录签到时间是否与自减后的时间匹配. ...
- NYOJ题目874签到
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAswAAAIzCAIAAACbd9iBAAAgAElEQVR4nO3dPXLjSNou0G8T8rUQ2V
- PHP+MYSQL+AJAX实现每日签到功能
一.web前端及ajax部分 文件index.html <html> <head> <meta http-equiv=Content-Type content=" ...
- PHP每日签到时怎么实现
以淘宝网领取淘金币的签到系统为例:目标:第一天签到增加5个积分:第二天连续签到则增加8个积分:第三天连续签到,增加11个积分,第 四天连续签到,增加15个积分:第五天连续签到,增加19个积分:第六天连 ...
- WeMall微信商城签到插件Sign的主要源码
WeMall微信商城源码签到插件Sign,用于商城的签到系统,分享了部分比较重要的代码,供技术员学习参考 AdminController.class.php <?php namespace Ad ...
随机推荐
- Local System、Local Service與Network Service
CreateService参数介绍SC_HANDLE CreateService( SC_HANDLE hSCManager, //服务控制管理程序维护的登记数据库的句柄,由系统函数OpenSCMan ...
- 【HDOJ】2492 Ping pong
线段树+离散化. #include <cstdio> #include <cstring> #include <cstdlib> #define MAXN 2000 ...
- centos ppp拨号
CentOS 6.4 电信ADSL 拨号连接的配置,亲测 .下载 rp-pppoe-3.8.tar.gz http://down1.chinaunix.net/distfiles/rp-pppoe-3 ...
- HTML父子页面通信问题(showModalDialog)
1. showModalDialog参数说明 window.showModalDialog(URL, ARGS,Features)(在父窗口中调用打开新的窗口) URL -- 必选 ...
- 利用C++11的function和bind简化类创建线程
问题引出 当在类中需要创建线程时,总是因为线程函数需要定义成静态成员函数,但是又需要访问非静态数据成员这种需求,来做若干重复性的繁琐工作.比如我以前就经常定义一个静态成员函数,然后定一个结构体,结构体 ...
- 局部更新 java web 的文件
方法一:直接更新文件 直接修改部署后的文件.比如用 maven 打包成 WAR 文件,部署(复制)到 Tomcat/webapps 目录后,Tomcat 会立即将 WAR 文件解压成目录结构.此时,只 ...
- linux获取CPU温度
Centos系列 1 yum install lm_sensors 2 sensors-detect 3 sensors Ubuntu系列(多了service module-init-tools st ...
- C++编写ATM(1)
// ATM的初始.cpp : 定义控制台应用程序的入口点. // /************************************************* 运行环境: VS2008 作者 ...
- 执行测试遇到log4j 没有找到日志appenders
log4j:WARN No appenders could be found for logger (com.sshtools.j2ssh.transport.publickey.SshKeyPair ...
- object- c 字符串操作
Objective-C 中核心处理字符串的类是 NSString 与 NSMutableString ,这两个类最大的区别就是NSString 创建赋值以后该字符串的内容与长度不能在动态的更改,除非重 ...