This commit is contained in:
aozhiwei 2023-08-30 15:25:38 +08:00
parent cec26567d4
commit a2eb258d18
2 changed files with 44 additions and 0 deletions

View File

@ -25,6 +25,7 @@ class StakingController extends BaseAuthedController {
public function info()
{
$info = array(
'pool_size' => 8000 * 10000 - Staking::getAllStakingValue(),
'total_staking_value' => '0',
'daily_staking_value' => '0',
'planet' => array(

View File

@ -17,6 +17,27 @@ class Staking extends BaseModel {
const NFT721 = 1;
public static function getAllStakingValue()
{
$value = 0;
$rows = SqlHelper::ormSelect(
myself()->_getMysql(''),
't_staking',
array(
'status' => self::STAKING_STATUS
)
);
foreach ($rows as $row) {
if ($row['nft_type'] == self::NFT721) {
if ($row['item_id']) {
$stakingDto = self::toDto($row);
$value += $stakingDto['cec_value'] * (1 + self::getTotalInterest($row['stake_time']));
}
}
}
return $value;
}
public static function all($address)
{
$result = array();
@ -307,4 +328,26 @@ class Staking extends BaseModel {
}
}
private static function getTotalInterest($stakeTime)
{
$months = intval($stakeTime / 3600 / 24 / 30);
if ($months <= 0) {
return 0;
}
//1 3 6 12 24
if ($months <= 1) {
return 0.01;
} else if ($months <= 3) {
return 0.05;
} else if ($months <= 6) {
return 0.15;
} else if ($months <= 12) {
return 0.4;
} else if ($months <= 24) {
return 1;
} else {
return 0;
}
}
}