hashRateService = new services\HashRateService(); $this->hashRateService->init(); myself()->_verifySwitch('hashrate'); } public function taskList(){ $type = getReqVal('type', 1); $taskDtoList1 = array(); $taskDtoList2 = array(); $obtain_start_time = 0; $obtain_end_time = 0; $income_start_time = 0; $income_end_time = 0; $state = 0; $myHashRate = 0; $goldRate = 0; $currentPeriod= \mt\AchievementsCycle::getCurrentPeriod(); if ($currentPeriod){ // $mateList = \mt\AchievementsPower::getCustomTypeMetaList($type,$this->hashRateService); $taskList = $this->hashRateService->getHashRateTasks($type); foreach ($taskList as $task) { $taskDb = HashRate::find($task['task_id'],$currentPeriod['id']); $taskDto = $this->hashRateService->hashRateTaskDto($task,$taskDb,$currentPeriod['id']); array_push($taskDtoList1, $taskDto); } $mateList2 = \mt\AchievementsPower::getListByType(\mt\AchievementsPower::TYPE5); foreach ($mateList2 as $mate) { $taskDb = HashRate::find($mate['id'],$currentPeriod['id']); $mate['task_id'] = $mate['id']; $mate['current'] = 0; $taskDto = $this->hashRateService->hashRateTaskDto($mate,$taskDb,$currentPeriod['id']); array_push($taskDtoList2, $taskDto); } $obtain_start_time = strtotime($currentPeriod['obtain_start_time']); $obtain_end_time = strtotime($currentPeriod['obtain_end_time']); $income_start_time = strtotime($currentPeriod['income_start_time']); $income_end_time = strtotime($currentPeriod['income_end_time']); if(myself()->_getNowTime() >= $obtain_start_time && myself()->_getNowTime() <= $obtain_end_time){ $state = 1; } if (myself()->_getNowTime() >= $income_start_time && myself()->_getNowTime() <= $income_end_time){ $state = 2; } $myHashRate = HashRate::getMyHashRate( $currentPeriod['id']); $computeR = explode("|",mt\Parameter::getVal('economy_account_compute_R',0)); $k = 0; for ($i=0;$i= $computeR[$i]){ $k = $i; } } $computeE = explode("|",mt\Parameter::getVal('economy_account_compute_E',0)); $goldRate = $computeE[$k]; } $this->_rspData(array( 'task_list1' => $taskDtoList1, 'task_list2' => $taskDtoList2, 'obtain_start_time' => $obtain_start_time, 'obtain_end_time' => $obtain_end_time, 'income_start_time' => $income_start_time, 'income_end_time' => $income_end_time, 'state' => $state, 'refresh_times' => myself()->_getDailyV(TN_HASH_DAILY_REFRESH_TIMES,0), 'myHashRate' => $myHashRate, 'goldRate' => $goldRate, )); } public function commitTaskS(){ $currentPeriod= \mt\AchievementsCycle::getCurrentPeriod(); if (! $currentPeriod){ $this->_rspErr(1, 'Already ended'); return; } $taskId = getReqVal('task_id', 0); $taskMeta = \mt\AchievementsPower::find($taskId); if (!$taskMeta) { $this->_rspErr(1, 'task_id error'); return; } if ($taskMeta['task_type'] == \mt\AchievementsPower::TYPE5){ $task = array( 'task_id' => $taskMeta['id'], 'current' => 0, ); }else{ $taskList = $this->hashRateService->getHashRateTasks($taskMeta['task_type']); foreach ($taskList as $value){ if ($value['task_id'] == $taskId){ $task = $value; } } } if (!isset($task)){ $this->_rspErr(10, 'server internal error'); return; } $taskDb = HashRate::find($taskMeta['id'],$currentPeriod['id']); $taskDto = $this->hashRateService->hashRateTaskDto($task,$taskDb,$currentPeriod['id']); if (!$taskDto) { $this->_rspErr(10, 'server internal error'); return; } if ($taskDto['state'] == \services\HashRateService::RECEIVED_STATE) { $this->_rspErr(2, "Can't get it again"); return; } if ($taskDto['state'] == \services\HashRateService::NOT_FINISHED_STATE) { $this->_rspErr(3, 'task not achieved'); return; } $lootIndex = $taskMeta['Reward_Loot']; $reward = \services\LootService::dropOutItem($lootIndex); $rewardNum = $reward[0]['item_num']; HashRate::add($taskMeta['id'],$currentPeriod['id']); HashRate::rewardAdd($currentPeriod['id'],$rewardNum); // //刷新任务 // $refreshTimes = myself()->_getDailyV(TN_HASH_DAILY_REFRESH_TIMES,0); // $refreshTimesMax = \mt\Parameter::getVal('economy_account_compute_refresh_max',5); // if ($taskMeta['is_refresh'] == \mt\AchievementsPower::REFRESH_STATE && $refreshTimes < $refreshTimesMax){ // $this->hashRateService->refreshHashRateTask($taskMeta,$currentPeriod['id']); // } // $this->hashRateService->resetCurrentGoal($taskMeta); $this->_rspData(array( 'award' => $reward, )); } public function refreshTask(){ $currentPeriod= \mt\AchievementsCycle::getCurrentPeriod(); if (! $currentPeriod){ $this->_rspErr(1, 'Already ended'); return; } $taskId = getReqVal('task_id', 0); $taskMeta = \mt\AchievementsPower::find($taskId); if (!$taskMeta) { $this->_rspErr(1, 'task_id error'); return; } if ($taskMeta['is_refresh'] == \mt\AchievementsPower::NOT_REFRESH_STATE){ $this->_rspErr(1, 'Unable to refresh'); return; } $refreshTimes = myself()->_getDailyV(TN_HASH_DAILY_REFRESH_TIMES,0); $refreshTimesMax = \mt\Parameter::getVal('economy_account_compute_refresh_max',5); if ( $refreshTimes >= $refreshTimesMax){ $this->_rspErr(1, 'The number of refreshes was exhausted today'); return; } $this->hashRateService->refreshHashRateTask($taskMeta,$currentPeriod['id']); $this->_rspOk(); } public function redTips(){ $currentPeriod= \mt\AchievementsCycle::getCurrentPeriod(); if (!$currentPeriod){ $this->_rspErr(1, 'Already ended'); return; } $tips = array(); for ($i=1;$i<5;$i++){ foreach ($this->hashRateService->getHashRateTasks($i) as $task){ $taskDb = HashRate::find($task['task_id'],$currentPeriod['id']); $taskDto = $this->hashRateService->hashRateTaskDto($task,$taskDb,$currentPeriod['id']); if ($taskDto['state'] == \services\HashRateService::FINISHED_STATE){ array_push($tips,$i); } } } $this->_rspData(array( 'tips' => $tips, )); } }