沉浸式阅读
Beta
转载

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

     订阅 PHP     2022-07-24     blog.csdn.net    网络转载    724    0    1    1    2022-07-24
学习要点:请用代码测试

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表设计

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

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

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

特别鸣谢: 如果您觉得本文对您有帮助,请给我们一个小小的赞,收藏本文更利于反复学习哦!

 
destoon程序前端开发标签生成器

下班PC阅读不方便?

手机也可以随时学习开发

微信关注公众号“商企云服”
"模板开发网前端开发教学"
每日干货技术分享
 
0

圈友点评

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


色彩
×

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

关注

微信
关注

微信扫一扫
不同的环境体验

幸运大转盘,好礼等您拿

模板开发网公众号

模板开发网微信小程序

代授权

程序
授权

黑小二

联系
客服

很高兴为您服务
尊敬的用户,欢迎您咨询,我们为新用户准备了优惠好礼。咨询客服

联系客服:

在线QQ: 290948585

客服电话: 18605917465

E_mail邮箱: kf@dtmuban.com

微信公众号: 商企云服

微信小程序: 模板开发

QQ客服 微信客服DT授权代办 在线交谈 智能小云

工作时间:

周一至周五: 09:00 - 18:00

APP下载

安卓
APK

模板开发网安卓版APP

反馈

我要
反馈