207 lines
7.5 KiB
PHP
207 lines
7.5 KiB
PHP
<?php
|
|
require_once('services/HashRateService.php');
|
|
require_once('services/MissionService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
require_once('services/AwardService.php');
|
|
|
|
require_once('mt/ServerTaskTime.php');
|
|
require_once('mt/ServerTask.php');
|
|
require_once('mt/Task.php');
|
|
require_once('mt/Parameter.php');
|
|
require_once('models/UserInvitationCode.php');
|
|
require_once('models/Mission.php');
|
|
|
|
|
|
use models\UserInvitationCode;
|
|
use models\Mission;
|
|
class ActivityController extends BaseAuthedController {
|
|
|
|
public function getInviteActivityInfo(){
|
|
$myCodeDb = UserInvitationCode::findMyCode();
|
|
if(!$myCodeDb){
|
|
UserInvitationCode::generateCode();
|
|
$myCodeDb = UserInvitationCode::findMyCode();
|
|
}
|
|
$myCode = $myCodeDb['invitation_code'];
|
|
$count = UserInvitationCode::getMyCodeBindCount($myCode);
|
|
$rewards = array();
|
|
$rewardArr = \mt\Parameter::getListValue('rookie_bind_reward');
|
|
foreach ($rewardArr as $value){
|
|
$values = explode(':', $value);
|
|
array_push($rewards,array(
|
|
'item_id' => $values[0],
|
|
'item_num' => $values[1],
|
|
));
|
|
}
|
|
$bindState = 0;
|
|
if (UserInvitationCode::verifyAccountBind()){
|
|
$bindState = 1;
|
|
}
|
|
$rewardState = 0;
|
|
if (UserInvitationCode::verifyAccountReward()){
|
|
$rewardState = 1;
|
|
}
|
|
$this->_rspData(array(
|
|
'invitation_code' => $myCode,
|
|
'invite_count' => $count,
|
|
'bind_state' => $bindState,
|
|
'reward_state' => $rewardState,
|
|
'bind_rewards' => $rewards
|
|
));
|
|
}
|
|
|
|
public function bindInvitationCode(){
|
|
$code = getReqVal('code', 0);
|
|
if (!UserInvitationCode::verifyCode($code)){
|
|
$this->_rspErr(1, "invitation code error");
|
|
return;
|
|
}
|
|
if (UserInvitationCode::verifyAccountBind()){
|
|
$this->_rspErr(1, "The user has been bind");
|
|
return;
|
|
}
|
|
$myCodeDb = UserInvitationCode::findMyCode();
|
|
if ($code == $myCodeDb['invitation_code']){
|
|
$this->_rspErr(1, "Unable to bind own code");
|
|
return;
|
|
}
|
|
UserInvitationCode::addInvitationCodeBind($code);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function getBindRewardS(){
|
|
if (!UserInvitationCode::verifyAccountBind()){
|
|
$this->_rspErr(1, "Unbound user");
|
|
return;
|
|
}
|
|
if (UserInvitationCode::verifyAccountReward()){
|
|
$this->_rspErr(1, "Can't get it again");
|
|
return;
|
|
}
|
|
$items = array();
|
|
$rewardArr = \mt\Parameter::getListValue('rookie_bind_reward');
|
|
foreach ($rewardArr as $value){
|
|
$values = explode(':', $value);
|
|
array_push($items,array(
|
|
'item_id' => $values[0],
|
|
'item_num' => $values[1],
|
|
));
|
|
}
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
myself()->_addItems($items,$awardService,$propertyChgService);
|
|
UserInvitationCode::updateRewardState();
|
|
$this->_rspData(array(
|
|
'award' => $awardService->toDto(),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
public function getInvitationTaskList(){
|
|
$missionService = new services\MissionService();
|
|
$missionMetaList = mt\Task::getCustomTypeMetaList(\mt\Task::NEW_USER_MISSON_TYPE, $missionService);
|
|
$missionHash = Mission::allToHash();
|
|
$taskDtoList = array();
|
|
foreach ($missionMetaList as $missionMeta) {
|
|
$missionDb = getXVal($missionHash, $missionMeta['id'], null);
|
|
$missionDto = $missionService->getMissionDto(
|
|
null, null, $missionDb, $missionMeta);
|
|
array_push($taskDtoList, $missionDto);
|
|
}
|
|
|
|
$this->_rspData(array(
|
|
'task_list' => $taskDtoList,
|
|
));
|
|
}
|
|
|
|
public function commitInvitationTaskS(){
|
|
$missionId = getReqVal('mission_id', 0);
|
|
$missionMeta = mt\Task::get($missionId);
|
|
if (!$missionMeta) {
|
|
$this->_rspErr(1, 'mission_id parameter error');
|
|
return;
|
|
}
|
|
$missionService = new services\MissionService();
|
|
|
|
$missionDb = Mission::find($missionId);
|
|
$missionDto = $missionService->getMissionDto(
|
|
null, null, $missionDb, $missionMeta);
|
|
if (!$missionDto) {
|
|
$this->_rspErr(10, 'server internal error');
|
|
return;
|
|
}
|
|
if ($missionDto['state'] == Mission::RECEIVED_STATE) {
|
|
$this->_rspErr(2, "Can't get it again");
|
|
return;
|
|
}
|
|
if ($missionDto['state'] == Mission::NOT_FINISHED_STATE) {
|
|
$this->_rspErr(3, 'Mission objectives not achieved');
|
|
return;
|
|
}
|
|
|
|
if ($missionDto['state'] != Mission::RECEIVEABLE_STATE) {
|
|
$this->_rspErr(3, 'Unknown mission status');
|
|
return;
|
|
}
|
|
$dropMeta = mt\Drop::get($missionMeta['reward']);
|
|
if (!$dropMeta) {
|
|
$this->_rspErr(10, 'server internal error:' . $missionMeta['reward']);
|
|
return;
|
|
}
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$awardService = new services\AwardService();
|
|
$this->_scatterDrop('mission:' . $missionId, $dropMeta, $awardService, $propertyChgService);
|
|
Mission::add($missionId);
|
|
$this->_rspData(array(
|
|
'award' => $awardService->toDto(),
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
}
|
|
|
|
|
|
/*
|
|
//服务器大事件
|
|
public function serverTask(){
|
|
$currentMeta = \mt\ServerTaskTime::getCurrentTime();
|
|
if (! $currentMeta){
|
|
GlobalData::addServerTaskStatus(\mt\ServerTask::NOT_ACCOMPLISH_STATE);
|
|
$this->_rspErr(111, 'The activity has not started yet');
|
|
return;
|
|
}
|
|
$taskDtoList = array();
|
|
|
|
$taskListMeta = \mt\ServerTask::getMetaList();
|
|
$hashRateService = new services\HashRateService();
|
|
$hashRateService->init();
|
|
foreach ($taskListMeta as $taskMeta){
|
|
$taskDto = $hashRateService->serverTaskDto($taskMeta);
|
|
array_push($taskDtoList,$taskDto);
|
|
}
|
|
$count = 0;
|
|
|
|
foreach ($taskDtoList as $taskDto){
|
|
if ($taskDto['state'] == \services\HashRateService::FINISHED_STATE){
|
|
$count += 1;
|
|
}
|
|
}
|
|
|
|
if ($count == count($taskDtoList)){
|
|
GlobalData::addServerTaskStatus(\mt\ServerTask::ACCOMPLISH_MOBA_STATE);
|
|
}
|
|
// $drop_state = $hashRateService->getServerASKBoxMode();
|
|
$switch = 0;
|
|
if (myself()->_getNowTime() >= strtotime($currentMeta['income_start_time']) && $count != count($taskDtoList)){
|
|
$switch = 1;
|
|
}
|
|
$this->_rspData(array(
|
|
'obtain_start_time' => strtotime($currentMeta['obtain_start_time']),
|
|
'obtain_end_time' => strtotime($currentMeta['obtain_end_time']),
|
|
'income_start_time' => strtotime($currentMeta['income_start_time']),
|
|
'income_end_time' => strtotime($currentMeta['income_end_time']),
|
|
'status' => GlobalData::getServerTaskStatus(),
|
|
'switch' => $switch,
|
|
'taskDtoList' => $taskDtoList,
|
|
));
|
|
}
|
|
*/
|
|
} |