<?php
/**
* 用户签到
*/
namespace app\index\controller;
use app\common\controller\Frontend;
use app\index\controller\Common as Base;
use think\Db;
use think\Session;
class ClickSign extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = '';
public function index()
{
$user_id = 1;
$data = Db::name('web_news')->where('status',2)->order('weigh desc')->field('id,title,memo,createtime,image')->select();
$qiandao_array = Db::name('integral_setup')->field('day_checkin,three_day,seven_day,fifteen_day,twenty_five_day,thirty_day')->find(1);
//获取今日签到状态
$res_status = $this->check_day_qiandao($user_id);
//获取本月签到次数
$month_count = $this->check_month_day($user_id);
//获取今天签到能获取到的积分
$day_jifen = $this->check_continuous_qiandao($user_id,$month_count);
return $this->view->fetch('',[
'data'=>$data,
'res_status'=>$res_status,
'month_count'=>$month_count,
'day_jifen' => $day_jifen,
'qiandao_array'=>$qiandao_array
]);
}
public function info(){
$id = $_GET['id'];
$data = Db::name('web_news')->field('id,title,content,createtime,image')->find($id);
return $this->view->fetch('',[
'data'=>$data
]);
}
//用户签到
public function qiandao(){
$user_id = 1;
$this->del_qiandao($user_id);
$day_check = $this->check_day_qiandao($user_id);
if(true == $day_check){
return Rjson('202','您今天已经签到过了');
}else{
//添加今日签到数据
//检查昨天是否有签到过,如果有,则为连续签到,根据签到规则,设置相对应积分
//获取签到积分和连续签到积分
// $yestaday = $this->getLastTime(1,'before');
//验证昨天是否签到
$check_before_qiandao = $this->check_qiandao($user_id);
//为false 则昨天没有签到
//为true 昨天有签到
//获取用户签到最大和连续签到时间
$user = new \app\index\model\User();
$member_info = $user->get($user_id);
//获取签到积分
Db::startTrans();
try {
//说明昨天有签到,则获取连续签到天数
$add_day = $this->check_month_day($user_id)+1;
if($check_before_qiandao == true){
//签到成功后+1
//更新连续签到次数
$member_info->save(['continuity_day'=>$add_day],['id'=>$user_id]);
}else{
//签到成功后+1
//则连续签到时间改为1
$member_info->save(['continuity_day'=>1],['id'=>$user_id]);
}
//更新积分
//如果连续签到天数,大于最大签到次数,则更新最大签到天数
if( $add_day > intval($member_info['max_days'])){
$member_info->save(['max_days'=>
thinkphp5签到功能获取奖励
最新推荐文章于 2024-04-25 18:29:19 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)