Ejemplo n.º 1
0
 /**
  * @desc 删除球队
  */
 public function actionDeleteTeam()
 {
     $masterId = CommonFunction::getUserId();
     $leagueId = Yii::app()->request->getPost('leagueId');
     $teamId = Yii::app()->request->getPost('teamId');
     if (empty($leagueId) || empty($teamId)) {
         CommonFunction::ajaxResult(State::$SYS_PARAM_ERROR_CODE, State::$SYS_PARAM_ERROR_MSG);
     }
     $leagueModel = new LeagueModel();
     $groupModel = new GroupModel();
     $Groups = $groupModel->findByLeagueId($leagueId);
     if (empty($Groups)) {
         $res = $leagueModel->removeRelation('teams', 'Team', $leagueId, $teamId);
         if (isset($res->updatedAt)) {
             $resM = $leagueModel->findByMaster($masterId, 1);
             $teamModel = new TeamModel();
             $leagueTeams = $teamModel->findRowsByRelation("teams", "League", $resM[0]->objectId);
             $deleteTeam = $teamModel->findTeamByObjectId($teamId);
             if (isset($deleteTeam[0]->captain->username)) {
                 $uid = $deleteTeam[0]->captain->username;
                 $pushMsg = '你的球队:' . $deleteTeam[0]->name . ',已被联赛【' . $resM[0]->name . '】移除出联赛';
                 CommonFunction::pushAppMsg($uid, $pushMsg);
                 //					$device = new InstallationModel();
                 //					$msg = $device->findByUid($uid);
                 //					if(isset($msg[0]) && !empty($msg[0])){
                 //						$deviceMsg = $msg[0];
                 //						$push = new PushMsgModel();
                 //						$pushMsg = '你的球队:'.$deleteTeam[0]->name.',已被联赛【'.$resM[0]->name.'】移除出联赛';
                 //						if(isset($deviceMsg->deviceToken) && isset($deviceMsg->deviceType) && $deviceMsg->deviceType == 'ios'){
                 //							$push->createIosPush($deviceMsg->deviceToken,$pushMsg);
                 //						}elseif(isset($deviceMsg->installationId) && isset($deviceMsg->deviceType) && $deviceMsg->deviceType == 'android'){
                 //							$push->createAndroidPush($deviceMsg->installationId,$pushMsg);
                 //						}
                 //					}
             }
         }
         CommonFunction::ajaxResult(State::$SUSSION_CODE, State::$SUSSION_MSG, array('leagueTeams' => $leagueTeams));
     } else {
         CommonFunction::ajaxResult(State::$TEAM_DELETE_ERROR_CODE, State::$TEAM_DELETE_ERROR_MSG);
     }
 }
