ThinkPHP continuous check-in small case

ThinkPHP continuous check-in small case

When you are doing website development, have you encountered members who sign in continuously to give points? For example, I have a rule for adding points for continuous sign-in, so when we implement this function, we face some problems. A few points to note:

(1) Continuous check-in, the number of times must be accumulated, which involves the judgment between two timestamps

(2) Whether it is the sign-in of this month, of course, if this is the case, the two timestamp judgments will also be resolved, but also pay attention to this place

(3) Add 1 continuously, otherwise clear to 0, and also generate a check-in record if there is no check-in before!

Below I will post a piece of sign-in implementation code, welcome everyone to make progress and study together! Table Structure

/**The realization of continuous sign-in*/
     public function signList(){
        /**Check if there is this user first*/
         $m_id = $_GET['m_id'];
         $sign = D('Sign')->where(array("m_id"=>$m_id))->limit(0)->find();
        /**If there is, judge the time difference, and then deal with the number of check-ins*/
         if($sign){
            /**Yesterday's timestamp time range*/
             $t = time();
             $last_start_time = mktime(0,0,0,date("m",$t),date("d",$t)-1,date("Y",$t));
             $last_end_time = mktime(23,59,59,date("m",$t),date("d",$t)-1,date("Y",$t));
            /**Today's timestamp time range*/
//$now_start_time = mktime(0,0,0,date("m",$t),date("d",$t),date("Y",$t));
//$now_end_time = mktime(23,59,59,date("m",$t),date("d",$t),date("Y",$t));
            /** Determine whether the last check-in time is within the time range of yesterday*/
             if($last_start_time<$sign['time']&&$sign['time']<$last_end_time){
                 $da['time'] = time();
                 $da['count'] = $sign['count']+1;
                /**Here can also add some operations to judge whether to sign in for a few days and then add points etc.*/
                 D('Sign')->where(array("m_id"=>$m_id))->save($da);
             }else{
                    /**Return to the operation that has been checked in*/
                     $da['time'] = time();
                     $da['count'] = 0;
                     D('Sign')->where(array("m_id"=>$m_id))->save($da);
             }
         }else{
             $data['m_id'] = $m_id;
             $data['time'] = time();
             $data['sign'] = 1;
             $res = D("Sign")->add($data);
             if($res){
                /**Return on success, or process some programs, such as adding points*/
             }
         }}
Reference: https://cloud.tencent.com/developer/article/1055995 ThinkPHP continuous check-in small case-Cloud + Community-Tencent Cloud