算力公式修改

This commit is contained in:
hujiabin 2023-09-08 15:42:21 +08:00
parent 665aa853f5
commit 6fe6da6b3d
7 changed files with 79 additions and 9 deletions

View File

@ -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',

View File

@ -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, '用户总科技值'],

View File

@ -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(),

View File

@ -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', '');

View File

@ -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);
}
//获取全服总算力

View File

@ -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),

View File

@ -0,0 +1,15 @@
<?php
namespace services;
use phpcommon;
class NumberService extends BaseService
{
public static function ceilEx($number , $decimals) {
$intPart = intval($number);
$floatPart = $number - $intPart;
$finallyFloatPart = ceil($floatPart * pow(10,$decimals)) / pow(10,$decimals);
return $intPart + $finallyFloatPart;
}
}