签到功能表的基本逻辑
1 //今天0点时间 2 $time = strtotime(date('y-m-d')); 3 //昨天0点时间 4 $prevtime = strtotime(date('y-m-d')) - 86400; 5 //明天0点时间 6 $nexttime = strtotime(date('y-m-d')) + 86400; 7 $user_id = 4; 8 $getSian = \app\sign\model\Sign::getSign($user_id); 9 if (empty($getSian)) { 10 $create = [ 11 'user_id' => $user_id, 12 'sign_time' => strtotime(date('y-m-d h:m:s')), 13 'integral' => 200, 14 'day' => 1 15 ]; 16 $addSign = \app\sign\model\Sign::addSign($create); 17 echo '第一次签到'; 18 die(); 19 } 20 //今天是否签到 21 if ($getSian['sign_time'] > $time && $getSian['sign_time'] < $nexttime) { 22 echo '今天已签到'; 23 die(); 24 } 25 //断签 26 if ($getSian['sign_time'] < $prevtime) { 27 $update = [ 28 'id' => $getSian['id'], 29 'user_id' => $getSian['user_id'], 30 'sign_time' => strtotime(date('y-m-d h:m:s')), 31 'integral' => 200, 32 'day' => 1 33 ]; 34 $addSign = \app\sign\model\Sign::updateSign($update); 35 echo '断签重新签到'; 36 die(); 37 } 38 //签到 39 if ($getSian['sign_time'] > $prevtime && $getSian['sign_time'] < $time) { 40 $update = [ 41 'id' => $getSian['id'], 42 'user_id' => $getSian['user_id'], 43 'sign_time' => strtotime(date('y-m-d h:m:s')), 44 'integral' => $getSian['integral'] + 50, 45 'day' => $getSian['day'] + 1 46 ]; 47 $addSign = \app\sign\model\Sign::updateSign($update); 48 echo '连续签到'; 49 die(); 50 }