TP签到程序

浏览:2647 发布日期:2015/09/22 分类:技术分享 关键字: TP签到程序 签到 签到代码
分享一段TP的签到程序,实际部署时,建议使用SESSSION安全机制。
代码演示地址:js代码http://www.jsdaima.com/,登陆后就可以签到了,在“我的js代码"即可以看到签到积分明细及总积分。PS:没有注册过会员的可以注册试试!有什么疑问或者更好的方法的,希望大家跟帖评论,谢谢啦^_^
//签到
    /**
     * 签到:首次签到奖励100积分,之后第一天签到得10积分,第二天连续签到得20积分,以此类推,第七天连续签到得70积分,第八天也是70积分,即70积分封顶!中途签到如有间隔,无法连续签到的话,则又回到第一天签到得10积分
     * @author Hency
     * @copyright www.jsdaima.com
     */
    public function sign(){
        $this->is_login();
        $db_member = M('member');
        $db_score  = M('score');
        $member_info = $db_member->where(array('id'=>$_COOKIE['mid']))->find();
        //判断今天是否签到
        $today = date('Y-m-d', time());
        $sign_time = date('Y-m-d', $member_info['sign_time']);
        if ($sign_time == $today) {
            $this->success('亲,今天你已经签过到啦^_^');
        }else{
            //判断是否为首次签到
            if (!$member_info['sign_last']) {
                $data = array(
                    'id'        => $_COOKIE['mid'],
                    'sign_time' => time(),
                    'sign_last' => time(),
                    'score'     => 100
                    );
                $db_member->save($data);
                $score_log = array(
                    'mid'   => $_COOKIE['mid'],
                    'score' => 100,
                    'time'  =>time(),
                    );
                $db_score->add($score_log);
                $this->success('首次签到,奖励100积分!');
            }else{
                //判断是否连续签到
                $yesterday = date('Y-m-d', strtotime("-1 day"));
                $sign_last = date('Y-m-d', $member_info['sign_last']);
                if ($sign_last == $yesterday) {
                    if ($member_info['continues'] <= 6) {
                        $db_member->where('id = '.$_COOKIE['mid'])->setInc('continues');
                    }
                    $db_member->where('id = '.$_COOKIE['mid'])->setInc('succession');
                    $data = array(
                        'id'        =>  $_COOKIE['mid'],
                        'sign_time' => time(),
                        'sign_last' => time(),
                        'score'     => $member_info['score'] + $member_info['continues'] * 10,
                        );
                    $db_member->save($data);
                    $score_log = array(
                        'mid'   => $_COOKIE['mid'],
                        'score' => $member_info['continues'] * 10,
                        'time'  =>time(),
                        );
                    $db_score->add($score_log);
                    $today_score    = $member_info['continues'] * 10;
                    if ($member_info['continues'] <= 6) {
                        $tomorrow_score = ($member_info['continues'] + 1) * 10;
                    }else{
                        $tomorrow_score = 70;
                    }
                    $this->success('连续签到'.$member_info['succession'].'天,获得'.$today_score.'积分,明天签到可以获得'.$tomorrow_score.'积分');
                }else{
                    $data = array(
                        'id'         =>  $_COOKIE['mid'],
                        'sign_time'  => time(),
                        'sign_last'  => time(),
                        'score'      => $member_info['score'] + 10,
                        'continues'  => 1,
                        'succession' => 1
                        );
                    $db_member->save($data);
                    $score_log = array(
                        'mid'   => $_COOKIE['mid'],
                        'score' => 10,
                        'time'  =>time(),
                        );
                    $db_score->add($score_log);
                    $this->success('连续签到1天,获得10积分,明天签到可以获得20积分');
                }
            }
        }
    }

    //判断是否已经登陆
    public function is_login(){
        if (!$_COOKIE['mid']) {
            $this->error('请登录');exit();
        }
    }
最佳答案
评论( 相关
后面还有条评论,点击查看>>