算力公式修改
This commit is contained in:
parent
665aa853f5
commit
6fe6da6b3d
12
doc/Team.py
12
doc/Team.py
@ -63,6 +63,18 @@ class Team(object):
|
|||||||
'response': [
|
'response': [
|
||||||
_common.RspHead(),
|
_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',
|
'name': 'kickout',
|
||||||
|
@ -1356,7 +1356,7 @@ class ComputingPower(object):
|
|||||||
self.fields = [
|
self.fields = [
|
||||||
['period_state', 0, '周期状态 -1:算力周期未开始 0:正常周期 1:等待周期 2:维护周期'],
|
['period_state', 0, '周期状态 -1:算力周期未开始 0:正常周期 1:等待周期 2:维护周期'],
|
||||||
['curr_period', ComputingPowerCurr(), '本期相关信息'],
|
['curr_period', ComputingPowerCurr(), '本期相关信息'],
|
||||||
['last_period', ComputingPowerReward(), '上期相关信息'],
|
['curr_reward', ComputingPowerReward(), '本期奖励信息'],
|
||||||
['listing_state', 0, 'listing状态 0:之前 1:之后'],
|
['listing_state', 0, 'listing状态 0:之前 1:之后'],
|
||||||
['owned_cec', 0, '拥有的cec数量'],
|
['owned_cec', 0, '拥有的cec数量'],
|
||||||
['owned_total_hash_rate', 0, '用户总科技值'],
|
['owned_total_hash_rate', 0, '用户总科技值'],
|
||||||
|
@ -6,6 +6,7 @@ require_once('mt/Parameter.php');
|
|||||||
require_once('services/HashRateService.php');
|
require_once('services/HashRateService.php');
|
||||||
require_once('services/AwardService.php');
|
require_once('services/AwardService.php');
|
||||||
require_once('services/PropertyChgService.php');
|
require_once('services/PropertyChgService.php');
|
||||||
|
require_once('services/NumberService.php');
|
||||||
|
|
||||||
require_once('models/ComputingPower.php');
|
require_once('models/ComputingPower.php');
|
||||||
require_once('models/CrystalRecord.php');
|
require_once('models/CrystalRecord.php');
|
||||||
@ -41,6 +42,15 @@ class ComputingPowerController extends BaseAuthedController
|
|||||||
$currentMeta = \mt\HashRateCommon::getCurrentPeriod();
|
$currentMeta = \mt\HashRateCommon::getCurrentPeriod();
|
||||||
$nextMeta = \mt\HashRateCommon::getNextPeriod();
|
$nextMeta = \mt\HashRateCommon::getNextPeriod();
|
||||||
if (!$currentMeta && $lastMeta){
|
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){
|
if ($nextMeta){
|
||||||
$period_state = 1;
|
$period_state = 1;
|
||||||
$curr_period['period_begin'] = strtotime($nextMeta['start_time']);
|
$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_exchange_hash_rate'] = $ownerNum;
|
||||||
$curr_period['total_hash_rate'] = $totalNum;
|
$curr_period['total_hash_rate'] = $totalNum;
|
||||||
|
|
||||||
$target = min($totalNum / $currentMeta['cec_pool'] , 1);
|
$target = \services\NumberService::ceilEx(min($totalNum / $currentMeta['cec_pool'] , 1),6);
|
||||||
|
if ($totalNum == 0) {
|
||||||
|
$ratio = 0;
|
||||||
|
}else{
|
||||||
$ratio = $ownerNum/$totalNum;
|
$ratio = $ownerNum/$totalNum;
|
||||||
$reward['cec'] = $currentMeta['cec_pool'] * $target * $ratio;
|
}
|
||||||
|
$reward['cec'] = \services\NumberService::ceilEx($currentMeta['cec_pool'] * $target * $ratio,2);
|
||||||
$reward['point'] = $ownerNum;
|
$reward['point'] = $ownerNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +85,7 @@ class ComputingPowerController extends BaseAuthedController
|
|||||||
$info = array(
|
$info = array(
|
||||||
'period_state' => $period_state,
|
'period_state' => $period_state,
|
||||||
'curr_period' => $curr_period,
|
'curr_period' => $curr_period,
|
||||||
'last_period' => $reward,
|
'curr_reward' => $reward,
|
||||||
'listing_state' => LISTING_SWITCH,
|
'listing_state' => LISTING_SWITCH,
|
||||||
'owned_cec' => RewardsCec::getTotalCecNum(),
|
'owned_cec' => RewardsCec::getTotalCecNum(),
|
||||||
'owned_total_hash_rate' =>ComputingPower::getMyTotalBH(),
|
'owned_total_hash_rate' =>ComputingPower::getMyTotalBH(),
|
||||||
|
@ -216,6 +216,25 @@ class TeamController extends BaseAuthedController {
|
|||||||
$this->_rspOk();
|
$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()
|
public function kickout()
|
||||||
{
|
{
|
||||||
$teamUuid = getReqVal('team_uuid', '');
|
$teamUuid = getReqVal('team_uuid', '');
|
||||||
|
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace models;
|
namespace models;
|
||||||
|
require_once('services/NumberService.php');
|
||||||
|
|
||||||
use mt;
|
use mt;
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
|
use services\NumberService;
|
||||||
|
|
||||||
class ComputingPower extends BaseModel
|
class ComputingPower extends BaseModel
|
||||||
{
|
{
|
||||||
const CRYSTAL1 = 260001;
|
const CRYSTAL1 = 260001;
|
||||||
@ -31,7 +34,8 @@ class ComputingPower extends BaseModel
|
|||||||
$my_total_num += $row['total_num'];
|
$my_total_num += $row['total_num'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $my_total_num;
|
|
||||||
|
return NumberService::ceilEx($my_total_num,6);
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取全服总算力
|
//获取全服总算力
|
||||||
|
@ -7,6 +7,8 @@ namespace models;
|
|||||||
use mt;
|
use mt;
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
use phpcommon;
|
use phpcommon;
|
||||||
|
use services\NumberService;
|
||||||
|
|
||||||
class RewardsCec extends BaseModel
|
class RewardsCec extends BaseModel
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -129,9 +131,13 @@ class RewardsCec extends BaseModel
|
|||||||
public static function celCecReward($account,$hashMeta){
|
public static function celCecReward($account,$hashMeta){
|
||||||
$ownerNum = ComputingPower::getOwnedBH($hashMeta['id'],$account); //13.7
|
$ownerNum = ComputingPower::getOwnedBH($hashMeta['id'],$account); //13.7
|
||||||
$totalNum = ComputingPower::getTotalBH($hashMeta['id']); //25.9
|
$totalNum = ComputingPower::getTotalBH($hashMeta['id']); //25.9
|
||||||
$target = min($totalNum / $hashMeta['cec_pool'] , 1); // 25.9/10000
|
$target = NumberService::ceilEx(min($totalNum / $hashMeta['cec_pool'] , 1),6); // 25.9/10000
|
||||||
$ratio = $ownerNum/$totalNum; // 13.7/25.9
|
if ($totalNum == 0) {
|
||||||
$cecNum = $hashMeta['cec_pool'] * $target * $ratio; //10000*(25.9/10000)*(13.7/25.9)
|
$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);
|
$address = User::findUserAddress($account);
|
||||||
SqlHelper::upsert(
|
SqlHelper::upsert(
|
||||||
myself()->_getMysql($account),
|
myself()->_getMysql($account),
|
||||||
|
15
webapp/services/NumberService.php
Normal file
15
webapp/services/NumberService.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user