game2006api/webapp/controller/StarController.class.php
2024-08-01 16:21:54 +08:00

202 lines
7.4 KiB
PHP

<?php
require_once('services/AwardService.php');
require_once('services/PropertyChgService.php');
require_once('services/LogService.php');
require_once('mt/LevelUp.php');
require_once('mt/StarLevel.php');
require_once('models/MissionStar.php');
require_once('models/RealtimeData.php');
use phpcommon\SqlHelper;
use models\MissionStar;
use models\RealtimeData;
use services\LogService;
class StarController extends BaseAuthedController {
private $awardService = null;
private $propertyChgService = null;
private $userInfo = null;
private $currMissionSeasonMeta = null;
public function _handlePre()
{
if(getReqVal('a', '') != 'resetStar'){
parent::_handlePre();
}
$this->_rspErr(10, 'server internal error');
die();
$this->currMissionSeasonMeta = \mt\StarLevel::getCurrentSeason();
if (!$this->currMissionSeasonMeta) {
$this->_rspErr(10, 'server internal error');
die();
}
// $this->_setV(TN_MISSION_STAR_SEASON, 0, $this->currMissionSeasonMeta['id']);
$this->propertyChgService = new services\PropertyChgService();
$this->awardService = new services\AwardService();
$this->userInfo = $this->_safeGetOrmUserInfo();
}
public function getList(){
$list = array();
$countdown = strtotime($this->currMissionSeasonMeta['end_time']) - myself()->_getNowTime();
$defaultList = \mt\StarLevel::getDefaultList();
$lvUpMetaList = \mt\StarLevel::getListBySeason($this->currMissionSeasonMeta['id']);
$collection = array_merge($defaultList,$lvUpMetaList);
foreach ($collection as $meta){
$state = MissionStar::NOT_FINISHED_STATE;
$target = getXVal($meta, 'need_star_num', 1);
$missionStarDb = MissionStar::find($meta['season_id'],$meta['id']);
if ($this->userInfo['star_num'] >= $target && !$missionStarDb){
$state = MissionStar::RECEIVEABLE_STATE;
if (empty($meta['item_id'])){
$state = MissionStar::RECEIVED_STATE;
}
}
if ($this->userInfo['star_num'] >= $target && $missionStarDb){
$state = MissionStar::RECEIVED_STATE;
}
array_push($list,
array(
'mission_id' => $meta['id'],
'current' => $this->userInfo['star_num'],
'target' => $target,
'state' =>$state
)
);
}
$this->_rspData(array(
'countdown' => $countdown,
'data' => $list,
));
}
public function commit(){
$missionId = getReqVal('mission_id', 0);
$meta = mt\StarLevel::get($missionId);
if (!$meta) {
$this->_rspErr(1, 'mission_id parameter error');
return;
}
if ($this->userInfo['star_num'] < $meta['need_star_num']){
$this->_rspErr(1, 'objectives not achieved');
return;
}
if (empty($meta['item_id'])){
$this->_rspErr(1, 'No bonus claim');
return;
}
$missionStarDb = MissionStar::find($meta['season_id'],$missionId);
if ($missionStarDb){
$this->_rspErr(1, "Can't get it again");
return;
}
$items = array(
array(
'item_id' => $meta['item_id'],
'item_num' => $meta['item_num'],
)
);
$this->_addItems($items,$this->awardService, $this->propertyChgService);
if ($meta['item_id'] == V_ITEM_GOLD){
//埋点
$event = [
'name' => LogService::STAR_MISSION_AWARD,
'val' => $meta['item_num']
];
LogService::productGold($event);
}
// $dropMeta = mt\Drop::get($meta['drop_id']);
// if (!$dropMeta) {
// $this->_rspErr(10, 'server internal error:' . $meta['drop_id']);
// return;
// }
// $this->_scatterDrop('missionStar:' . $missionId, $dropMeta, $this->awardService, $this->propertyChgService);
MissionStar::add($meta['season_id'],$missionId);
$this->_rspData(array(
'award' => $this->awardService->toDto(),
'property_chg' => $this->propertyChgService->toDto(),
));
}
public function commitAll(){
$defaultList = \mt\StarLevel::getDefaultList();
$lvUpMetaList = \mt\StarLevel::getListBySeason($this->currMissionSeasonMeta['id']);
$collection = array_merge($defaultList,$lvUpMetaList);
$gold = 0;
foreach ($collection as $meta){
$target = getXVal($meta, 'need_star_num', 1);
$missionStarDb = MissionStar::find($meta['season_id'],$meta['id']);
if ($this->userInfo['star_num'] >= $target && !$missionStarDb && !empty($meta['item_id'])){
if ($meta['item_id'] == V_ITEM_GOLD){
$gold += $meta['item_num'];
}
//可领取
$items = array(
array(
'item_id' => $meta['item_id'],
'item_num' => $meta['item_num'],
)
);
$this->_addItems($items,$this->awardService, $this->propertyChgService);
MissionStar::add($meta['season_id'],$meta['id']);
// $dropMeta = mt\Drop::get($meta['drop_id']);
// if ($dropMeta) {
// $this->_scatterDrop('missionStar:' . $meta['id'], $dropMeta, $this->awardService, $this->propertyChgService);
// MissionStar::add($meta['season_id'],$meta['id']);
// }
}
}
if ($gold > 0){
//埋点
$event = [
'name' => LogService::STAR_MISSION_AWARD,
'val' => $gold
];
LogService::productGold($event);
}
$this->_rspData(array(
'award' => $this->awardService->toDto(),
'property_chg' => $this->propertyChgService->toDto(),
));
}
public function resetStar(){
return;
$season = RealtimeData::getMissionSeason();
if ( $this->currMissionSeasonMeta['id'] > $season){
$meta = mt\Parameter::getByName('starroad_restart_point');
if (!$meta){
error_log('ERROR INFO : parameter.xlsx not param starroad_restart_point');
return ;
}
$max_star_num = getXVal($meta, 'param_value',1000);
$rows = myself()->_getSelfMysql()->execQuery(
'SELECT account_id,star_num FROM t_user WHERE star_num>:star_num',
array(
"star_num"=>$max_star_num
)
);
if (count($rows) > 0){
foreach ($rows as $row){
myself()->_getSelfMysql()->execQuery(
'UPDATE t_user SET star_num=:star_num WHERE account_id=:account_id',
array(
"star_num"=>$max_star_num,
"account_id"=>$row['account_id'],
)
);
}
}
error_log("request resetStar time : ". date('Y-M-D h:i:s',time()));
RealtimeData::setMissionSeason($this->currMissionSeasonMeta['id']);
}
}
}