190 lines
6.6 KiB
PHP
190 lines
6.6 KiB
PHP
<?php
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Rank.php');
|
|
require_once('mt/Season.php');
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/RankSeason.php');
|
|
|
|
require_once('models/User.php');
|
|
require_once('models/Season.php');
|
|
require_once('models/Mission.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/SeasonService.php');
|
|
require_once('services/MissionService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\User;
|
|
use models\Season;
|
|
use models\Mission;
|
|
|
|
class SeasonController extends BaseAuthedController {
|
|
|
|
private $propertyChgService = null;
|
|
private $awardService = null;
|
|
private $userInfo = null;
|
|
private $seasonService = null;
|
|
private $currSeasonMeta = null;
|
|
private $currRankSeasonMeta = null;
|
|
private $seasonDb = null;
|
|
private $missionService = null;
|
|
|
|
public function _handlePre()
|
|
{
|
|
parent::_handlePre();
|
|
$this->currRankSeasonMeta = mt\RankSeason::getCurrentSeason();
|
|
$this->currSeasonMeta = mt\Season::getCurrentSeason();
|
|
if (!$this->currSeasonMeta) {
|
|
$this->_rspErr(10, 'server internal error');
|
|
die();
|
|
}
|
|
$this->propertyChgService = new services\PropertyChgService();
|
|
$this->awardService = new services\AwardService();
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
$this->seasonService = new services\SeasonService();
|
|
if (!$this->seasonService->checkSeason($this->userInfo)) {
|
|
$this->userInfo = $this->_safeGetOrmUserInfo();
|
|
$this->propertyChgService->addUserChg();
|
|
}
|
|
$this->seasonDb = Season::find($this->currSeasonMeta['id']);
|
|
if (!$this->seasonDb) {
|
|
Season::add($this->currSeasonMeta['id']);
|
|
$this->seasonDb = Season::find($this->currSeasonMeta['id']);
|
|
}
|
|
if (!$this->seasonDb) {
|
|
$this->_rspErr(10, 'server internal error');
|
|
die();
|
|
}
|
|
$this->missionService = new services\MissionService();
|
|
$this->missionService->init($this->userInfo, $this->seasonDb);
|
|
}
|
|
|
|
public function info()
|
|
{
|
|
$rankMeta = mt\Rank::get($this->userInfo['rank']);
|
|
$this->_rspData(array(
|
|
'info' => array(
|
|
'season_id' => $this->currSeasonMeta['id'],
|
|
'rank' => $this->userInfo['rank'],
|
|
'score' => $this->userInfo['score'],
|
|
'max_score' => $rankMeta ? $rankMeta['max_score'] : 0,
|
|
'noshow_score_bar' => $rankMeta ? $rankMeta['noshow_score_bar'] : 1,
|
|
'mission' => $this->getMissionInfo()
|
|
)
|
|
));
|
|
}
|
|
|
|
public function infoNew()
|
|
{
|
|
$rankMeta = mt\Rank::getRankById($this->userInfo['rank']);
|
|
$nextRankMeta = mt\Rank::getNextRankById($this->userInfo['rank']);
|
|
if (!$nextRankMeta){
|
|
$nextRankMeta = mt\Rank::getMaxRank();
|
|
}
|
|
$info = array(
|
|
'season_name' => $this->currRankSeasonMeta['name'],
|
|
'rank' => $this->userInfo['rank'],
|
|
'rank_name' => $rankMeta['rank_name'],
|
|
'score' => $this->userInfo['score'],
|
|
'next_score' => $nextRankMeta['rank_score'],
|
|
'season_end_time' => strtotime($this->currRankSeasonMeta['end_time']),
|
|
'season_reward' => Season::seasonReward($rankMeta)
|
|
);
|
|
|
|
// $rank_param = getReqVal('rank',$this->userInfo['rank']);
|
|
$users = User::orderBy(User::getUserByRank($this->userInfo['rank']));
|
|
$season_rank = array();
|
|
if (count($users)>0){
|
|
foreach ($users as $k=>$user){
|
|
if ($k<20){
|
|
$userDto = User::getUserByRankMess($user);
|
|
$userDto['rank_sort'] = $k+1;
|
|
array_push($season_rank,$userDto);
|
|
}
|
|
}
|
|
}
|
|
$info['season_rank'] = $season_rank;
|
|
$this->_rspData(['info'=>$info]);
|
|
// print_r($info);
|
|
}
|
|
|
|
public function getRankingInfo(){
|
|
$rank_param = getReqVal('rank',0);
|
|
if (!$rank_param){
|
|
$this->_rspErr(1, 'params rank error');
|
|
die();
|
|
}
|
|
$users = User::orderBy(User::getUserByRank($rank_param));
|
|
$season_rank = array();
|
|
if (count($users)>0){
|
|
foreach ($users as $k=>$user){
|
|
if ($k<20){
|
|
$userDto = User::getUserByRankMess($user);
|
|
$userDto['rank_sort'] = $k+1;
|
|
array_push($season_rank,$userDto);
|
|
}
|
|
}
|
|
}
|
|
$this->_rspData(['info'=>$season_rank]);
|
|
}
|
|
|
|
public function getMissionReward()
|
|
{
|
|
$mission = $this->getMissionInfo();
|
|
if (!$mission || $mission['state'] != Mission::RECEIVEABLE_STATE) {
|
|
$this->_rspErr(1, 'Can not receive');
|
|
return;
|
|
}
|
|
$missionMeta = mt\Task::get($this->currSeasonMeta['task_id']);
|
|
$missionId = $this->currSeasonMeta['task_id'];
|
|
if (!$missionMeta) {
|
|
$this->_rspErr(10, 'server internal error');
|
|
return;
|
|
}
|
|
$dropMeta = mt\Drop::get($missionMeta['reward']);
|
|
if (!$dropMeta) {
|
|
$this->_rspErr(10, 'server internal error');
|
|
return;
|
|
}
|
|
$this->_scatterDrop('mission:' . $missionId, $dropMeta, $this->awardService, $this->propertyChgService);
|
|
Mission::add($missionId);
|
|
$missionDb = Mission::find($missionId);
|
|
$missionDto = $this->missionService->getMissionDto(
|
|
$this->userInfo,
|
|
$this->seasonDb,
|
|
$missionDb,
|
|
$missionMeta);
|
|
$this->_rspData(array(
|
|
'award' => $this->awardService->toDto(),
|
|
'property_chg' => $this->propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
private function getMissionInfo()
|
|
{
|
|
$info = array(
|
|
'state' => Mission::NOT_FINISHED_STATE,
|
|
'current' => 0,
|
|
'target' => 0,
|
|
'target_rank' => 0
|
|
);
|
|
$missionMeta = mt\Task::get($this->currSeasonMeta['task_id']);
|
|
if ($missionMeta) {
|
|
$info['target_rank'] = $missionMeta['param1'];
|
|
$info['target'] = $missionMeta['target'];
|
|
$missionDb = Mission::find($missionMeta['id']);
|
|
$missionDto = $this->missionService->getMissionDto(
|
|
$this->userInfo, $this->seasonDb, $missionDb, $missionMeta);
|
|
if ($missionDto) {
|
|
$info['state'] = $missionDto['state'];
|
|
$info['current'] = $missionDto['current'];
|
|
$info['target'] = $missionDto['target'];
|
|
}
|
|
}
|
|
return $info;
|
|
}
|
|
|
|
}
|