简单每日签到实现
签到如YII官方的一样
if(IS_AJAX){
$userid = $_SESSION['username']['id'];
$sign_model = D('sign');
$detail_model = D('user_detail');
$where = array('userid'=>$userid);
$time = date('Y-m-d',time());
$now_time = strtotime($time);
$time_where = array('signtime'=>$now_time);
//判断是否为第一次签到
$res = $sign_model->where($where)->find();
//用户积分情况
$details = $detail_model->where($where)->find();
if(empty($res)){
//第一次签到新增签到表
$data['cta'] = 1;
$data['num'] = 1;
$data['signtime'] = $now_time;
$data['userid'] = $userid;
$sign_model->add($data);
$details['integral'] += 5;
$detail_model->save($details);
//返回连续签到天数
$arr = array(
'status'=>'ok',
'cta'=>1
);
}else{
//已经签到
if($res['signtime']==$now_time){
exit(json_encode(array('status'=>'happened')));
die;
}
//断签
if(($now_time-$res['signtime'])>24*3600){
$res['cta'] = 1;
}else{
//连续签到
$res['cta'] += 1;
}
$res['signtime'] = $now_time;
$res['num'] += 1;
$sign_model->save($res);
//用户连续签到7天
if($res['cta']%7==0){
$details['integral'] += 20;
}else{
$details['integral'] += 5;
}
//返回连续签到天数
$arr = array(
'status'=>'ok',
'cta'=>$res['cta'],
);
}
$detail_model->save($details);
//更新今日有多少人签到
$query = $sign_model->field('sign_id')->where($time_where)->select();
$count = count($query);
//签到总人数
$arr = array_merge($arr,array('count'=>$count));
exit(json_encode($arr));
}