game2006api/webapp/controller/OtherController.class.php
aozhiwei c443e669ea 1
2024-08-21 14:26:36 +08:00

397 lines
14 KiB
PHP

<?php
require_once('services/PropertyChgService.php');
require_once('services/ServerSwitchService.php');
require_once('services/HashRateService.php');
require_once('mt/RankSeason.php');
require_once('mt/HashRateCommon.php');
require_once('mt/ActivityRewards.php');
require_once('mt/MapMode.php');
require_once('mt/ServerTaskTime.php');
require_once('mt/AchievementsCycle.php');
require_once('models/SignLog.php');
require_once('models/RankingSetRecord.php');
//require_once('models/Staking.php');
require_once('models/SeasonRanking.php');
require_once('models/RewardsCec.php');
require_once('models/GlobalData.php');
require_once('models/HashRate.php');
require_once('models/Hero.php');
require_once('models/HeroSkin.php');
require_once('models/Chip.php');
require_once('models/Bag.php');
use models\SignLog;
use phpcommon\SqlHelper;
use models\RankingSetRecord;
//use models\Staking;
use models\SeasonRanking;
use models\RewardsCec;
use models\GlobalData;
use models\HashRate;
use models\Hero;
use models\HeroSkin;
use models\Chip;
use models\Bag;
class OtherController extends BaseAuthedController {
const HERO = 1;
const CHIP = 2;
const BAG = 3;
const SIGN = 4;
const HASH_RATE = 5;
const HERO_SKIN = 6;
public function tag()
{
$types = getReqVal('types', 0);
$typeArr = explode(",",$types);
$list = array();
foreach ($typeArr as $type){
$state = 0;
switch ($type){
case self::HERO : {
$res = myself()->_getSelfMysql()->execQueryOne("SELECT COUNT(idx) as totalNum FROM t_hero WHERE account_id=:account AND is_old=:is_old LIMIT 1",array(
'account' => myself()->_getAccountId(),
'is_old' => 0,
));
if ($res['totalNum']){
$state = 1;
}
array_push($list,array(
'type' => self::HERO,
'state' => $state,
));
}
break;
case self::CHIP :{
$res = myself()->_getSelfMysql()->execQueryOne("SELECT COUNT(idx) as totalNum FROM t_chip WHERE account_id=:account AND is_old=:is_old LIMIT 1",array(
'account' => myself()->_getAccountId(),
'is_old' => 0,
));
if ($res['totalNum']){
$state = 1;
}
array_push($list,array(
'type' => self::CHIP,
'state' => $state,
));
}
break;
case self::BAG :{
$res = myself()->_getSelfMysql()->execQueryOne("SELECT COUNT(idx) as totalNum FROM t_bag WHERE account_id=:account AND item_num>0 AND is_old=:is_old LIMIT 1",array(
'account' => myself()->_getAccountId(),
'is_old' => 0,
));
if ($res['totalNum']){
$state = 1;
}
array_push($list,array(
'type' => self::BAG,
'state' => $state,
));
}
break;
case self::SIGN :{
$signDb = SignLog::find();
if ($signDb && $signDb['is_receive'] == 0){
$state = 1;
}
array_push($list,array(
'type' => self::SIGN,
'state' => $state,
));
}
break;
case self::HASH_RATE :{
$currentPeriod= \mt\AchievementsCycle::getCurrentPeriod();
if ($currentPeriod){
$hashRateService = new services\HashRateService();
$hashRateService->init();
if ($hashRateService->_isHaveRedTag($currentPeriod['id'])){
$state = 1;
}
}
array_push($list,array(
'type' => self::HASH_RATE,
'state' => $state,
));
}
break;
case self::HERO_SKIN :{
$res = myself()->_getSelfMysql()->execQueryOne("SELECT COUNT(idx) as totalNum FROM t_hero_skin WHERE account_id=:account AND is_old=:is_old LIMIT 1",array(
'account' => myself()->_getAccountId(),
'is_old' => 0,
));
if ($res['totalNum']){
$state = 1;
}
array_push($list,array(
'type' => self::HERO_SKIN,
'state' => $state,
));
}
}
}
$this->_rspData(array(
'list'=>$list
));
}
public function cancelTag()
{
$type = getReqVal('type', 0);
$unnid = getReqVal('item_unnid', 0);
$propertyChgService = new services\PropertyChgService();
switch ($type) {
case self::HERO :{
$heroDb = Hero::find($unnid);
if (!$heroDb){
$this->_rspErr(1, 'param item_unnid error');
return;
}
Hero::update($unnid,array(
'is_old' => 1
));
$propertyChgService->addHeroChg();
}
break;
case self::CHIP :{
$chipDb = Chip::find($unnid);
if (!$chipDb){
$this->_rspErr(2, 'param item_unnid error');
return;
}
Chip::update2($unnid,array(
'is_old' => 1
));
$propertyChgService->addChip();
}
break;
case self::BAG :{
$bagDb = Bag::findByUniId($unnid);
if (!$bagDb){
$this->_rspErr(3, 'param item_unnid error');
return;
}
SqlHelper::update
(myself()->_getSelfMysql(),
't_bag',
array(
'idx' => $unnid,
),
array(
'is_old' => 1
)
);
$propertyChgService->addBagChg();
}
break;
case self::HASH_RATE :{
}
break;
case self::HERO_SKIN :{
$skinDb = HeroSkin::find($unnid);
if (!$skinDb){
$this->_rspErr(1, 'param item_unnid error');
return;
}
HeroSkin::update($unnid,array(
'is_old' => 1
));
$propertyChgService->addHeroSkinChg();
}
break;
default:{
$this->_rspErr(4, 'param type error');
return;
}
}
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto()
));
}
public function getGameModuleState(){
//七日签到
$signState = 0;
$signDb = SignLog::find();
if(($signDb['days'] == 7 && $signDb['is_receive'] == 1) || $signDb['days'] > 7){
$signState = 1;
}
//排位
$rankState = 0;
$currSeasonMeta = mt\RankSeason::getCurrentSeason();
if($currSeasonMeta){
$rankState = 1;
}
$countdown = 0;
$nextCurrSeasonMeta = mt\RankSeason::getNextCurrentSeason();
if ($nextCurrSeasonMeta){
$countdown = strtotime($nextCurrSeasonMeta['start_time']) - myself()->_getNowTime();
}
//算力
$hashRateState = 0;
$hashRateMeta = \mt\HashRateCommon::find(1);
if (myself()->_getNowTime() > strtotime($hashRateMeta['start_time'])){
$hashRateState = 1;
}
$data = array(
"firstTopUp" => myself()->_getV(TN_FIRST_TUPOP_STATUS,0),
"signDayState" => $signState,
"rankState" => $rankState,
"nextRankSeasonCountdown" => $countdown,
"hashRateState" => $hashRateState,
);
$this->_rspData(array(
'data'=>$data
));
}
public function getRankingState(){
$recordDb = RankingSetRecord::find();
$data = array(
'state' => 0 ,
);
if ($recordDb){
$data = RankingSetRecord::toDto($recordDb);;
}
$this->_rspData(array(
'data'=>$data
));
}
public function getCecRewardHistory(){
$historyList = array();
$totalCecVal = 0;
SeasonRanking::getSeasonList(function ($row) use (&$historyList,&$totalCecVal) {
if ($row && $row['ranking_point'] > 0){
$totalCecVal += ($row['ranking_point'] * 0.15);
array_push($historyList,array(
'type' => 1,
'cecVal' => $row['ranking_point'] * 0.15,
'createtime' => $row['createtime'],
));
}
});
// \models\RewardsCec::all(function ($row) use (&$historyList,&$totalCecVal) {
// if ($row){
// $totalCecVal += $row['reward_cec'];
// array_push($historyList,array(
// 'type' => 2,
// 'cecVal' => $row['reward_cec'],
// 'createtime' => $row['createtime'],
// ));
// }
// });
// $stakingDb = Staking::all(myself()->_getAddress());
// foreach ($stakingDb as $row) {
// if ($row['status'] == Staking::REDEEM_STATUS) {
// $item = Staking::toDto($row);
// $totalCecVal += $item['total_rewards'];
// array_push($historyList, array(
// "type" => 3,
// "cecVal" => $item['total_rewards'],
// "createtime" => $item['redeem_time']
// ));
// }
// }
$rewards = \mt\ActivityRewards::find(myself()->_getAccountId());
if ($rewards){
foreach ($rewards as $reward){
array_push($historyList, array(
"type" => -1,
"event_name" => $reward['event_name'],
"cecVal" => $reward['cec'],
"createtime" => strtotime($reward['time'])
));
}
}
$this->_rspData(array(
'cec'=>$totalCecVal,
'list'=>$historyList,
));
}
public function getMapModeList()
{
$modeList = array();
// $taskStatus = GlobalData::getServerTaskStatus();
// $taskMeta = mt\ServerTaskTime::getCurrentTime();
$rankSeasonMeta = mt\RankSeason::getCurrentSeason();
mt\MapMode::traverseMeta(function($modeMeta) use(&$modeList, $rankSeasonMeta){
if ($modeMeta['is_open']) {
if ($modeMeta['limit_time'] == 1 && !$rankSeasonMeta) {
return true;
}
// if ($modeMeta['limit_time'] == 2 ){
// return true;
// }
$temp = array(
'id' => $modeMeta['id']
);
if ($modeMeta['daily_open_time']){
$dailyOpenTimeOffset = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ".$modeMeta['daily_open_time']));
$dailyEndTimeOffset = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ".$modeMeta['daily_end_time']));
$nowTimeOffset = myself()->_getDaySecondsOffset(myself()->_getNowTime());
$temp['daily_open_time'] = strtotime($modeMeta['daily_open_time']) ;
$temp['daily_end_time'] = strtotime($modeMeta['daily_end_time']);
$temp['state'] = $nowTimeOffset >= $dailyOpenTimeOffset && $nowTimeOffset <= $dailyEndTimeOffset ? 1 : 0;
}
if ($modeMeta['daily_open_time_2']){
$dailyOpenTimeOffset = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ".$modeMeta['daily_open_time_2']));
$dailyEndTimeOffset = myself()->_getDaySecondsOffset(strtotime("2024-6-22 ".$modeMeta['daily_end_time_2']));
$nowTimeOffset = myself()->_getDaySecondsOffset(myself()->_getNowTime());
$temp['daily_open_time_2'] = strtotime($modeMeta['daily_open_time_2']) ;
$temp['daily_end_time_2'] = strtotime($modeMeta['daily_end_time_2']);
$temp['state2'] = $nowTimeOffset >= $dailyOpenTimeOffset && $nowTimeOffset <= $dailyEndTimeOffset ? 1 : 0;
}
$isOpen = mt\MapMode::isOpen($modeMeta);
if ($isOpen) {
array_push(
$modeList,
$temp
);
}
}
return true;
});
$this->_rspData(array(
'mode_list' => $modeList
));
}
public function getServerSwitch(){
$version = getReqVal('_version', 0);
$packageId = getReqVal('_packageid', 0);
$row = SqlHelper::ormSelectOne(myself()->_getConfDbMysql(), 't_audit',
array(
'model' => $packageId
));
$examining = !empty($row) && $row['version'] == $version && $row['is_auditing'] ? 1 : 0;
$con = services\ServerSwitchService::getGameSwitch();
$this->_rspData(array(
'data' => $examining ? $con['auditing'] : $con['normal']
));
}
}