Ejemplo n.º 2
0
 /**
  * @desc 编辑比赛结果
  */
 public function actionEditGameResult()
 {
     if (!Yii::app()->request->isAjaxRequest) {
         throw new CHttpException(500, '此方法只允许ajax调用');
     }
     $masterId = CommonFunction::getUserId();
     $gameId = Yii::app()->request->getPost('gameid');
     $homeTeamScore = Yii::app()->request->getPost('home_team_score');
     $opponentTeamScore = Yii::app()->request->getPost('opponent_team_score');
     if (empty($gameId) || !is_numeric($homeTeamScore) || !is_numeric($opponentTeamScore)) {
         CommonFunction::ajaxResult(State::$SYS_PARAM_ERROR_CODE, State::$SYS_PARAM_ERROR_MSG);
     }
     $leagueModel = new LeagueModel();
     $res = $leagueModel->findByMaster($masterId, 1);
     if (empty($res)) {
         throw new CHttpException(500, '该用户无权限管理联赛');
     }
     $leagueId = $res[0]->objectId;
     $gameModel = new TournamentModel();
     $userModel = new UserModel();
     $gameArr = $gameModel->findByObjectId($gameId);
     if (isset($gameArr[0])) {
         $game = $gameArr[0];
         if (isset($game->home_court->captain->objectId)) {
             $homeTeamCaptainId = $game->home_court->captain->objectId;
             $homeTeamCaptain = $userModel->getByObjectId($homeTeamCaptainId);
             if (!empty($homeTeamCaptain)) {
                 if (isset($homeTeamCaptain->username) && !empty($homeTeamCaptain->username)) {
                     $homeTeamCaptainUsername = $homeTeamCaptain->username;
                     $pushMsg = '比赛已通过认证';
                     CommonFunction::pushAppMsg($homeTeamCaptainUsername, $pushMsg);
                 }
             }
             //var_dump($homeTeamCaptain);
             //echo $homeTeamCaptainId;
         }
         if (isset($game->opponent->captain->objectId)) {
             $opponentTeamCaptainId = $game->opponent->captain->objectId;
             $opponentTeamCaptain = $userModel->getByObjectId($opponentTeamCaptainId);
             //var_dump($opponentTeamCaptain);
             //echo $opponentTeamCaptainId;
         }
     }
     //		var_dump($game);exit;
     $res = '';
     try {
         $res = $gameModel->updateScore($gameId, $homeTeamScore, $opponentTeamScore);
     } catch (Exception $e) {
         //echo $e;
     }
     //	var_dump($res);exit;
     if (isset($res->updatedAt)) {
         if (isset($gameArr[0])) {
             $game = $gameArr[0];
             $teamScoreModel = new TeamScoreModel();
             if (isset($game->home_court->objectId)) {
                 $homeTeamId = $game->home_court->objectId;
                 if (isset($game->home_court->name)) {
                     $homeTeamName = $game->home_court->name;
                 }
                 $diffScore = $homeTeamScore - $opponentTeamScore;
                 $win = false;
                 $draw = false;
                 $loss = false;
                 $score = 0;
                 if ($diffScore > 0) {
                     $win = true;
                     $score = 3;
                 } elseif ($diffScore == 0) {
                     $draw = true;
                     $score = 1;
                 } elseif ($diffScore < 0) {
                     $loss = true;
                 }
                 $homeTeamBasic = array('league' => array("__type" => "Pointer", "className" => "League", "objectId" => $leagueId), 'competition' => array("__type" => "Pointer", "className" => "Tournament", "objectId" => $gameId), 'team' => array("__type" => "Pointer", "className" => "Team", "objectId" => $homeTeamId), 'name' => $homeTeamName);
                 $homeTeamDev = array('goals' => $homeTeamScore, 'goals_against' => $opponentTeamScore, 'goal_difference' => $diffScore, 'win' => $win, 'draw' => $draw, 'loss' => $loss, 'score' => $score);
                 $hasData = $teamScoreModel->findByCompetitionTeam($gameId, $homeTeamId);
                 if (!isset($hasData[0]->objectId)) {
                     $homeTeamData = array_merge($homeTeamBasic, $homeTeamDev);
                     $teamScoreModel->save($homeTeamData);
                 } else {
                     $teamScoreId = $hasData[0]->objectId;
                     $teamScoreModel->update($teamScoreId, $homeTeamDev);
                 }
             }
             if (isset($game->opponent->objectId)) {
                 $opponentTeamId = $game->opponent->objectId;
                 if (isset($game->opponent->name)) {
                     $opponentTeamName = $game->opponent->name;
                 }
                 $diffScore = $opponentTeamScore - $homeTeamScore;
                 $win2 = false;
                 $draw2 = false;
                 $loss2 = false;
                 $score2 = 0;
                 if ($diffScore > 0) {
                     $win2 = true;
                     $score2 = 3;
                 } elseif ($diffScore == 0) {
                     $draw2 = true;
                     $score2 = 1;
                 } elseif ($diffScore < 0) {
                     $loss2 = true;
                 }
                 $opponentTeamBasic = array('league' => array("__type" => "Pointer", "className" => "League", "objectId" => $leagueId), 'competition' => array("__type" => "Pointer", "className" => "Tournament", "objectId" => $gameId), 'team' => array("__type" => "Pointer", "className" => "Team", "objectId" => $opponentTeamId), 'name' => $opponentTeamName);
                 $opponentTeamDev = array('goals' => $opponentTeamScore, 'goals_against' => $homeTeamScore, 'goal_difference' => $diffScore, 'win' => $win2, 'draw' => $draw2, 'loss' => $loss2, 'score' => $score2);
                 $hasData2 = $teamScoreModel->findByCompetitionTeam($gameId, $opponentTeamId);
                 if (!isset($hasData2[0]->objectId)) {
                     $opponentTeamData = array_merge($opponentTeamBasic, $opponentTeamDev);
                     $teamScoreModel->save($opponentTeamData);
                 } else {
                     $teamScoreId2 = $hasData2[0]->objectId;
                     $teamScoreModel->update($teamScoreId2, $opponentTeamDev);
                 }
             }
         }
         $response = 'success';
     } else {
         $response = 'fail';
     }
     CommonFunction::ajaxResult(State::$SUSSION_CODE, State::$SUSSION_MSG, array('response' => $response));
 }