Beispiel #1
0
function initCounter()
{
    global $counter;
    if ($counter === null) {
        $counter = new SaeCounter();
        $counter->create('dbhit');
        $counter->create('cachehit');
        $counter->create('mailsent');
    }
}
 public function register($username, $password, $email, $code)
 {
     if (IS_POST) {
         $d = time();
         //待处理的日期
         $w = date("w", $d);
         //这天是星期几
         if ($code == NULL) {
             echo json_encode(array('error' => '邀请码不是一个有效项'));
             return;
         }
         $isCounterCode = false;
         if ($code == 'can') {
             $c = new \SaeCounter();
             if (($yqmCounter = $c->get('yqm')) > 50) {
                 echo json_encode(array('error' => '人数已满'));
                 return;
             } else {
                 $isCounterCode = true;
             }
         }
         if ($code != 'cccc' . $w * 4 && !$isCounterCode) {
             echo json_encode(array('error' => '邀请码不是一个有效项'));
             return;
         }
         $resArr = D('User')->CreateUser($username, $password, $email);
         // 注册后立即登录
         if ($resArr['info'] == 'Success') {
             $c->set('yqm', $yqmCounter + 1);
             cookie('token', login_en_code(D('User')->login_random($username) . $username));
             cookie('username', $username);
             session('user_status', 1);
         }
         echo json_encode($resArr);
     }
 }
Beispiel #3
0
 public function counter()
 {
     $c = new SaeCounter();
     //实例化
     $c->create("test");
     //创建计算器
     $c->set("test", 30);
     //设置值
     $ret = $c->get("test");
     //获得值
     dump($ret);
     $ret = $c->incr("test");
     //增加值
     dump($ret);
     $ret = $c->decr("test");
     //减少值
     dump($ret);
 }
// http://5.littlesmallsu.sinaapp.com/chessPlay.php?ini=1
// http://5.littlesmallsu.sinaapp.com/chessPlay.php?x=1&y=1&c=1
header("Content-type:text/html;charset=utf-8");
//初始化
if (isset($_REQUEST['ini'])) {
    deleteChess();
    $c = new SaeCounter();
    $c->set('chessStep', 1);
}
//刷新下棋位置
if (isset($_REQUEST['x']) && isset($_REQUEST['y']) && isset($_REQUEST['c'])) {
    $tmp['c'] = $_REQUEST['c'];
    $tmp['x'] = $_REQUEST['x'];
    $tmp['y'] = $_REQUEST['y'];
    $c = new SaeCounter();
    $tmp['s'] = $c->get('chessStep');
    insertChess($tmp);
    $c->incr('chessStep');
}
//显示所有下棋
selectChess();
//函数部分
function insertChess($tmp)
{
    $kv = new SaeKV();
    $ret = $kv->init();
    $ret = $kv->set('chess_' . $tmp['s'], $tmp);
}
function deleteChess()
{
 protected function _initialize()
 {
     header("Content-Type:text/html; charset=utf-8");
     $logon;
     $sign;
     $pvCounter = new SaeCounter();
     $User = M("User");
     // 实例化User对象
     $pv;
     if ($this->PVCounter()) {
         $pv = $pvCounter->incr('PVCount');
     } else {
         $pv = $pvCounter->get('PVCount');
     }
     if (session('tennis-user') == null) {
         $condition['mailbox'] = $_COOKIE['tennis-user'];
         $user0 = $User->where($condition)->select();
         if ($user != null) {
             $user = current($user0);
             // 更新日志
             //=================
             $data['module'] = '用户登录(手机)';
             $data['operation'] = '登录';
             $data['update_user'] = $user['id'];
             $data['ip'] = $this->getIP();
             $log = M('operation_log');
             $log->add($data);
             //=================
             // 上次登录日期比较,计算连续登录日期
             $date = date('Y-m-d H:i:s');
             $last_logon_date = $user['last_logon_date'];
             $info = array();
             $is_first_visit = false;
             if (date('d') != date('d', strtotime($last_logon_date)) || date('m') != date('m', strtotime($last_logon_date)) || date('Y') != date('Y', strtotime($last_logon_date))) {
                 $user['logon_days']++;
                 $is_first_visit = true;
                 $info['is_sign'] = 0;
                 $user['is_sign'] = 0;
             }
             $info['last_logon_date'] = $date;
             $info['logon_days'] = $user['logon_days'];
             // 是否解禁
             if ($user['is_forbidden'] == 1) {
                 $d1 = strtotime($date);
                 $d2 = strtotime($user['end_forbid_date']);
                 if ($d1 >= $d2) {
                     $info['is_forbidden'] = 0;
                     $user['is_forbidden'] = 0;
                 }
             }
             $User->where('id=' . $user['id'])->setField($info);
             $_SESSION['tennis-user'] = $user;
             if ($is_first_visit) {
                 $this->updateScoreAndExp(1);
             }
         }
     }
     if (session('tennis-user') != null) {
         $user = session('tennis-user');
         $logon = ' <li class="dropdown">
                     <a href="#" class="dropdown-toggle" style="text-align:center"  data-toggle="dropdown">' . $user['username'] . '<b class="caret"></b></a>
                     <ul class="dropdown-menu">
                     
                       <li><a class="btn" style="color:white;" href="__APP__/Mobile/User/userInfo"> 用户中心</a> </li>
                       <li><a class="btn" style="color:white;" href="__APP__/Mobile/Public/logout">退出</a></li>';
         if ($user['is_sign'] == 0) {
             $sign = "<li><a style='color:white;' id='signStr' class='btn' onclick='sign0();' >签到</a></li>";
         } else {
             $sign = "<li><a style='color:white;'id='signStr' class='btn' onclick='sign0();' disabled >已签到</a></li>";
         }
         if ($user['role'] == 0) {
             $logon .= '<li class="divider"></li> <li><a class="btn" href="__APP__/Admin/Index/index">后台管理</a></li></ul></li>';
         } else {
             if ($user['role'] == 1 && !(strpos($user['manage_club_id'], ';' . $club_id . ';') === false)) {
                 $logon .= '<li class="divider"></li> <li><a class="btn" href="__APP__/Admin/Index/index">后台管理</a></li></ul></li>';
             } else {
                 $logon .= ' </ul></li>';
             }
         }
     } else {
         $logon = '<li><a class="btn" data-toggle="modal" data-target="#myModal">登录</a></li>';
     }
     // 获取俱乐部id变量
     $club_id = $this->getClubId();
     $this->assign('pagePostfix', '_' . $club_id);
     $this->assign('logon', $logon);
     $this->assign('sign', $sign);
     $this->assign('PV', $pv);
     $this->assign('clubName', $this->getClubName());
 }
 public function ck_addtask()
 {
     $c = new SaeCounter();
     if (!$c->exists('sae_checker_wait_tq')) {
         if (!$c->create('sae_checker_wait_tq', 0)) {
             return '1.1';
         }
     }
     $url = $_SERVER['SCRIPT_URI'] . '?passkey=' . $GLOBALS['md5key'] . '&service=taskq&action=trigger';
     $this->tq()->addTask($url, NULL, true);
     $this->tq()->push();
     $s_time = time();
     $pass = false;
     while (!$pass && time() - $s_time < 20) {
         if ($c->get('sae_checker_wait_tq') > 0) {
             $pass = true;
         } else {
             time_nanosleep(0, 100000000);
         }
         // 1/10 second
     }
     $c->remove('sae_checker_wait_tq');
     if ($pass) {
         return '1.0';
     } else {
         return '1.1';
     }
 }