算力修改相关功能

This commit is contained in:
hujiabin 2023-09-06 16:53:39 +08:00
parent b5cfe0639c
commit e693535cfc
4 changed files with 46 additions and 35 deletions

View File

@ -1335,21 +1335,19 @@ class ComputingPowerCurr(object):
['period_end', '', '本期结束时间(0 不显示)'],
['await_time', '', '结算等待时间'],
['assignable_cec', '', '可分配的总cec奖励'],
['total_target', '', '全服算力总目标'],
# ['total_target', '', '全服算力总目标'],
# ['refresh_remain_time', '', '刷新剩余时间'],
['total_hash_rate', '', '全服总兑换算力'],
['total_exchange_hash_rate', '', "玩家已兑换算力"],
]
class ComputingPowerLast(object):
class ComputingPowerReward(object):
def __init__(self):
self.fields = [
['period_begin', 0, '上期开始时间(0 不显示)'],
['period_end', 0, '上期结束时间(0 不显示)'],
['reward', 0, '上期的cec奖励'],
['last_hash_rate', 0, '上期的科技值'],
['cec', 0, 'cec奖励'],
['point', 0, '科技值'],
]
class ComputingPower(object):
@ -1358,7 +1356,7 @@ class ComputingPower(object):
self.fields = [
['period_state', 0, '周期状态 -1:算力周期未开始 0:正常周期 1:等待周期 2:维护周期'],
['curr_period', ComputingPowerCurr(), '本期相关信息'],
['last_period', ComputingPowerLast(), '上期相关信息'],
['last_period', ComputingPowerReward(), '上期相关信息'],
['listing_state', 0, 'listing状态 0:之前 1:之后'],
['owned_cec', 0, '拥有的cec数量'],
['owned_total_hash_rate', 0, '用户总科技值'],

View File

@ -1624,3 +1624,30 @@ CREATE TABLE `t_ranking_settlement_record` (
PRIMARY KEY (`idx`),
KEY `account_id` (`account_id`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE TABLE `t_staking` (
`idx` bigint(20) NOT NULL AUTO_INCREMENT,
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
`address` varchar(60) NOT NULL DEFAULT '' COMMENT 'address',
`order_id` varchar(60) COMMENT 'order_id',
`token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id',
`item_id` int(11) NOT NULL COMMENT 'item_id',
`token_type` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片 6:荣誉 7:徽章',
`net_id` bigint NOT NULL DEFAULT '0' COMMENT 'net_id',
`contract_address` varchar(60) NOT NULL DEFAULT '' COMMENT 'contract_address',
`stacked_num` varchar(60) NOT NULL DEFAULT '' COMMENT 'stacked_num',
`start_time` bigint NOT NULL DEFAULT '0' COMMENT '质押开始时间',
`stake_time` bigint NOT NULL DEFAULT '0' COMMENT '质押结束时间',
`redeem_time` bigint NOT NULL DEFAULT '0' COMMENT '赎回时间',
`status` int(11) NOT NULL COMMENT '0:质押中 1:已解押',
`txhash` varchar(255) NOT NULL DEFAULT '' COMMENT 'txhash',
`nft_type` int(11) NOT NULL COMMENT '',
`nft_reward` double NOT NULL DEFAULT '0' COMMENT '利息',
`createtime` int(11) NOT NULL COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `unikey1` (`token_id`, `contract_address`, `net_id`, `start_time`),
UNIQUE KEY `unikey2` (`token_id`, `contract_address`, `net_id`, `order_id`),
KEY `address` (`address`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8;

View File

@ -24,21 +24,17 @@ class ComputingPowerController extends BaseAuthedController
public function info(){
$period_state = -1 ; //-1:算力周期未开始 0:正常周期 1:等待周期 2:维护周期
$curr_period = array(
// "current_state" => -1, //-1:算力周期未开始 0:正常周期 1:等待周期 2:维护周期
"period_begin" => 0,
"period_end" => 0,
"await_time" => 0,
"assignable_cec" => 0,
"total_target" => 0,
"total_exchange_hash_rate" => 0,
"total_hash_rate" => 0,
// "refresh_remain_time" => 0,
);
$last_period = array(
"period_begin" => 0,
"period_end" => 0,
"reward" => 0,
$reward = array(
"cec" => 0,
"point" => 0,
);
$lastMeta = \mt\HashRateCommon::getLastPeriod();
@ -47,45 +43,35 @@ class ComputingPowerController extends BaseAuthedController
if (!$currentMeta && $lastMeta){
if ($nextMeta){
$period_state = 1;
// $curr_period['current_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{
// $curr_period['current_state'] = 2;
$period_state = 2;
}
}
if ($currentMeta){
$period_state = 0;
// $curr_period['current_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'] = $currentMeta['cec_pool'];
$curr_period['total_target'] = $currentMeta['target'];
$curr_period['total_exchange_hash_rate'] = ComputingPower::getOwnedBH($currentMeta['id']);
// $rowDb = ComputingPower::getTotalBH($currentMeta['id']);
$curr_period['total_hash_rate'] = ComputingPower::getTotalBH($currentMeta['id']) + $currentMeta['hashrate_add'];
// $curr_period['refresh_remain_time'] = $rowDb ? $rowDb['modifytime'] + 3600 - myself()->_getNowTime() : 0;
$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;
$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']);
}
$info = array(
'period_state' => $period_state,
'curr_period' => $curr_period,
'last_period' => $last_period,
'last_period' => $reward,
'listing_state' => LISTING_SWITCH,
'owned_cec' => RewardsCec::getTotalCecNum(),
'owned_total_hash_rate' =>ComputingPower::getMyTotalBH(),

View File

@ -128,8 +128,8 @@ class RewardsCec extends BaseModel
public static function celCecReward($account,$hashMeta){
$ownerNum = ComputingPower::getOwnedBH($hashMeta['id'],$account); //13.7
$totalNum = ComputingPower::getTotalBH($hashMeta['id']) + $hashMeta['hashrate_add']; //25.9
$target = min($totalNum / $hashMeta['target'] , 1); // 25.9/10000
$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)
$address = User::findUserAddress($account);