/**
  * 添加友情贴吧
  * @access public
  * @param string $fid 贴吧id
  * @param string $fname 贴吧名
  */
 public function addRelatedForum($fid, $fname)
 {
     if ($this->uid == null) {
         $this->ajaxReturn('need-login');
         return;
     }
     $uid = $this->uid;
     if (A('Forum')->getManageStatus($fid) != 0) {
         $this->ajaxReturn('invalid-authority');
         return;
     }
     $old_count = A('Forum')->getRelatedForumCount($fid);
     $forum_id_array = M('forum')->field('forum_id')->where(array('forum_name' => $fname))->find();
     if ($forum_id_array == null) {
         $this->ajaxReturn('invalid-forum');
     }
     $new_fid = $forum_id_array['forum_id'];
     if ($old_count <= 5) {
         $info = M('related_forum')->where(array('forum_id' => $fid, 'object_id' => $new_fid))->find();
         if ($info != null) {
             $this->ajaxReturn('already-add');
         } else {
             $data['data_id'] = getMikuInt();
             $data['forum_id'] = $fid;
             $data['object_id'] = $new_fid;
             $re = M('related_forum')->data($data)->add();
         }
     } else {
         $this->ajaxReturn('only-five');
     }
     if ($re) {
         $this->ajaxReturn('add-success');
     } else {
         $this->ajaxReturn('add-failure');
     }
 }
 /**
  * 收藏帖子
  * @access public
  * @param string $tid 帖子id
  */
 public function storeThread($tid)
 {
     if ($this->uid == null) {
         $this->ajaxReturn('need-login');
     }
     $uid = $this->uid;
     $store_status = $this->getStoreStatus($tid, $uid);
     if ($store_status == null) {
         $data['data_id'] = getMikuInt();
         $data['user_id'] = $uid;
         $data['thread_id'] = $tid;
         $data['stored_date'] = getNowDate();
         $re = M('stored_thread')->data($data)->add();
         $this->ajaxReturn('do-success');
     } else {
         $re = M('stored_thread')->where(array('thread_id' => $tid, 'user_id' => $uid))->delete();
         $this->ajaxReturn('do-success');
     }
 }
 /**
  * 注册
  * @access public
  */
 public function doRegister()
 {
     $param = I('post.');
     $username = $param['username'];
     $password = $param['password'];
     $email = $param['email'];
     $code = $param['verifyCode'];
     if ($username == '') {
         $this->ajaxReturn('empty-username');
     }
     if (preg_match("/[ '.,:;*?~`!@#\$%^&+=)(<>{}]|\\]|\\[|\\/|\\\\|\"|\\|/", $username)) {
         $this->ajaxReturn('invalid-username');
     }
     if (getUtf8Strlen($username) > 12) {
         $this->ajaxReturn('too-long-username');
     }
     $info = M('users')->where(array('user_name' => $username))->find();
     if ($info != null) {
         $this->ajaxReturn('username-exist');
     }
     if (strlen($password) < 6 || strlen($password) > 30) {
         $this->ajaxReturn('invalid-password');
     }
     if (!preg_match('/^[A-Za-z0-9-_.+%]+@[A-Za-z0-9-.]+\\.[A-Za-z]{2,4}$/', $email)) {
         $this->ajaxReturn('invalid-email');
     }
     if ($this->checkVerifyCode($code) == false) {
         $this->ajaxReturn('error-code');
     }
     $data['user_name'] = $username;
     $data['user_pass'] = md5($password);
     $data['user_id'] = getMikuInt();
     $data['user_sex'] = 1;
     $data['user_avatar'] = 0;
     $data['user_regdate'] = getNowDate();
     $data['user_email'] = $param['email'];
     $data['user_openid'] = $param['openid'];
     $re = M('users')->data($data)->add();
     if ($re) {
         $this->ajaxReturn('register-success');
     } else {
         $this->ajaxReturn('register-error');
     }
 }
 /**
  * 访问用户的主页
  * @access private
  * @param string $id 用户id
  */
 private function visitUser($id)
 {
     if ($this->uid == null) {
         return;
     }
     $uid = $this->uid;
     $data['data_id'] = getMikuInt();
     $data['user_id'] = $id;
     $data['visitor_id'] = $uid;
     //先查看是否访问过
     $info = M('user_visitor')->where(array('user_id' => $id, 'visitor_id' => $uid))->find();
     //获取总来访数
     $info_2 = M('user_visitor')->field("max(visitor_order)")->where(array('user_id' => $id))->find();
     $visitor_count = $info_2['max(visitor_order)'];
     //没有访问过
     if ($info == null) {
         //要插入表中的来访次序
         $data['visitor_order'] = $visitor_count + 1;
         $re_1 = M('user_visitor')->data($data)->add();
     } else {
         //来访过
         //获取当前访客之前的次序
         $info_3 = M('user_visitor')->field('visitor_order')->where(array('user_id' => $id, 'visitor_id' => $uid))->find();
         $current_order = $info_3['visitor_order'];
         //将在他之后来访的人的次序-1
         $re_2 = M('user_visitor')->where(array('user_id' => $id, 'visitor_order' => array('gt', $current_order)))->setDec('visitor_order');
         //再把当前访客的次序设置为最大
         $re_3 = M('user_visitor')->where(array('user_id' => $id, 'visitor_id' => $uid))->setField('visitor_order', $visitor_count);
     }
 }
 /**
  * 申请小吧主表单
  * @access public
  */
 public function doApplySmallManager()
 {
     $param = I('post.');
     $fid = $param['fid'];
     $content = $param['content'];
     if ($this->uid == null) {
         $this->ajaxReturn('need-login');
     }
     $uid = $this->uid;
     $info = M('forum_manager_apply')->where(array('forum_id' => $fid, 'user_id' => $uid, 'is_pass' => 0))->find();
     if (!empty($info)) {
         $this->ajaxReturn('already-apply');
     }
     $info_2 = M('forum_manager')->where(array('forum_id' => $fid, 'user_id' => $uid))->find();
     if (!empty($info_2)) {
         $this->ajaxReturn('already-apply');
     }
     $data['data_id'] = getMikuInt();
     $data['user_id'] = $uid;
     $data['forum_id'] = $fid;
     $data['apply_date'] = getNowDate();
     $data['apply_type'] = 1;
     $data['apply_content'] = $content;
     $data['is_pass'] = 0;
     $re = M('forum_manager_apply')->data($data)->add();
     if ($re) {
         $this->ajaxReturn('apply-success');
     } else {
         $this->ajaxReturn('apply-failure');
     }
 }