예제 #1
0
 /**
  * @desc 添加球队
  */
 public function actionAddTeam()
 {
     $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->createRelation('teams', 'Team', $leagueId, $teamId);
         if (isset($res->updatedAt)) {
             $resM = $leagueModel->findByMaster($masterId, 1);
             $teamModel = new TeamModel();
             $leagueTeams = $teamModel->findRowsByRelation("teams", "League", $resM[0]->objectId);
             $addTeam = $teamModel->findTeamByObjectId($teamId);
             if (isset($addTeam[0]->captain->username)) {
                 $uid = $addTeam[0]->captain->username;
                 $pushMsg = '你的球队:' . $addTeam[0]->name . ',已被添加进联赛:' . $resM[0]->name;
                 //给队长发送联赛邀请
                 $baiduPushModel = new BaiduPushModel();
                 $baiduPushModel->sendInviteMessageForTeamCaptain($leagueId, $teamId, $addTeam[0]->captain);
                 //					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 = '你的球队:'.$addTeam[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_ADD_ERROR_CODE, State::$TEAM_ADD_ERROR_MSG);
     }
 }