public function signin(){
$user = Db::name('user')->field('id,score,sign_days,last_sign')->where('id',$this->auth->id)->find();
$today = strtotime(date('Y-m-d'));
if($user['last_sign'] == $today){
$this->success('今天已经签到过了');
}else{
if(($user['last_sign'] == strtotime(date("Y-m-d",time()-86400)))){
$add = 0;
$sign_days = $user['sign_days']+1;
if($sign_days%7 == 1) {
$add = getConfig('one');
}elseif($sign_days%7 == 2) {
$add = getConfig('two');
}elseif($sign_days%7 == 3) {
$add = getConfig('three');
}elseif($sign_days%7 == 4) {
$add = getConfig('four');
}elseif($sign_days%7 == 5) {
$add = getConfig('five');
}elseif($sign_days%7 == 6) {
$add = getConfig('six');
}elseif($sign_days%7 == 0) {
$add = getConfig('seven');
}
$signin = ['last_sign'=>strtotime(date('Y-m-d')),'sign_days'=>$sign_days,'score'=>$user['score']+$add];
}else{
$add = getConfig('one');
$signin = ['last_sign'=>strtotime(date('Y-m-d')),'sign_days'=>1,'score'=>$user['score']+$add];
}
$data = [
'user_id' => $this->auth->id,
'date' => $today,
'score' => $add,
'createtime' => time(),
'updatetime' => time()
];
Db::startTrans();
try{
$r1 = Db::name('user')->where('id',$this->auth->id)->update($signin);
$r2 = Db::name('usersign')->insert($data);
if($r1 !== false && $r2){
Db::commit();
$this->success('签到成功',$add);
}else{
Db::rollBack();
$this->error('签到失败');
}
}catch (Exception $e){
Db::rollBack();
$this->error('服务器忙,稍后请重试');
}
}
}
/**
*notes:签到展示
*auther:李耀殿<13592627031@163.com>
*time:2021/12/20 0020下午 5:03
*/
public function signlist(){
$user_sign = Db::name('user')->field('id,score,sign_days,last_sign')->where('id',$this->auth->id)->find();
$user_sign['count'] = DB::name('usersign')->where('user_id',$this->auth->id)->count();
$tod = strtotime(date('Y-m-d'));
if($user_sign['last_sign'] == $tod){
$user_sign['sign'] = 1;
}else{
$user_sign['sign'] = 0;
$sign_day = $user_sign['sign_days']+1;
if($sign_day%7 == 1) {
$user_sign['sign_score'] = getConfig('one');
}elseif($sign_day%7 == 2) {
$user_sign['sign_score'] = getConfig('two');
}elseif($sign_day%7 == 3) {
$user_sign['sign_score'] = getConfig('three');
}elseif($sign_day%7 == 4) {
$user_sign['sign_score'] = getConfig('four');
}elseif($sign_day%7 == 5) {
$user_sign['sign_score'] = getConfig('five');
}elseif($sign_day%7 == 6) {
$user_sign['sign_score'] = getConfig('six');
}elseif($sign_day%7 == 0) {
$user_sign['sign_score'] = getConfig('seven');
}
}
$this->success('查询成功',$user_sign);
}
签到 和 签到展示
最新推荐文章于 2024-11-08 16:00:10 发布