public function getAction($targetId)
 {
     if (!MyTool::loginAuth($this)) {
         return MyTool::onExit($this, MyConst::STATUS_NOT_LOGIN, 'must login first');
     }
     $targetId = @trim($targetId);
     if (empty($targetId)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_PARAM, 'invalid param');
     }
     $team = TeamLogic::getTeam($targetId);
     if (empty($team)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_TEAM, 'unknown team id');
     }
     if ($team->flag != MyConst::TEAM_FLAG_NORMAL) {
         $uid = @intval(MyTool::getCookie($this, MyConst::COOKIE_UID));
         if ($team->owner != $uid && !TeamLogic::hasMember($team->id, $uid)) {
             return MyTool::onExit($this, MyConst::STATUS_NO_PERMISSION, 'permission denied');
         }
     }
     MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK);
     MyTool::setVar($this, MyConst::FIELD_TEAM, $team);
     $this->logger->log($team->mission);
     $leaders = TeamLogic::getLeaders($team->id);
     if (!empty($leaders)) {
         MyTool::setVar($this, MyConst::FIELD_LEADER, $leaders);
     }
     return true;
 }
 public function applyAction($targetId)
 {
     MyTool:
     simpleView();
     if (!MyTool::loginAuth($this)) {
         return $this->onExit(MyConst::STATUS_NOT_LOGIN, 'must login first');
     }
     $targetId = @intval($targetId);
     $uid = @intval(MyTool::getCookie($this, MyConst::COOKIE_UID));
     // 是否已申请过
     if (MaTeamInvitation::exists($uid, $targetId)) {
         return MyTool::onExit($this, MyConst::STATUS_EXISTS, 'record already exists');
     }
     // 获取用户信息
     $user = MaUser::getUser($uid);
     if (empty($user)) {
         return MyTool::onExit($this, MyConst::STATUS_ERROR, 'invalid user id');
     }
     // 获得团队信息
     $team = TeamLogic::getTeam($targetId);
     if (empty($team)) {
         return MyTool::onExit($this, MyConst::STATUS_INVALID_TEAM, 'invalid team id');
     }
     if (TeamLogic::isOwner($uid, $targetId)) {
         return MyTool::onExit($this, MyConst::STATUS_OK, 'already owner of this team');
     }
     if (TeamLogic::hasMember($uid, $targetId)) {
         return MyTool::onExit($this, MyConst::STATUS_OK, 'already member of this team');
     }
     // 添加申请
     $apply = MaTeamInvitatoin::apply($team->id, $team->name, $user->id, $user->name);
     try {
         if (true !== $apply->create()) {
             return MyTool::onExit($this, MyConst::STATUS_DB, 'join in team apply failed');
         }
     } catch (Exception $e) {
         return MyTool::onExit($this, MyConst::STATUS_ERROR, $e->getMessage());
     }
     // 返回
     MyTool::setVar($this, MyConst::FIELD_STATUS, MyConst::STATUS_OK);
     return true;
 }