From 408335c8e328553ae56f206b7c8918a5d5b6e6f9 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Fri, 5 Jan 2024 14:15:53 +0800 Subject: [PATCH] 1 --- sql/gamedb.sql | 33 ++- sql/gamedb2006_migrate_231228_01.sql | 4 +- .../controller/BaseAuthedController.class.php | 2 +- webapp/controller/BattleController.class.php | 2 +- .../ComputingPowerController.class.php | 4 +- .../controller/HashRateController.class.php | 2 +- webapp/models/HashRate.php | 30 +++ webapp/models/HashRateTask.php | 170 ------------ webapp/services/HashRateService.php | 253 ++---------------- webapp/services/TameBattleDataService.php | 2 +- 10 files changed, 81 insertions(+), 421 deletions(-) create mode 100644 webapp/models/HashRate.php delete mode 100644 webapp/models/HashRateTask.php diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 409e1c53..e6a87ae2 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1695,16 +1695,37 @@ CREATE TABLE `t_avatar` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; -CREATE TABLE `t_hash_rate_task` ( +-- +-- Table structure for table `t_hash_rate` +-- + +DROP TABLE IF EXISTS `t_hash_rate`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_hash_rate` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', - `task_id` int(11) NOT NULL COMMENT '配置表HashRateTask', - `season` int(11) NOT NULL DEFAULT '0' COMMENT 'taskId 为10003可用', - `record_total` int(64) NOT NULL DEFAULT '0' COMMENT '记录总数据', - `claim_day` int(64) NOT NULL DEFAULT '0' COMMENT '当天领取数据', - `claim_total` int(64) NOT NULL DEFAULT '0' COMMENT '领取总数据', + `task_id` int(11) NOT NULL COMMENT '配置表id', + `period` int(11) NOT NULL DEFAULT '0' COMMENT '算力期数', + `reward` int(64) NOT NULL DEFAULT '0' COMMENT '奖励', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), UNIQUE KEY `account_task_id` (`account_id`, `task_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +-- +-- Table structure for table `t_hash_rate_battle_data` +-- + +DROP TABLE IF EXISTS `t_hash_rate_battle_data`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_hash_rate_battle_data` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `battle_data` mediumblob COMMENT 'battle_data', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; diff --git a/sql/gamedb2006_migrate_231228_01.sql b/sql/gamedb2006_migrate_231228_01.sql index 41f84e78..a6d6027e 100644 --- a/sql/gamedb2006_migrate_231228_01.sql +++ b/sql/gamedb2006_migrate_231228_01.sql @@ -1,11 +1,11 @@ begin; -CREATE TABLE `t_hash_rate_task` ( +CREATE TABLE `t_hash_rate` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', `task_id` int(11) NOT NULL COMMENT '配置表id', `period` int(11) NOT NULL DEFAULT '0' COMMENT '算力期数', - `total_num` int(64) NOT NULL DEFAULT '0' COMMENT '记录数据', + `reward` int(64) NOT NULL DEFAULT '0' COMMENT '奖励', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index 59109987..49673f80 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -16,7 +16,7 @@ require_once('models/Parachute.php'); require_once('models/Chip.php'); require_once('models/Pass.php'); require_once('models/Avatar.php'); -require_once('models/HashRateTask.php'); +require_once('models/HashRate.php'); require_once('mt/Parameter.php'); require_once('mt/RankSeason.php'); require_once('mt/LevelUp.php'); diff --git a/webapp/controller/BattleController.class.php b/webapp/controller/BattleController.class.php index 371643d9..7b9d5a1b 100644 --- a/webapp/controller/BattleController.class.php +++ b/webapp/controller/BattleController.class.php @@ -12,7 +12,7 @@ require_once('models/User.php'); require_once('models/Parachute.php'); require_once('models/ChipPage.php'); require_once('models/Battle.php'); -require_once('models/HashRateTask.php'); +require_once('models/HashRate.php'); require_once('services/BattleDataService.php'); require_once('services/TameBattleDataService.php'); require_once('services/FormulaService.php'); diff --git a/webapp/controller/ComputingPowerController.class.php b/webapp/controller/ComputingPowerController.class.php index 32c85538..2082031b 100644 --- a/webapp/controller/ComputingPowerController.class.php +++ b/webapp/controller/ComputingPowerController.class.php @@ -1,7 +1,7 @@ hashRateService->hashRateTaskDto($mate); + $temp = $this->hashRateService->hashRateTaskDto($mate ,$currentPeriod); array_push($hashRateDtoList, $temp); } $obtain_end_time = strtotime($currentPeriod['obtain_end_time']); diff --git a/webapp/models/HashRate.php b/webapp/models/HashRate.php new file mode 100644 index 00000000..e4dee517 --- /dev/null +++ b/webapp/models/HashRate.php @@ -0,0 +1,30 @@ +_getSelfMysql(), + 't_hash_rate_task', + array( + 'account_id' => myself()->_getAccountId(), + 'task_id' => $taskId, + 'period' => $period, + ) + ); + } + + public static function add($fieldKv){ + SqlHelper::insert( + myself()->_getSelfMysql(), + 't_hash_rate_task', + $fieldKv + ); + } + +} \ No newline at end of file diff --git a/webapp/models/HashRateTask.php b/webapp/models/HashRateTask.php deleted file mode 100644 index bf92ae05..00000000 --- a/webapp/models/HashRateTask.php +++ /dev/null @@ -1,170 +0,0 @@ -_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - ) - ); - if (count($rows) < 1){ - $rows = array(); - } - return $rows; - } - - public static function toDto($row){ - array( - 'task_id' => $row['task_id'] - ); - } - - public static function findByTaskId($taskId){ - return SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - 'task_id' => $taskId, - ) - ); - } - - public static function incRecordNum($period,$taskId,$num){ - SqlHelper::upsert - (myself()->_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - 'period' => $period, - 'task_id' => $taskId, - ), - array( - 'total_num' => function () use($num) { - return "total_num + ${num}"; - }, - 'modifytime' => myself()->_getNowTime() - ), - array( - 'account_id' => myself()->_getAccountId(), - 'period' => $period, - 'task_id' => $taskId, - 'total_num' => $num, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) - ); - } - - public static function getDailyReward($taskId){ - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - 'task_id' => $taskId, - ) - ); - $modifytime = $row ? $row['modifytime'] : myself()->_getNowTime(); - $num = $row ? $row['claim_day'] : 0; - - if (myself()->_getDaySeconds($modifytime) < myself()->_getNowDaySeconds()) { - $num = 0; - } - return $num; - } - - public static function incDailyReward($taskId,$val,$total){ - $oldVal = self::getDailyReward($taskId); - $val += $oldVal; - SqlHelper::upsert - (myself()->_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - 'task_id' => $taskId, - ), - array( - 'claim_day' => $val, - 'claim_total' => function () use($total) { - return "claim_total + ${total}"; - }, - 'modifytime' => myself()->_getNowTime() - ), - array( - 'account_id' => myself()->_getAccountId(), - 'task_id' => $taskId, - 'claim_day' => $val, - 'claim_total' => $total, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) - ); - } - - public static function updateKv($taskId,$fieldKv){ - SqlHelper::update - (myself()->_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - 'task_id' => $taskId, - ), - $fieldKv - ); - } - - public static function setRankedData(){ - $SeasonMeta = RankSeason::getCurrentSeason(); - if (!$SeasonMeta){ - error_log("当前赛季结束"); - return; - } - if (! self::findByTaskIdOrSeason(self::RANK_TYPE,$SeasonMeta['id'])){ - $userDb = myself()->_safeGetOrmUserInfo(); - $rankMeta = Rank::getRankById($userDb['rank']); - SqlHelper::insert - (myself()->_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - 'task_id' => self::RANK_TYPE, - 'season' => $SeasonMeta['id'], - 'record_total' => $rankMeta['rank_order2'], - 'claim_total' => $rankMeta['rank_order2'], - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) - ); - - } - - } - - public static function findByTaskIdOrSeason($taskId,$season){ - return SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hash_rate_task', - array( - 'account_id' => myself()->_getAccountId(), - 'task_id' => $taskId, - 'season' => $season, - ) - ); - } - - -} \ No newline at end of file diff --git a/webapp/services/HashRateService.php b/webapp/services/HashRateService.php index d0cdcbe7..83d3795a 100644 --- a/webapp/services/HashRateService.php +++ b/webapp/services/HashRateService.php @@ -4,22 +4,21 @@ namespace services; require_once('mt/HashRate.php'); require_once('mt/Parameter.php'); -require_once('mt/HashRateTask.php'); +require_once('mt/HashRate.php'); require_once('mt/Rank.php'); require_once('mt/RankSeason.php'); require_once('models/Bag.php'); require_once('models/CrystalRecord.php'); require_once('models/Staking.php'); -require_once('models/HashRateTask.php'); +require_once('models/HashRate.php'); require_once('models/HashRateBattleData.php'); use models\Bag; use models\CrystalRecord; use models\HashRateBattleData; use models\Staking; -use models\HashRateTask; +use models\HashRate; use mt\AchievementsPower; -use mt\HashRate; use mt\Parameter; use mt\Rank; use mt\RankSeason; @@ -61,7 +60,7 @@ class HashRateService extends BaseService $this->mobaBattleData = $this->hashRateData['mobaData']; } - public function hashRateTaskDto($taskMate){ + public function hashRateTaskDto($taskMate ,$currentPeriod){ $taskDto = array( 'task_id' => $taskMate['id'], 'current' => 0, @@ -144,6 +143,18 @@ class HashRateService extends BaseService if ($taskDto['current'] >= $taskDto['target']) { $taskDto['current'] = $taskDto['target']; $taskDto['state'] = self::FINISHED_STATE; + $hashRateDb = HashRate::find($taskMate['id'],$currentPeriod['id']); + if (!$hashRateDb){ + $fieldKv = array( + 'account_id' => myself()->_getAccountId(), + 'task_id' => $taskMate['id'], + 'period' => $currentPeriod['id'], + 'reward' => $taskMate['Reward_quantity'], + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ); + HashRate::add($fieldKv); + } } return $taskDto; } @@ -177,236 +188,4 @@ class HashRateService extends BaseService return $val; } -//-----------------------以下弃用--------------------------- - const NONE_STATE = 0; - const RECEIVED_STATE = 1; - const EXCHANGE_RATE = 10; - //弃用 - public function getCrystalDto($crystalMeta,&$crystalDto){ - $crystalDto = array( - 'item_id' => $crystalMeta['id'], - 'pending' => 0, - 'total' => array(), - 'claimed' => 0, - 'state' => self::NONE_STATE, - ); - $hashRateMeta = HashRate::findHash($crystalMeta['id']); - $ownedNum = CrystalRecord::getCrystalNum($crystalMeta['id']); - $crystalDto['claimed'] = intval($ownedNum); - switch ($crystalMeta['sub_type']){ - case 1 : { - $param = explode('|',$hashRateMeta['parameter']); - $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); - $killsNumEx = $killsNum - $killsNumEd; - $starNumEx = $starNum - $starNumEd ; - $crystalDto['total'] = array( - 'param1' => floatval($killsNumEx), - 'param2' => floatval($starNumEx), - ); - $paramKill = explode(':',$param[0]); - $paramStar = explode(':',$param[1]); - $totalNum = max(0,floor($killsNumEx / $paramKill[0]) * $paramKill[1] + - floor($starNumEx / $paramStar[0]) * $paramStar[1] ); - $crystalDto['pending'] = intval($totalNum); - $crystalDto['state'] = $crystalDto['pending'] > 0 ? self::RECEIVED_STATE : self::NONE_STATE; - } - break; - case 2 : { - // 游戏内消费总价值 - $param = explode(':',$hashRateMeta['parameter']); - $consumeCost = myself()->_getV(TN_TOTAL_DIAMOND_CONSUME,0); - $consumeCostEd = myself()->_getV(TN_TOTAL_DIAMOND_CONSUME,-1); - $consumeCostEx = $consumeCost - $consumeCostEd ; - $crystalDto['total'] = array( - 'param1' => floatval($consumeCostEx / self::EXCHANGE_RATE), - ); - $totalNum = max(0,floor($consumeCostEx / self::EXCHANGE_RATE / $param[0]) * $param[1]); - $crystalDto['pending'] = intval($totalNum); - $crystalDto['state'] = $crystalDto['pending'] > 0 ? self::RECEIVED_STATE : self::NONE_STATE; - } - break; - case 3 : { - // Market交易总价值 - $param = explode(':',$hashRateMeta['parameter']); - $consumeCost = myself()->_getV(TN_TOTAL_CEG_CONSUME,0); - $consumeCostEd = myself()->_getV(TN_TOTAL_CEG_CONSUME,-1); - $consumeCostEx = $consumeCost - $consumeCostEd ; - $crystalDto['total'] = array( - 'param1' => floatval($consumeCostEx / self::EXCHANGE_RATE), - ); - $totalNum = max(0,floor($consumeCostEx / self::EXCHANGE_RATE / $param[0]) * $param[1]); - $crystalDto['pending'] = intval($totalNum); - $crystalDto['state'] = $crystalDto['pending'] > 0 ? self::RECEIVED_STATE : self::NONE_STATE; - } - break; - case 4 : { - // 质压总价值 - $param = explode(':',$hashRateMeta['parameter']); -// $rate = Parameter::getVal('cec_exchange_rate',10); - $cecVal = Staking::getStakingTotalValue(); - $crystalDto['total'] = array( - 'param1' => floatval($cecVal ), - ); - $recordDb = CrystalRecord::getNewestRecordOne($crystalMeta['id']); - if ($recordDb && myself()->_getNowDaySeconds() == myself()->_getDaySeconds($recordDb['createtime'])){ - $crystalDto['pending'] = 0; - }else{ - $totalNum = max(0,floor($cecVal / $param[0]) * $param[1]); - $crystalDto['pending'] = intval($totalNum); - } - $crystalDto['state'] = $crystalDto['pending'] > 0 ? self::RECEIVED_STATE : self::NONE_STATE; - } - break; - } - } - - //弃用 - public function getCrystalValue(){ - $chaimNum = 0; - $playing = array(); - $staking = array(); - $trading = array(); - $consuming = array(); - $nft = array(); -// $hashRateMt = \mt\HashRateTask::getListByType(\mt\HashRateTask::PLAYING); -// foreach ($hashRateMt as $meta){ -// $finalVal = 0; -// $uplimit = $meta['upperlimit'] ; -// if ($meta['id'] == HashRateTask::RANK_TYPE){ -// $seasonMeta = RankSeason::getCurrentSeason(); -// if (!$seasonMeta){ -// $seasonMeta = RankSeason::getLastSeason(); -// } -// $hashRateDb = HashRateTask::findByTaskIdOrSeason($meta['id'],$seasonMeta['id']); -// $userDb = myself()->_safeGetOrmUserInfo(); -// $rankMeta = Rank::getRankById($userDb['rank']); -// if ($rankMeta['rank_order2'] > $hashRateDb['record_total']){ -// $finalVal = ($rankMeta['rank_order2'] - $hashRateDb['claim_total']) * $meta['reward']; -// } -// } else { -// $hashRateDb = HashRateTask::findByTaskId($meta['id']); -// $targetVal = 0; -// if ($hashRateDb){ -// $total = $hashRateDb['record_total'] - $hashRateDb['claim_total']; -// if ($hashRateDb['task_id'] == HashRateTask::BATTLE_TIME_TYPE){ -// $targetVal = max(0,floor($total / 1000 / $meta['target'])) * $meta['reward']; -// }else{ -// $targetVal = max(0,floor($total / $meta['target'])) * $meta['reward']; -// } -// } -// -// -// $claim_day = HashRateTask::getDailyReward($meta['id']); -// $uplimit = $meta['upperlimit'] - $claim_day; -// $finalVal = min($targetVal , $uplimit); -// } -// $chaimNum += $finalVal; -// array_push($detail,array( -// 'task_id' => $meta['id'], -// 'uplimit' => $uplimit, -// 'chaim_num' => $finalVal -// )); -// } - $hashRateTask = \mt\HashRateTask::getMetaList(); - foreach ($hashRateTask as $metaTask){ - $finalVal = 0; - $uplimit = $metaTask['upperlimit'] ; - switch ($metaTask['type']){ - case \mt\HashRateTask::PLAYING :{ - if ($metaTask['id'] == HashRateTask::RANK_TYPE){ - $seasonMeta = RankSeason::getCurrentSeason(); - if (!$seasonMeta){ - $seasonMeta = RankSeason::getLastSeason(); - } - $hashRateDb = HashRateTask::findByTaskIdOrSeason($metaTask['id'],$seasonMeta['id']); - $userDb = myself()->_safeGetOrmUserInfo(); - $rankMeta = Rank::getRankById($userDb['rank']); -// - if ($hashRateDb && $rankMeta['rank_order2'] > $hashRateDb['record_total']){ - $finalVal = ($rankMeta['rank_order2'] - $hashRateDb['claim_total']) * $metaTask['reward']; - - } - } else { - $hashRateDb = HashRateTask::findByTaskId($metaTask['id']); - $targetVal = 0; - if ($hashRateDb){ - $total = $hashRateDb['record_total'] - $hashRateDb['claim_total']; - if ($hashRateDb['task_id'] == HashRateTask::BATTLE_TIME_TYPE){ - $targetVal = max(0,floor($total / 1000 / $metaTask['target'])) * $metaTask['reward']; - }else{ - $targetVal = max(0,floor($total / $metaTask['target'])) * $metaTask['reward']; - } - } - - - $claim_day = HashRateTask::getDailyReward($metaTask['id']); - $uplimit = $metaTask['upperlimit'] - $claim_day; - $finalVal = min($targetVal , $uplimit); - } - $chaimNum += $finalVal; - array_push($playing,array( - 'task_id' => $metaTask['id'], - 'uplimit' => $uplimit, - 'chaim_num' => $finalVal - )); - } - break; - case \mt\HashRateTask::STAKING :{ - //质押价值 - $stakingVal = Staking::getStakingTotalValue(); - $targetVal = max(0,floor($stakingVal / $metaTask['target']) * $metaTask['reward']); - $claim_day = HashRateTask::getDailyReward($metaTask['id']); - if ($claim_day){ - $finalVal = 0; - }else{ - $finalVal = $targetVal; - } - $chaimNum += $finalVal; - array_push($staking,array( - 'task_id' => $metaTask['id'], - 'uplimit' => $uplimit, - 'chaim_num' => $finalVal - )); - } - break; -// case \mt\HashRateTask::TRADING : { -// $consumeCost = myself()->_getV(TN_TOTAL_CEG_CONSUME,0); -// $consumeCostEd = myself()->_getV(TN_TOTAL_CEG_CONSUME,-1); -// $total = $consumeCost - $consumeCostEd ; -// $finalVal = max(0,floor($total / self::EXCHANGE_RATE / $metaTask['target']) * $metaTask['reward']); -// $chaimNum += $finalVal; -// array_push($trading,array( -// 'task_id' => $metaTask['id'], -// 'uplimit' => $uplimit, -// 'chaim_num' => $finalVal -// )); -// } -// break; - case \mt\HashRateTask::CONSUMING : { - $consumeCost = myself()->_getV(TN_TOTAL_DIAMOND_CONSUME,0); - $consumeCostEd = myself()->_getV(TN_TOTAL_DIAMOND_CONSUME,-1); - $total = $consumeCost - $consumeCostEd; - $finalVal = max(0,floor($total / self::EXCHANGE_RATE / $metaTask['target']) * $metaTask['reward']); - $chaimNum += $finalVal; - array_push($consuming,array( - 'task_id' => $metaTask['id'], - 'uplimit' => $uplimit, - 'chaim_num' => $finalVal - )); - } - } - } - return array( - 'totalNum' => $chaimNum, - 'playing'=>$playing, - 'staking'=>$staking, - 'consuming'=>$consuming, - 'nft'=>$nft, - ); - } - - } \ No newline at end of file diff --git a/webapp/services/TameBattleDataService.php b/webapp/services/TameBattleDataService.php index 0c0e5978..25c89f4c 100644 --- a/webapp/services/TameBattleDataService.php +++ b/webapp/services/TameBattleDataService.php @@ -32,7 +32,7 @@ require_once('models/NftActive.php'); require_once('models/FragmentRecord.php'); require_once('models/BattleSettlement.php'); require_once('models/RankBattle.php'); -require_once('models/HashRateTask.php'); +require_once('models/HashRate.php'); require_once('models/HashRateBattleData.php'); require_once('services/RankActivityService.php');