From e56cb2bc52a0983b09fcb185b0783a23640be3eb Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Thu, 25 Apr 2024 14:03:33 +0800 Subject: [PATCH] 1 --- doc/ComputingPower.py | 163 ------ sql/gamedb.sql | 81 +-- webapp/controller/BagController.class.php | 5 +- .../controller/BaseAuthedController.class.php | 30 +- webapp/controller/BattleController.class.php | 6 - .../controller/BlockChainController.class.php | 5 - webapp/controller/BoxController.class.php | 25 - .../controller/ChipPageController.class.php | 2 +- .../ComputingPowerController.class.php | 509 ------------------ .../DailyRequestController.class.php | 73 +-- .../controller/FragmentController.class.php | 3 +- webapp/controller/GunController.class.php | 12 +- webapp/controller/HeroController.class.php | 7 - .../controller/HeroSkillController.class.php | 4 - webapp/controller/MarketController.class.php | 16 +- webapp/controller/MissionController.class.php | 5 - webapp/controller/OtherController.class.php | 11 +- webapp/controller/UserController.class.php | 12 - webapp/models/ComputingPower.php | 138 ----- webapp/models/CrystalRecord.php | 67 --- webapp/models/RewardsCec.php | 141 ----- 21 files changed, 17 insertions(+), 1298 deletions(-) delete mode 100644 doc/ComputingPower.py delete mode 100644 webapp/models/ComputingPower.php delete mode 100644 webapp/models/CrystalRecord.php diff --git a/doc/ComputingPower.py b/doc/ComputingPower.py deleted file mode 100644 index a3e081be..00000000 --- a/doc/ComputingPower.py +++ /dev/null @@ -1,163 +0,0 @@ -# -*- coding: utf-8 -*- - -import _common - -class ComputingPower(object): - - def __init__(self): - self.apis = [ - { - 'name': 'info', - 'desc': '获取算力信息', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=info', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['info', _common.ComputingPower(), '算力信息'] - ] - }, - { - 'name': 'getCrystalUi', - 'desc': '获取晶体ui信息', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=getCrystalUi', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['data', _common.CrystalUI(), '晶体的获取方式信息'] - ] - }, - { - 'name': 'exchangeCrystal', - 'desc': '兑换晶体', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=exchangeCrystal', - 'params': [ - _common.ReqHead(), - ['item_id', 0, '晶体item'], -# ['item_num', 0, '晶体数量'], - ], - 'response': [ - _common.RspHead(), - ['property_chg', _common.PropertyChg(), '属性变更'], - ] - }, - { - 'name': 'getExchangeCrystalRecord', - 'desc': '获取兑换晶体记录', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=getExchangeCrystalRecord', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['data', _common.ExchangeCrystalRecord(), '算力信息'] - ] - }, - { - 'name': 'exchangePower', - 'desc': '晶体兑换算力', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=exchangePower', - 'params': [ - _common.ReqHead(), - ['num1', 0, '晶体260001兑换数'], - ['num2', 0, '晶体260002兑换数'], - ['num3', 0, '晶体260003兑换数'], - ['num4', 0, '晶体260004兑换数'], - ], - 'response': [ - _common.RspHead(), - ['property_chg', _common.PropertyChg(), '属性变更'], - ] - }, - { - 'name': 'exchangeUplimit', - 'desc': '每周晶体兑换上限', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=exchangeUplimit', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['data', _common.ExchangeCrystalNum(), '本周期晶体兑换信息'] - ] - }, - { - 'name': 'getRewardHistory', - 'desc': '获取奖励历史', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=getRewardHistory', - 'params': [ - _common.ReqHead(), - ['star_time', 0, '开始时间,都没传查全部'], - ['end_time', 0, '结束时间,都没传查全部'], - ], - 'response': [ - _common.RspHead(), - ['!data', [_common.CECRewardHistory()], '算力信息'], - ['pending_rewards', '', '剩余总计'], - ] - }, - { - 'name': 'exchangeCrystalInfo', - 'desc': '晶体兑换信息', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=exchangeCrystalInfo', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['totalNum', 0, '可领取的总晶体'], - ['!playing', [Info()], '游戏行为'], - ['!staking', [Info()], '质押行为'], - ['!consuming', [Info()], '支出行为'], - ] - }, - { - 'name': 'claimCrystal', - 'desc': '一键领取晶体', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=claimCrystal', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['award', _common.Award(), '奖励信息'], - ['property_chg', _common.PropertyChg(), '属性变更'], - ] - }, - { - 'name': 'exchangePowerNew', - 'desc': '晶体兑换算力', - 'group': 'ComputingPower', - 'url': 'webapp/index.php?c=ComputingPower&a=exchangePowerNew', - 'params': [ - _common.ReqHead(), - ['num', 0, '晶体兑换数'], - ], - 'response': [ - _common.RspHead(), - ['property_chg', _common.PropertyChg(), '属性变更'], - ] - }, - ] - - -class Info(object): - - def __init__(self): - self.fields = [ - ['task_id', 0, 'task_id'], - ['uplimit', '', '上限数量 -1为无上限'], - ['chaim_num', 0, '可领取数量'], - ] \ No newline at end of file diff --git a/sql/gamedb.sql b/sql/gamedb.sql index a3232881..cd51c00a 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1578,85 +1578,8 @@ CREATE TABLE `t_market_transaction_record` ( ) ENGINE=InnoDB AUTO_INCREMENT=10002 DEFAULT CHARSET=utf8; - -- --- Table structure for table `t_crystal_exchange_record` --- - -DROP TABLE IF EXISTS `t_crystal_exchange_record`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `t_crystal_exchange_record` ( - `idx` bigint(20) NOT NULL AUTO_INCREMENT, - `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', - `address` varchar(60) COMMENT 'address', - `period` int(11) NOT NULL DEFAULT '0' COMMENT '第几期', - `item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id', - `item_num` bigint NOT NULL DEFAULT '0' COMMENT '道具数量', - `createtime` int(11) NOT NULL COMMENT '创建时间', - `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', - PRIMARY KEY (`idx`), - KEY `account_id` (`account_id`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `t_power_exchange_record` --- - -DROP TABLE IF EXISTS `t_power_exchange_record`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `t_power_exchange_record` ( - `idx` bigint(20) NOT NULL AUTO_INCREMENT, - `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', - `address` varchar(60) COMMENT 'address', - `period` int(11) NOT NULL DEFAULT '0' COMMENT '第几期', - `item_num1` int(11) NOT NULL DEFAULT '0' COMMENT '晶体道具260001兑换算力数量', - `item_num2` int(11) NOT NULL DEFAULT '0' COMMENT '晶体道具260002兑换算力数量', - `item_num3` int(11) NOT NULL DEFAULT '0' COMMENT '晶体道具260003兑换算力数量', - `item_num4` int(11) NOT NULL DEFAULT '0' COMMENT '晶体道具260004兑换算力数量', - `total_num` double NOT NULL DEFAULT '0' COMMENT '算力总量', - `createtime` int(11) NOT NULL COMMENT '创建时间', - `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', - PRIMARY KEY (`idx`), - KEY `account_id` (`account_id`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Table structure for table `t_computing_power_period` --- - -DROP TABLE IF EXISTS `t_hash_rate_reward`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `t_hash_rate_reward` ( - `idx` bigint(20) NOT NULL AUTO_INCREMENT, - `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', - `address` varchar(60) COMMENT 'address', - `period` int(11) NOT NULL DEFAULT '0' COMMENT '第几期', - `power` varchar(60) COMMENT '算力', - `reward_cec` varchar(60) COMMENT 'reward cec', - `reward1` int(11) NOT NULL DEFAULT '0' COMMENT '第1周奖励', - `reward2` int(11) NOT NULL DEFAULT '0' COMMENT '第2周奖励', - `reward3` int(11) NOT NULL DEFAULT '0' COMMENT '第3周奖励', - `reward4` int(11) NOT NULL DEFAULT '0' COMMENT '第4周奖励', - `txHash1` varchar(60) NOT NULL DEFAULT '' COMMENT '地址1', - `txHash2` varchar(60) NOT NULL DEFAULT '' COMMENT '地址2', - `txHash3` varchar(60) NOT NULL DEFAULT '' COMMENT '地址3', - `txHash4` varchar(60) NOT NULL DEFAULT '' COMMENT '地址4', - - `createtime` int(11) NOT NULL COMMENT '创建时间', - `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', - PRIMARY KEY (`idx`), - KEY `account_id` (`account_id`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; - - --- --- Table structure for table `t_computing_power_period` +-- Table structure for table `t_ranking_settlement_record` -- DROP TABLE IF EXISTS `t_ranking_settlement_record`; @@ -1679,7 +1602,7 @@ CREATE TABLE `t_ranking_settlement_record` ( -- --- Table structure for table `t_computing_power_period` +-- Table structure for table `t_staking` -- DROP TABLE IF EXISTS `t_staking`; diff --git a/webapp/controller/BagController.class.php b/webapp/controller/BagController.class.php index 74f54b0f..5b13a903 100644 --- a/webapp/controller/BagController.class.php +++ b/webapp/controller/BagController.class.php @@ -8,8 +8,7 @@ require_once('mt/LootConfig.php'); require_once('models/Bag.php'); require_once('models/Hero.php'); -require_once('models/Gun.php'); -require_once('models/Nft.php'); + require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); @@ -20,8 +19,6 @@ require_once('services/LootService.php'); use phpcommon\SqlHelper; use models\Bag; use models\Hero; -use models\Gun; -use models\Nft; use services\LogService; class BagController extends BaseAuthedController { diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index 2879da8e..baf5accb 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -16,7 +16,6 @@ require_once('models/Parachute.php'); require_once('models/Chip.php'); require_once('models/Pass.php'); require_once('models/Avatar.php'); -require_once('models/HashRate.php'); require_once('mt/Parameter.php'); require_once('mt/RankSeason.php'); require_once('mt/LevelUp.php'); @@ -40,7 +39,6 @@ use models\UserSeasonRing; use models\Chip; use models\Pass; use models\Avatar; -use models\HashRateTask; use services\LogService; class BaseAuthedController extends BaseController { @@ -119,7 +117,6 @@ class BaseAuthedController extends BaseController { } } - $this->_userLvRestriction(); } /*if (SERVER_ENV == _ONLINE) { @@ -132,32 +129,7 @@ class BaseAuthedController extends BaseController { }*/ } - protected function _userLvRestriction(){ - $userDb = $this->_getOrmUserInfo(); - $controller = getReqVal('c', ''); - switch ($controller){ - case "Chip" : { - if (getReqVal('a', '') != 'chipList' && $userDb['star_num'] < \mt\StarLevel::STAR_NUM_CHIP_LIMIT){ - $this->_rspErr(1,'Not agreed terms. star number of need ' .\mt\StarLevel::STAR_NUM_CHIP_LIMIT); - die(); - } - } - break; - case "Emoji" : { - if ($userDb['star_num'] < \mt\StarLevel::STAR_NUM_EMOJI_LIMIT){ - $this->_rspErr(1,'Not agreed terms star number of need ' .\mt\StarLevel::STAR_NUM_EMOJI_LIMIT); - die(); - } - } - break; - case "Fragment" : { - if (getReqVal('a', '') == 'syntheticFragment' && $userDb['star_num'] < \mt\StarLevel::STAR_NUM_PIECE_LIMIT){ - $this->_rspErr(1,'Not agreed terms star number of need ' .\mt\StarLevel::STAR_NUM_PIECE_LIMIT); - die(); - } - } - } - } + protected function updateSession($accountId, $sessionId) { diff --git a/webapp/controller/BattleController.class.php b/webapp/controller/BattleController.class.php index 72101b72..b5a94865 100644 --- a/webapp/controller/BattleController.class.php +++ b/webapp/controller/BattleController.class.php @@ -3,23 +3,18 @@ require_once('phpcommon/tglog.php'); require_once('models/Hero.php'); require_once('models/HeroSkin.php'); require_once('models/Gun.php'); -require_once('models/Chip.php'); require_once('models/Bag.php'); require_once('models/DynData.php'); require_once('models/BattleSettlement.php'); -require_once('models/BattleHistory.php'); require_once('models/User.php'); require_once('models/Parachute.php'); require_once('models/ChipPage.php'); require_once('models/Battle.php'); -require_once('models/HashRate.php'); require_once('services/BattleDataService.php'); require_once('services/TameBattleDataService.php'); require_once('services/RoomBattleDataService.php'); require_once('services/FormulaService.php'); require_once('mt/RankSeason.php'); -require_once('mt/ServerTask.php'); -require_once('mt/ServerTaskTime.php'); require_once('mt/Robot.php'); require_once('mt/Skill.php'); require_once('mt/MapMode.php'); @@ -30,7 +25,6 @@ use models\HeroSkin; use models\Gun; use models\Bag; use models\DynData; -use models\BattleHistory; use models\BattleSettlement; use models\User; use models\Parachute; diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 3b1e811e..9f4fa3bb 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -5,7 +5,6 @@ require_once('mt/Item.php'); require_once('mt/Drop.php'); require_once('mt/Hero.php'); -require_once('models/Bag.php'); require_once('models/Hero.php'); require_once('models/Gun.php'); require_once('models/Nft.php'); @@ -13,17 +12,14 @@ require_once('models/Chip.php'); require_once('models/Transaction.php'); require_once('models/BuyRecord.php'); require_once('models/Chip.php'); -require_once('models/TransactionPrefee.php'); require_once('models/BcOrder.php'); require_once('models/Mall.php'); require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); -require_once('services/NameService.php'); require_once('services/BlockChainService.php'); use phpcommon\SqlHelper; -use models\Bag; use models\Hero; use models\Gun; use models\Nft; @@ -32,7 +28,6 @@ use models\BuyRecord; use models\Chip; use models\BcOrder; use models\Mall; -use models\TransactionPrefee; use services\BlockChainService; diff --git a/webapp/controller/BoxController.class.php b/webapp/controller/BoxController.class.php index eb81100a..bc2e8bf6 100644 --- a/webapp/controller/BoxController.class.php +++ b/webapp/controller/BoxController.class.php @@ -1,31 +1,6 @@ 0, - "period_end" => 0, - "await_time" => 0, - "assignable_cec" => 0, - "cec_pool" => 0, - "total_exchange_hash_rate" => 0, - "total_hash_rate" => 0, - - ); - $reward = array( - "cec" => 0, - "point" => 0, - ); - $last_period = array( - "period_begin" => 0, - "period_end" => 0, - "reward" => 0, - ); - - $lastMeta = \mt\HashRateCommon::getLastPeriod(); - $currentMeta = \mt\HashRateCommon::getCurrentPeriod(); - $nextMeta = \mt\HashRateCommon::getNextPeriod(); - if (!$currentMeta && $lastMeta){ - $ownerNum = ComputingPower::getOwnedBH($lastMeta['id']); - $totalNum = ComputingPower::getTotalBH($lastMeta['id']); - $target = \services\NumberService::ceilEx(min($totalNum / $lastMeta['cec_pool'] , 1),6); - if ($totalNum == 0) { - $ratio = 0; - }else{ - $ratio = $ownerNum/$totalNum; - } - $reward['cec'] = \services\NumberService::ceilEx($currentMeta['cec_pool'] * $target * $ratio,2); - if ($nextMeta){ - $period_state = 1; - $curr_period['period_begin'] = strtotime($nextMeta['start_time']); - $curr_period['period_end'] = strtotime($nextMeta['end_time']); - $curr_period['await_time'] = strtotime($nextMeta['start_time']) - myself()->_getNowTime(); - }else{ - $period_state = 2; - } - } - if ($currentMeta){ - $period_state = 0; - $ownerNum = ComputingPower::getOwnedBH($currentMeta['id']); - $totalNum = ComputingPower::getTotalBH($currentMeta['id']); - $curr_period['period_begin'] = strtotime($currentMeta['start_time']); - $curr_period['period_end'] = strtotime($currentMeta['end_time']); - $curr_period['assignable_cec'] = min($currentMeta['cec_pool'],$totalNum); - $curr_period['cec_pool'] = $currentMeta['cec_pool']; - $curr_period['total_exchange_hash_rate'] = $ownerNum; - $curr_period['total_hash_rate'] = $totalNum; - $curr_period['await_time'] = strtotime($currentMeta['end_time']) - myself()->_getNowTime(); - - $target = \services\NumberService::ceilEx(min($totalNum / $currentMeta['cec_pool'] , 1),6); - if ($totalNum == 0) { - $ratio = 0; - }else{ - $ratio = $ownerNum/$totalNum; - } - $reward['cec'] = \services\NumberService::ceilEx($currentMeta['cec_pool'] * $target * $ratio,2); - $reward['point'] = $ownerNum; - } - - if ($lastMeta){ - $last_period['period_begin'] = strtotime($lastMeta['start_time']); - $last_period['period_end'] = strtotime($lastMeta['end_time']); - $cecDb = RewardsCec::findByAccount(myself()->_getAccountId(),$lastMeta['id']); - $last_period['reward'] = $cecDb ? $cecDb['reward_cec'] : 0; - $last_period['last_hash_rate'] = ComputingPower::getOwnedBH($lastMeta['id']); - } - - - - $crystalDb = Bag::find(ComputingPower::CRYSTAL_NEW); - $info = array( - 'period_state' => $period_state, - 'curr_period' => $curr_period, - 'curr_reward' => $reward, - 'last_period' => $last_period, - 'listing_state' => LISTING_SWITCH, - 'owned_cec' => RewardsCec::getTotalCecNum(), - 'owned_total_hash_rate' =>ComputingPower::getMyTotalBH(), - 'owned_total_crystal' =>$crystalDb ? $crystalDb['item_num'] : 0, - ); - $this->_rspData(array( - 'info' => $info - )); - } - - //弃用 - public function getCrystalUi(){ - $crystalList = array(); - $itemMetas = \mt\Item::getMetaListByType(\mt\Item::CRYSTAL_TYPE); - $hashRateService = new \services\HashRateService(); - foreach ($itemMetas as $meta){ - $crystalDto = array(); - $hashRateService->getCrystalDto($meta,$crystalDto); - array_push($crystalList,$crystalDto); - } - $this->_rspData(array( - 'data' => $crystalList - )); - } - - //弃用 - public function exchangeCrystal(){ - $itemId = getReqVal('item_id', 0); - $itemMeta = \mt\Item::get($itemId); - if (!$itemMeta || $itemMeta['type'] != \mt\Item::CRYSTAL_TYPE ){ - $this->_rspErr(1, 'param error'); - return ; - } - $hashRateMeta = HashRate::findHash($itemId); - if (!$hashRateMeta){ - $this->_rspErr(1, 'param error'); - return ; - } - $param = explode('|',$hashRateMeta['parameter']); - $paramEd = explode(':',$param[0]); - $paramEx = explode(':',$param[1]); - $crystalNum = 0; - switch ($itemId){ - case ComputingPower::CRYSTAL1 : { - $killsNum = myself()->_getV(TN_TOTAL_KILLS_NUM,0); - $killsNumEd = myself()->_getV(TN_TOTAL_KILLS_NUM,-1); - $killsNumEx = $killsNum - $killsNumEd; - $starNum = myself()->_getV(TN_TOTAL_STAR_NUM,0); - $starNumEd = myself()->_getV(TN_TOTAL_STAR_NUM,-1); - $starNumEx = $starNum - $starNumEd ; - $crystalNum = max(0,floor($killsNumEx / $paramEd[0]) * $paramEd[1] + - floor($starNumEx / $paramEx[0]) * $paramEx[1] ); - } - break; - case ComputingPower::CRYSTAL2 : { - $consumeCost = myself()->_getV(TN_TOTAL_DIAMOND_CONSUME,0); - $consumeCostEd = myself()->_getV(TN_TOTAL_DIAMOND_CONSUME,-1); - $consumeCostEx = $consumeCost - $consumeCostEd ; - $crystalNum = max(0,floor($consumeCostEx / \services\HashRateService::EXCHANGE_RATE / $paramEd[0]) * $paramEd[1]); - } - break; - case ComputingPower::CRYSTAL3 : { - $consumeCost = myself()->_getV(TN_TOTAL_CEG_CONSUME,0); - $consumeCostEd = myself()->_getV(TN_TOTAL_CEG_CONSUME,-1); - $consumeCostEx = $consumeCost - $consumeCostEd; - $crystalNum = max(0,floor($consumeCostEx / \services\HashRateService::EXCHANGE_RATE / $paramEd[0]) * $paramEd[1]); - } - break; - case ComputingPower::CRYSTAL4 : { - $recordDb = CrystalRecord::getNewestRecordOne($itemId); - error_log('exchangeCrystal:'.json_encode($recordDb)); - if ($recordDb && myself()->_getNowDaySeconds() == myself()->_getDaySeconds($recordDb['createtime'])){ - $this->_rspErr(1, 'There are no available crystals'); - return ; - } -// $rate = Parameter::getVal('cec_exchange_rate',10); - $cecVal = Staking::getStakingTotalValue(); - $crystalNum = max(0,floor($cecVal / $paramEd[0]) * $paramEd[1]); - - } - } - - if ($crystalNum < 1){ - $this->_rspErr(1, 'There are no available crystals'); - return ; - } - - - - $items = array( - array( - 'item_id' => $itemId, - 'item_num' => $crystalNum, - ) - ); - $propertyChgService = new services\PropertyChgService(); - $awardService = new services\AwardService(); - $this->_addItems($items,$awardService,$propertyChgService); - CrystalRecord::addCrystalRecord($itemId,$crystalNum); - switch ($itemId) { - case ComputingPower::CRYSTAL1 : { - - $killsNum = myself()->_getV(TN_TOTAL_KILLS_NUM,0); - $killsNumEd = myself()->_getV(TN_TOTAL_KILLS_NUM,-1); - $starNum = myself()->_getV(TN_TOTAL_STAR_NUM,0); - $starNumEd = myself()->_getV(TN_TOTAL_STAR_NUM,-1); - //floor($killsNumEx / $paramEd[0]) * $paramEd[1] 222 100:3 222/100=2 2*3=6 6/3=2 2*100 - $newKillsNum = floor(($killsNum-$killsNumEd)/$paramEd[0]) * $paramEd[0]; - myself()->_incV(TN_TOTAL_KILLS_NUM,-1,$newKillsNum); - $newStarNum = floor(($starNum-$starNumEd)/$paramEx[0]) * $paramEx[0]; - myself()->_incV(TN_TOTAL_STAR_NUM,-1,$newStarNum); - } - break; - case ComputingPower::CRYSTAL2 : { - myself()->_incV(TN_TOTAL_DIAMOND_CONSUME,-1,$crystalNum / $paramEd[1] * $paramEd[0] * \services\HashRateService::EXCHANGE_RATE); - } - break; - case ComputingPower::CRYSTAL3 : { - myself()->_incV(TN_TOTAL_CEG_CONSUME,-1,$crystalNum / $paramEd[1] * $paramEd[0] * \services\HashRateService::EXCHANGE_RATE); - } - break; - } - $this->_rspData(array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - )); - } - - public function getExchangeCrystalRecord(){ - $crystalRecordList = array(); - CrystalRecord::getCrystalRecordList(function ($row) use (&$crystalRecordList) { - array_push($crystalRecordList,array( - 'item_id' => $row['item_id'], - 'item_num' => $row['item_num'], - 'createtime' => $row['createtime'], - )); - }); - $this->_rspData(array( - 'data' => $crystalRecordList, - )); - } - - public function exchangeUplimit(){ - $currentMeta = \mt\HashRateCommon::getCurrentPeriod(); - if (!$currentMeta){ - $this->_rspErr(1, 'kindly await'); - return ; - } - $list = ComputingPower::findByPeriod($currentMeta['id']); - $this->_rspData(array( - 'data' => $list, - )); - } - - //弃用 - public function exchangePower(){ - $num1 = getReqVal('num1', 0); - $num2 = getReqVal('num2', 0); - $num3 = getReqVal('num3', 0); - $num4 = getReqVal('num4', 0); - $currentMeta = \mt\HashRateCommon::getCurrentPeriod(); - if (!$currentMeta){ - $this->_rspErr(1, 'kindly await'); - return ; - } - if (!$num1 && !$num2 && !$num3 && !$num4 ){ - $this->_rspErr(1, 'exchange none'); - return ; - } - $BH = 0 ; - $costItems = array(); - if ($num1 > 0){ - $meta = \mt\HashRate::findHash(ComputingPower::CRYSTAL1); - $this->_verificationCeiling($currentMeta['id'],$meta,$num1,$num2,$num3,$num4); - $BH += $num1 * $meta['amount_bh']; - array_push($costItems,array( - 'item_id' => ComputingPower::CRYSTAL1, - 'item_num' => $num1 - )); - } - if ($num2 > 0){ - $meta = \mt\HashRate::findHash(ComputingPower::CRYSTAL2); - $this->_verificationCeiling($currentMeta['id'],$meta,$num1,$num2,$num3,$num4); - $BH += $num2 * $meta['amount_bh']; - array_push($costItems,array( - 'item_id' => ComputingPower::CRYSTAL2, - 'item_num' => $num2 - )); - } - if ($num3 > 0){ - $meta = \mt\HashRate::findHash(ComputingPower::CRYSTAL3); - $this->_verificationCeiling($currentMeta['id'],$meta,$num1,$num2,$num3,$num4); - $BH += $num3 * $meta['amount_bh']; - array_push($costItems,array( - 'item_id' => ComputingPower::CRYSTAL3, - 'item_num' => $num3 - )); - } - if ($num4 > 0){ - $meta = \mt\HashRate::findHash(ComputingPower::CRYSTAL4); - $this->_verificationCeiling($currentMeta['id'],$meta,$num1,$num2,$num3,$num4); - $BH += $num4 * $meta['amount_bh']; - array_push($costItems,array( - 'item_id' => ComputingPower::CRYSTAL4, - 'item_num' => $num4 - )); - } - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $this->_decItems($costItems); - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addBagChg(); - ComputingPower::addPowerRecord( - array( - 'period' => $currentMeta['id'], - 'item_num1' => $num1, - 'item_num2' => $num2, - 'item_num3' => $num3, - 'item_num4' => $num4, - 'total_num' => $BH, - ) - ); - $this->_rspData(array( - 'property_chg' => $propertyChgService->toDto(), - )); - - } - - public function getRewardHistory(){ - $starTime = getReqVal('star_time', 0); - $endTime = getReqVal('end_time', 0); - $historyDb = RewardsCec::getHistoryByTime($starTime,$endTime); - $historyList = array(); - $pendingNum = 0; - foreach ($historyDb as $row){ - $historyDto = RewardsCec::toDto($row); - $pendingNum += $historyDto['pending_num']; - array_push($historyList,$historyDto); - } - $this->_rspData(array( - 'data' => $historyList, - 'pending_rewards' => strval($pendingNum), - )); - } - - public function exchangeCrystalInfo(){ - $hashRateService = new \services\HashRateService(); - $crystalInfo = $hashRateService->getCrystalValue(); - $this->_rspData(array( - 'crystalInfo' => $crystalInfo - )); - } - - public function claimCrystal(){ - $hashRateService = new \services\HashRateService(); - $crystalInfo = $hashRateService->getCrystalValue(); - if ($crystalInfo['totalNum'] < 1){ - $this->_rspErr(1, 'No crystals available at this time'); - return ; - } - foreach ($crystalInfo['playing'] as $val){ - if ($val['chaim_num'] < 1){ - continue; - } - $hashRateMt = \mt\HashRateTask::find($val['task_id']); - switch ($val['task_id']){ - case HashRateTask::RANK_TYPE :{ - $chaimUpTotal = $val['chaim_num'] / $hashRateMt['reward']; - HashRateTask::updateKv($val['task_id'],array( - 'claim_total' => function () use($chaimUpTotal) { - return "claim_total + ${chaimUpTotal}"; - }, - 'modifytime' => myself()->_getNowTime() - )); - } - break; - default : { - - if ($val['task_id'] == HashRateTask::BATTLE_TIME_TYPE){ - $chaimTotal = $val['chaim_num'] / $hashRateMt['reward'] * $hashRateMt['target'] * 1000; - }else{ - $chaimTotal = $val['chaim_num'] / $hashRateMt['reward'] * $hashRateMt['target']; - } - HashRateTask::incDailyReward($val['task_id'],$val['chaim_num'],$chaimTotal); - } - } - } - foreach ($crystalInfo['staking'] as $val){ - if ($val['chaim_num'] > 0){ - HashRateTask::updateKv($val['task_id'],array( - 'claim_day' => 1, - 'modifytime' => myself()->_getNowTime() - )); - } - } - - foreach ($crystalInfo['consuming'] as $val){ - if ($val['chaim_num'] > 0){ - $hashRateMt = \mt\HashRateTask::find($val['task_id']); - $chaimTotal = $val['chaim_num'] / $hashRateMt['reward'] * $hashRateMt['target'] * \services\HashRateService::EXCHANGE_RATE; - myself()->_incV(TN_TOTAL_DIAMOND_CONSUME,-1,$chaimTotal); - } - } - $items = array( - array( - 'item_id' => ComputingPower::CRYSTAL_NEW, - 'item_num' => $crystalInfo['totalNum'], - ) - ); - $propertyChgService = new services\PropertyChgService(); - $awardService = new services\AwardService(); - $this->_addItems($items,$awardService,$propertyChgService); - CrystalRecord::addCrystalRecord(ComputingPower::CRYSTAL_NEW,$crystalInfo['totalNum']); - $this->_rspData(array( - 'award' => $awardService->toDto(), - 'property_chg' => $propertyChgService->toDto(), - )); - } - - public function exchangePowerNew(){ - $num = getReqVal('num', 0); - $currentMeta = \mt\HashRateCommon::getCurrentPeriod(); - if (!$currentMeta){ - $this->_rspErr(1, 'kindly await'); - return ; - } - if (!$num){ - $this->_rspErr(1, 'exchange none'); - return ; - } - //校验是否兑换上限 - { - - } - $BH = $num; - $costItems = array(); - array_push($costItems,array( - 'item_id' => ComputingPower::CRYSTAL_NEW, - 'item_num' => $num - )); - $lackItem = null; - if (!$this->_hasEnoughItems($costItems, $lackItem)) { - $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); - return; - } - $this->_decItems($costItems); - $propertyChgService = new services\PropertyChgService(); - $propertyChgService->addBagChg(); - ComputingPower::addPowerRecord( - array( - 'period' => $currentMeta['id'], - 'item_num1' =>$num, - 'item_num2' => 0, - 'item_num3' => 0, - 'item_num4' => 0, - 'total_num' => $BH, - ) - ); - $this->_rspData(array( - 'property_chg' => $propertyChgService->toDto(), - )); - } - - private function _verificationCeiling($period,$meta,$num1,$num2,$num3,$num4){ - $list = ComputingPower::findByPeriod($period); - switch ($meta['item_id']){ - case ComputingPower::CRYSTAL1 : { - if ($list['num1'] + $num1 > $meta['week_max']){ - $this->_rspErr(1, 'Micro crystal exchange ceiling'); - die ; - } - } - break; - case ComputingPower::CRYSTAL2 : { - if ($list['num2'] + $num2 > $meta['week_max']){ - $this->_rspErr(1, 'Standard crystal exchange ceiling'); - die ; - } - } - break; - case ComputingPower::CRYSTAL3 : { - if ($list['num3'] + $num3 > $meta['week_max']){ - $this->_rspErr(1, 'Large crystal exchange ceiling'); - die ; - } - } - break; - case ComputingPower::CRYSTAL4 : { - if ($list['num4'] + $num4 > $meta['week_max']){ - $this->_rspErr(1, 'Giant crystal exchange ceiling'); - die ; - } - } - break; - } - } - - - } \ No newline at end of file diff --git a/webapp/controller/DailyRequestController.class.php b/webapp/controller/DailyRequestController.class.php index 75509aa9..37520704 100644 --- a/webapp/controller/DailyRequestController.class.php +++ b/webapp/controller/DailyRequestController.class.php @@ -11,15 +11,13 @@ require_once('mt/HashRateCommon.php'); require_once('models/RealtimeData.php'); require_once('models/Season.php'); require_once('models/RankingSetRecord.php'); -require_once('models/ComputingPower.php'); -require_once('models/RewardsCec.php'); + use phpcommon\SqlHelper; use models\RealtimeData; use models\Season; use models\RankingSetRecord; -use models\ComputingPower; -use models\RewardsCec; + class DailyRequestController extends BaseAuthedController { private $awardService = null; @@ -31,51 +29,6 @@ class DailyRequestController extends BaseAuthedController { $this->awardService = new services\AwardService(); } - /** - * 星星之路的赛季结算 - */ - public function missionStarSeasonSettlement(){ - $season = RealtimeData::getMissionSeason(); - $currMissionSeasonMeta = \mt\StarLevel::getCurrentSeason(); - if ($currMissionSeasonMeta && $currMissionSeasonMeta['id'] > $season){ - $max_star_num = mt\Parameter::getVal('starroad_restart_point',400); - $rows = myself()->_getMysql('')->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){ - $crystalNum = round($row['star_num']/1000); - myself()->switchAccount($row['account_id']); - $items = array( - array( - 'item_id' => ComputingPower::CRYSTAL1, - 'item_num' => $crystalNum, - ) - ); - myself()->_addItems($items, null, $this->propertyChgService); - myself()->_updateUserInfo(array( - 'star_num' => $max_star_num, - )); -// myself()->_getMysql('')->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("DailyRequestController : Mission Star Season ".$season." Settlement Success !" . " Request Time : ". date('Y-M-D h:i:s',time())); - RealtimeData::setMissionSeason($currMissionSeasonMeta['id']); - $this->_rspData(array('message'=>'星星之路结算成功')); - return; - } - $this->_rspOk(); - } - /** * 通行证的赛季结算 */ @@ -167,27 +120,5 @@ class DailyRequestController extends BaseAuthedController { $this->_rspOk(); } - /** - * 算力周期cec计算 - */ - public function computingPowerRewards(){ - $currentMeta = \mt\HashRateCommon::getLatestPeriod(); - if (\mt\HashRateCommon::checkAwaitTime()){ - $temp = ComputingPower::getAccountGroup($currentMeta['id']); - if (! $temp){ - error_log("computingPowerRewards : No one involved"); - die; - } - foreach ($temp as $row){ - if ( ! RewardsCec::findByAccount($row['account_id'],$currentMeta['id'])){ - RewardsCec::celCecReward($row['account_id'],$currentMeta); - error_log("computingPowerRewards : ACCOUNT_ID_{$row['account_id']} CEC Reward record completion"); - } - } - $this->_rspData(array('message'=>'算力结算成功')); - return; - } - $this->_rspOk(); - } } \ No newline at end of file diff --git a/webapp/controller/FragmentController.class.php b/webapp/controller/FragmentController.class.php index ac75951a..18b0a35c 100644 --- a/webapp/controller/FragmentController.class.php +++ b/webapp/controller/FragmentController.class.php @@ -1,6 +1,6 @@ _getAccountId(); - } - $rows = SqlHelper::ormSelect( - myself()->_getMysql($account), - 't_power_exchange_record', - array( - 'account_id'=>$account, - 'period' => $period - ) - ); - $my_total_num = 0; - if ($rows){ - foreach ($rows as $row){ - $my_total_num += $row['total_num']; - } - } - - return NumberService::ceilEx($my_total_num,6); - } - - //获取全服总算力 - public static function getTotalBH($period){ - $rows = SqlHelper::select( - myself()->_getMysql(''), - 't_power_exchange_record', - array( - "period", - "total_num" - ), - array( - 'period' => $period - ) - ); - $total_num = 0; - if ($rows){ - foreach ($rows as $row){ - $total_num += $row['total_num']; - } - } - return $total_num; - } - - //获取我的总算力 - public static function getMyTotalBH(){ - $rows = SqlHelper::select( - myself()->_getSelfMysql(), - 't_power_exchange_record', - array( - "period", - "total_num" - ), - array( - 'account_id'=>myself()->_getAccountId(), - ) - ); - $total_num = 0; - if ($rows){ - foreach ($rows as $row){ - $total_num += $row['total_num']; - } - } - return $total_num; - } - - public static function findByPeriod($period){ - $rows = SqlHelper::ormSelect( - myself()->_getSelfMysql(), - 't_power_exchange_record', - array( - 'account_id'=>myself()->_getAccountId(), - 'period' => $period - ) - ); - $list = array( - 'num1' => 0, - 'num2' => 0, - 'num3' => 0, - 'num4' => 0, - ); - if ($rows){ - foreach ($rows as $row){ - $list['num1'] += $row['item_num1']; - $list['num2'] += $row['item_num2']; - $list['num3'] += $row['item_num3']; - $list['num4'] += $row['item_num4']; - } - } - return $list; - } - - public static function addPowerRecord($fieldKv){ - SqlHelper::insert( - myself()->_getSelfMysql(), - 't_power_exchange_record', - array( - 'account_id'=>myself()->_getAccountId(), - 'address'=>myself()->_getAddress(), - 'period'=>$fieldKv['period'], - 'item_num1'=>$fieldKv['item_num1'], - 'item_num2' => $fieldKv['item_num2'], - 'item_num3' => $fieldKv['item_num3'], - 'item_num4' => $fieldKv['item_num4'], - 'total_num' => $fieldKv['total_num'], - 'createtime'=>myself()->_getNowTime(), - 'modifytime'=>myself()->_getNowTime(), - ) - ); - } - - public static function getAccountGroup($period){ - $sql = "select account_id,`period` from t_power_exchange_record where `period` = $period group by account_id"; - $rows = myself()->_getMysql('')->execQuery($sql); - return $rows; - } - - -} \ No newline at end of file diff --git a/webapp/models/CrystalRecord.php b/webapp/models/CrystalRecord.php deleted file mode 100644 index 02f7ea3c..00000000 --- a/webapp/models/CrystalRecord.php +++ /dev/null @@ -1,67 +0,0 @@ -_getSelfMysql(), - 't_crystal_exchange_record', - array( - 'account_id'=>myself()->_getAccountId(), - 'item_id'=>ComputingPower::CRYSTAL_NEW, - ), - function ($row) use($cb) { - $cb($row); - } - ); - } - - public static function getCrystalNum($item_id){ - $rows = SqlHelper::ormSelect( - myself()->_getSelfMysql(), - 't_crystal_exchange_record', - array( - 'account_id'=>myself()->_getAccountId(), - 'item_id' => $item_id - ) - ); - - $crystalNum = 0; - if ($rows){ - foreach ($rows as $row){ - $crystalNum += $row['item_num']; - } - } - return $crystalNum; - } - - public static function addCrystalRecord($itemId,$itemNum){ - SqlHelper::insert( - myself()->_getSelfMysql(), - 't_crystal_exchange_record', - array( - 'account_id'=>myself()->_getAccountId(), - 'address'=>myself()->_getAddress(), - 'item_id'=>$itemId, - 'item_num' => $itemNum, - 'createtime'=>myself()->_getNowTime(), - 'modifytime'=>myself()->_getNowTime(), - ) - ); - } - - public static function getNewestRecordOne($itemId){ - $sql = "select * from t_crystal_exchange_record where `account_id` = :account_id and item_id = :item_id order by idx desc limit 1"; - $rows = myself()->_getMysql('')->execQuery($sql,array( - 'account_id' =>myself()->_getAccountId(), - 'item_id' =>$itemId, - )); - return count($rows) > 0 ? $rows[0] : array(); - } - -} \ No newline at end of file diff --git a/webapp/models/RewardsCec.php b/webapp/models/RewardsCec.php index dc57006e..1b5091e3 100644 --- a/webapp/models/RewardsCec.php +++ b/webapp/models/RewardsCec.php @@ -25,145 +25,4 @@ class RewardsCec extends BaseModel ); } - public static function getTotalCecNum(){ - $rows = SqlHelper::ormSelect( - myself()->_getSelfMysql(), - 't_hash_rate_reward', - array( - 'account_id'=>myself()->_getAccountId(), - ) - ); - $totalCecNum = 0; - if ($rows){ - foreach ($rows as $row){ - $totalCecNum += $row['reward_cec']; - } - } - return $totalCecNum; - } - - public static function getHistoryByTime($starTime,$endTime){ - if ($starTime || $endTime){ - $sql = "select * from t_hash_rate_reward where account_id=:account and createtime>:starTime and createtime<:endTime"; - $rows = myself()->_getSelfMysql()->execQuery( - $sql, - array( - 'account' => myself()->_getAccountId(), - 'starTime' => $starTime, - 'endTime' => $endTime, - ) - ); - }else{ - $sql = "select * from t_hash_rate_reward where account_id=:account"; - $rows = myself()->_getSelfMysql()->execQuery( - $sql, - array( - 'account' => myself()->_getAccountId(), - ) - ); - } - if (!$rows){ - $rows =array(); - } - return $rows; - } - - public static function toDto($row){ - if (!$row){ - return; - } - $week1 = phpcommon\getMondaySeconds($row['createtime']); - $week2 = $week1 + 60*60*24*7 ; - $week3 = $week1 + 60*60*24*14 ; - $week4 = $week1 + 60*60*24*21 ; - $state = $row['reward1'] && $row['reward2'] && $row['reward3'] && $row['reward4'] ? 1 : 0; -// $pendingNum = $row['reward_cec']; - $pendingNum = 0; - if (!$row['reward1']){ -// $pendingNum -= $pendingNum*0.25; - $pendingNum += 1; - } - if (!$row['reward2']){ -// $pendingNum -= $pendingNum*0.5; - $pendingNum += 1; - } - if (!$row['reward3']){ -// $pendingNum -= $pendingNum*0.75; - $pendingNum += 1; - } - if (!$row['reward4']){ -// $pendingNum = 0; - $pendingNum += 1; - } - return array( - 'hash_rate' => $row['power'], - 'cec_num' => $row['reward_cec'], - 'state' => $state, - 'week1' => $row['reward1'] ? $row['reward1'] : $week1, - 'week2' => $row['reward2'] ? $row['reward2'] : $week2, - 'week3' => $row['reward3'] ? $row['reward3'] : $week3, - 'week4' => $row['reward4'] ? $row['reward4'] : $week4, - 'txHash1' => $row['txHash1'] ? $row['txHash1'] : "", - 'txHash2' => $row['txHash2'] ? $row['txHash2'] : "", - 'txHash3' => $row['txHash3'] ? $row['txHash3'] : "", - 'txHash4' => $row['txHash4'] ? $row['txHash4'] : "", - 'create_time' => $row['createtime'], - 'pending_num' => strval($pendingNum), - ); - } - - - public static function findByAccount($account,$period){ - $row = SqlHelper::ormSelectOne( - myself()->_getMysql($account), - 't_hash_rate_reward', - array( - 'account_id'=>$account, - 'period' => $period - ) - ); - if (!$row){ - $row = null; - } - return $row; - } - - public static function celCecReward($account,$hashMeta){ - $ownerNum = ComputingPower::getOwnedBH($hashMeta['id'],$account); //13.7 - $totalNum = ComputingPower::getTotalBH($hashMeta['id']); //25.9 - $target = NumberService::ceilEx(min($totalNum / $hashMeta['cec_pool'] , 1),6); // 25.9/10000 - if ($totalNum == 0) { - $ratio = 0; - }else{ - $ratio = $ownerNum/$totalNum; - } - $cecNum = NumberService::ceilEx($hashMeta['cec_pool'] * $target * $ratio,2); //10000*(25.9/10000)*(13.7/25.9) - $address = User::findUserAddress($account); - SqlHelper::upsert( - myself()->_getMysql($account), - 't_hash_rate_reward', - array( - 'account_id'=>$account, - 'period'=>$hashMeta['id'], - ), - array( - - ), - array( - 'account_id'=>$account, - 'address'=>$address, - 'period'=>$hashMeta['id'], - 'power'=>$ownerNum, - 'reward_cec' => $cecNum, -// 'reward1' => 0, -// 'reward2' => 0, -// 'reward3' => 0, -// 'reward4' => 0, - 'createtime'=>myself()->_getNowTime(), - 'modifytime'=>myself()->_getNowTime(), - ) - ); - } - - } \ No newline at end of file