隐藏侧栏
Beta
转载

php设计 点击签到,补签,补签卡设计,签到获取连签天数,连签获取奖励

     订阅 php知识     2022-07-24 19:17     blog.csdn.net     网络转载     41     0     1     1     2022-07-24 19:20
destoon程序前端开发教程
学习要点:请用代码测试

PHP

    public function sign__log(){
        $user = $this->auth->getUser();
        $time = $this->request->param('time');
        $year = date('Y',time());
        $month = date('m',time());
        $day = date('d',time());
        $days = date("t"); 
        $where = [
            'year' => $year,
            'month' => $month,
            'day' => $time,
        ];
        $is_sgin = Db::name('sign_log')->where($where)->find();
        if($is_sgin){
            $this->error('已经签过到了');
        }
        
        $sign_log = [
            'user_id' => $user['id'],
            'year' => $year,
            'month' => $month,
            'day' => $time,
            'createtime' => time(),
        ];
        if($time <= $day){
            if($time < $day){
                // 是否有补签卡
                if($user['signature_num'] <= 0){
                    $this->error('抱歉,您暂时没有可用的补签次数');
                }
                // 减去补签卡次数
                Db::name('user')->where('id',$user['id'])->setDec('signature_num');

                // 是补签
                $sign_log['is_repair'] = 1;
                $memo = '补签获得';
            }else{
                $sign_log['is_repair'] = 0;
                $memo = '签到获得';
            }

            // 签到 sign_log
           
            Db::name('sign_log')->insert($sign_log);
            $i = $this->exticle();
            // 签到送积分
            //根据$i是连续签到的第几天进行分发奖励
            $give_score = 获得的积分数量; 
            // 存入积分表,加上积分
            $saveuser['score'] = $user['score'] + $give_score;
            $user_score_log = [
                'user_id' => $user['id'],
                'score' => $give_score,
                'before' => $user['score'],
                'after' => $user['score'] + $give_score,
                'memo' => $memo,
                'createtime' => time(),
            ];
            Db::name('user_score_log')->insert($user_score_log);
            //存入
            $saveuser['count_sign'] = $user['count_sign'] + 1;
            if($user['continuity_sign'] != $i){
                $saveuser['continuity_sign'] = $i;
            }
            Db::name('user')->where('id',$user['id'])->update($saveuser);
            if($time < $day){
                $this->success('恭喜您,补签成功!',$i);
            }else{
                $this->success('恭喜您,签到成功!',$i);
            }
        }else{
            $this->error('还没有到日期哦');
        }
        
    }
    //获取连签的天数
    public function exticle(){
        $user = $this->auth->getUser();
        $year = date('Y',time());
        $month = date('m',time());
        // $month = 5;
        $day = date('d',time());
        // $day = 31;
        $thismonth = Db::name('sign_log')->field('day')->where(array('user_id'=>$user['id'],'year'=>$year,'month'=>$month))->order('day DESC')->select();
        foreach($thismonth as $v){
            $touch[] = $v['day'];
        }
        // var_dump($touch);exit;
        if(count($thismonth) != 0){
            if(count($touch) > 2){
                if(in_array($day,$touch) || in_array($day-1,$touch)){
                    // 今天 
                    for ($x=0; $x<count($touch)-1; $x++) {
                        if($touch[$x] - $touch[$x+1] > 1){
                            $i = $x + 1;
                        }
                    } 
                    if(!isset($i)){
                        $i = count($touch);
                    }
                }else{
                    //今天昨天都没有,连签变为0
                    $i = 0;
                }
            }else{
                if(count($touch) == 1){
                    if($touch[0] == $day || $touch[0] == $day-1){
                        $i = 1;
                    }else{
                        $i = 0;
                    }
                }else if(count($touch) == 2){
                    if($touch[0] == $day || $touch[0] == $day-1){
                        if($touch[0] - $touch[1] == 1){
                            $i = 2;
                        }else{
                            $i = 1;
                        }
                    }else{
                        $i = 0;
                    }
                }
            }
        }else{
            $i = 0;
        }
        return $i;
    }


MYSQL表设计

微信扫码查看本文(微信小程序 移动新体验)

微信扫码查看本文(H5移动版)

--结束END--

本文标题: php设计 点击签到,补签,补签卡设计,签到获取连签天数,连签获取奖励

本文链接: https://www.mbkfw.com/course/1093.html (转载时请注明来源链接)

本文来源于网络转载,有问题请发送至: 邮箱/kf@dtmuban.com 进行修改或删除

阅读更多
 
本文标签: 签到 补签 每日 连签 断签

下班PC阅读不方便?

手机也可以随时学习开发

微信关注公众号“商企云服”
"模板开发网前端开发教学"
每日干货技术分享
【ECS精选特惠】新用户上云低至1折起
 
0

圈友点评

文明上网理性发言,请遵守网络评论服务协议

小编推荐


搬运工

助人为乐

勤写标兵

×

《客户实名在线注册登记》售后一直都在!