From 6fe6da6b3deb913ac741b63df7aca81825fef37c Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Fri, 8 Sep 2023 15:42:21 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=97=E5=8A=9B=E5=85=AC=E5=BC=8F=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Team.py | 12 ++++++++++ doc/_common.py | 2 +- .../ComputingPowerController.class.php | 22 +++++++++++++++---- webapp/controller/TeamController.class.php | 19 ++++++++++++++++ webapp/models/ComputingPower.php | 6 ++++- webapp/models/RewardsCec.php | 12 +++++++--- webapp/services/NumberService.php | 15 +++++++++++++ 7 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 webapp/services/NumberService.php diff --git a/doc/Team.py b/doc/Team.py index c34d6180..30c48576 100644 --- a/doc/Team.py +++ b/doc/Team.py @@ -63,6 +63,18 @@ class Team(object): 'response': [ _common.RspHead(), ] + },{ + 'name': 'breakup', + 'desc': '解散队伍', + 'group': 'Team', + 'url': 'webapp/index.php?c=Team&a=breakup', + 'params': [ + _common.ReqHead(), + ['team_uuid', '', '队伍唯一id'], + ], + 'response': [ + _common.RspHead(), + ] }, { 'name': 'kickout', diff --git a/doc/_common.py b/doc/_common.py index 53592c4f..f06194d4 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1356,7 +1356,7 @@ class ComputingPower(object): self.fields = [ ['period_state', 0, '周期状态 -1:算力周期未开始 0:正常周期 1:等待周期 2:维护周期'], ['curr_period', ComputingPowerCurr(), '本期相关信息'], - ['last_period', ComputingPowerReward(), '上期相关信息'], + ['curr_reward', ComputingPowerReward(), '本期奖励信息'], ['listing_state', 0, 'listing状态 0:之前 1:之后'], ['owned_cec', 0, '拥有的cec数量'], ['owned_total_hash_rate', 0, '用户总科技值'], diff --git a/webapp/controller/ComputingPowerController.class.php b/webapp/controller/ComputingPowerController.class.php index d8270ea5..81f31566 100644 --- a/webapp/controller/ComputingPowerController.class.php +++ b/webapp/controller/ComputingPowerController.class.php @@ -6,6 +6,7 @@ require_once('mt/Parameter.php'); require_once('services/HashRateService.php'); require_once('services/AwardService.php'); require_once('services/PropertyChgService.php'); +require_once('services/NumberService.php'); require_once('models/ComputingPower.php'); require_once('models/CrystalRecord.php'); @@ -41,6 +42,15 @@ class ComputingPowerController extends BaseAuthedController $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']); @@ -60,9 +70,13 @@ class ComputingPowerController extends BaseAuthedController $curr_period['total_exchange_hash_rate'] = $ownerNum; $curr_period['total_hash_rate'] = $totalNum; - $target = min($totalNum / $currentMeta['cec_pool'] , 1); - $ratio = $ownerNum/$totalNum; - $reward['cec'] = $currentMeta['cec_pool'] * $target * $ratio; + $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; } @@ -71,7 +85,7 @@ class ComputingPowerController extends BaseAuthedController $info = array( 'period_state' => $period_state, 'curr_period' => $curr_period, - 'last_period' => $reward, + 'curr_reward' => $reward, 'listing_state' => LISTING_SWITCH, 'owned_cec' => RewardsCec::getTotalCecNum(), 'owned_total_hash_rate' =>ComputingPower::getMyTotalBH(), diff --git a/webapp/controller/TeamController.class.php b/webapp/controller/TeamController.class.php index f7193880..6c7557c2 100644 --- a/webapp/controller/TeamController.class.php +++ b/webapp/controller/TeamController.class.php @@ -216,6 +216,25 @@ class TeamController extends BaseAuthedController { $this->_rspOk(); } + public function breakup(){ + $teamUuid = getReqVal('team_uuid', ''); + $r = $this->_getRedis($teamUuid); + $teamDb = $this->readTeamDb($r, $teamUuid); + if (empty($teamDb)) { + $this->_rspErr(1, 'The team has been disbanded'); + return; + } + foreach ($teamDb['member_list'] as &$member) { + if ($member['account_id'] == $this->_getAccountId() && $member['is_leader'] != 1){ + $this->_rspErr(1, 'You are not the captain.'); + return; + } + } + $this->delTeamDb($r, $teamUuid); + $this->_rspOk(); + } + + public function kickout() { $teamUuid = getReqVal('team_uuid', ''); diff --git a/webapp/models/ComputingPower.php b/webapp/models/ComputingPower.php index e15f6b6f..28930925 100644 --- a/webapp/models/ComputingPower.php +++ b/webapp/models/ComputingPower.php @@ -2,9 +2,12 @@ namespace models; +require_once('services/NumberService.php'); use mt; use phpcommon\SqlHelper; +use services\NumberService; + class ComputingPower extends BaseModel { const CRYSTAL1 = 260001; @@ -31,7 +34,8 @@ class ComputingPower extends BaseModel $my_total_num += $row['total_num']; } } - return $my_total_num; + + return NumberService::ceilEx($my_total_num,6); } //获取全服总算力 diff --git a/webapp/models/RewardsCec.php b/webapp/models/RewardsCec.php index f49fa41d..dc57006e 100644 --- a/webapp/models/RewardsCec.php +++ b/webapp/models/RewardsCec.php @@ -7,6 +7,8 @@ namespace models; use mt; use phpcommon\SqlHelper; use phpcommon; +use services\NumberService; + class RewardsCec extends BaseModel { @@ -129,9 +131,13 @@ class RewardsCec extends BaseModel public static function celCecReward($account,$hashMeta){ $ownerNum = ComputingPower::getOwnedBH($hashMeta['id'],$account); //13.7 $totalNum = ComputingPower::getTotalBH($hashMeta['id']); //25.9 - $target = min($totalNum / $hashMeta['cec_pool'] , 1); // 25.9/10000 - $ratio = $ownerNum/$totalNum; // 13.7/25.9 - $cecNum = $hashMeta['cec_pool'] * $target * $ratio; //10000*(25.9/10000)*(13.7/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), diff --git a/webapp/services/NumberService.php b/webapp/services/NumberService.php new file mode 100644 index 00000000..e2db629e --- /dev/null +++ b/webapp/services/NumberService.php @@ -0,0 +1,15 @@ +