/** * @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); } }
/** * @desc 修复android严重比赛结果后没保存TeamScore的问题 */ public function actionTestSaveTeamScore() { $masterId = CommonFunction::getUserId(); $gameId = "b404c1fc88"; $homeTeamScore = "8"; $opponentTeamScore = "0"; $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; } } } if (isset($game->opponent->captain->objectId)) { $opponentTeamCaptainId = $game->opponent->captain->objectId; $opponentTeamCaptain = $userModel->getByObjectId($opponentTeamCaptainId); } } // var_dump($game);exit; $res = ''; try { // $res = $gameModel->updateScore($gameId,$homeTeamScore,$opponentTeamScore); } catch (Exception $e) { //echo $e; } if (true) { 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'; } }
/** * @desc 百度云推送 * @param $users 用户的对象数组 * @param $title 推送的标题 * @param $msg 推送的内容 * @param $type 详细看文档 * @param $subType 详细看文档 * @param $msg_type 推送的类型:0:消息(透传)1:通知 * @param $options * @return bool|mixed */ public function push($users, $title, $msg, $type, $subType, $optional, $msg_type = 1) { $pushMsgModel = new PushMsgModel(); if (!is_array($users)) { $users = array($users); } if (count($users) > 0) { $masterId = CommonFunction::getUserId(); $content = $msg; $saveBatchArr = array(); //保存推送消息到PushMsg表 foreach ($users as $user) { if (isset($user->username) && !empty($user->username)) { $extra = array("belongId" => $user->username, "title" => $title, "type" => $type, "time" => time(), "targetId" => $this->getTargetId($subType, $optional), "subtype" => $subType); $saveArr = array('belongUsername' => $user->username, 'isRead' => 0, 'status' => 0, 'msgType' => 0, 'extra' => json_encode($extra), 'content' => $content); array_push($saveBatchArr, $saveArr); } } try { $results = $pushMsgModel->saveBatch($saveBatchArr); } catch (Exception $e) { return $e->getMessage(); } //发送百度推送 for ($i = 0; $i < count($users); $i++) { $user = $users[$i]; $result = $results[$i]; if (!property_exists($user, 'pushUserId')) { continue; } if ($user->pushUserId == "") { continue; } $push_type = 1; //推送单播消息 $optional[Channel::USER_ID] = $user->pushUserId; //如果推送单播消息,需要指定user $message = array(); if ($user->deviceType == "ios") { //指定发到ios设备 $optional[Channel::DEVICE_TYPE] = 4; //apns证书状态 $optional[Channel::DEPLOY_STATUS] = Yii::app()->params['apnDeployStatus']; $message['aps']['alert'] = $msg; $message['aps']['sound'] = ""; $message['aps']['badge'] = 0; $message['objectId'] = $result->success->objectId; $message['belongId'] = $user->username; $message['targetId'] = $this->getTargetId($subType, $optional); $message['title'] = $title; $message['time'] = time(); $message['type'] = $type; $message['subtype'] = $subType; $message['flag'] = "notice"; } else { //android $optional[Channel::DEVICE_TYPE] = 3; $message['title'] = $title; $message['description'] = $msg; $message['custom_content']['objectId'] = $result->success->objectId; $message['custom_content']['belongId'] = $user->username; $message['custom_content']['targetId'] = $this->getTargetId($subType, $optional); $message['custom_content']['title'] = $title; $message['custom_content']['time'] = time(); $message['custom_content']['type'] = $type; $message['custom_content']['subtype'] = $subType; $message['custom_content']['flag'] = "notice"; } $optional[Channel::MESSAGE_TYPE] = $msg_type; $message_key = md5(json_encode($message)); $ret = $this->channel->pushMessage($push_type, json_encode($message), $message_key, $optional); // echo "send pushId:".$user->pushUserId."<br/>"; //检查返回值 if (false === $ret) { echo 'baiduPush_WRONG, ' . __FUNCTION__ . ' ERROR!!!!<br/>'; echo 'baiduPush_ERROR NUMBER: ' . $this->channel->errno() . '<br/>'; echo 'baiduPush_ERROR MESSAGE: ' . $this->channel->errmsg() . '<br/>'; echo 'baiduPush_REQUEST ID: ' . $this->channel->getRequestId() . '<br/>'; echo '<br/>'; } } } // Helper::flash('error', "你无权限编辑联赛信息(请确认你至少有一个联赛的管理权限)!", '/site/'); }