From a2eb258d189fcd6a384e5ff642102045361b7dc2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 30 Aug 2023 15:25:38 +0800 Subject: [PATCH] 1 --- webapp/controller/StakingController.class.php | 1 + webapp/models/Staking.php | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 50104ef2..0dbb8d2c 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -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( diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 61be5889..4e3931f1 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -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; + } + } + }