From e411f4a2eb645f0de2023d3f5148de0694028bbd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 25 Aug 2023 19:04:05 +0800 Subject: [PATCH 01/23] 1 --- webapp/models/Staking.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 4180700b..83a76420 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -170,6 +170,12 @@ class Staking extends BaseModel { if (!$stakingMeta) { return false; } + if ($row['stake_time'] >= 3600 * 24 * 30 * 12 * 2) { + + } else if ($row['stake_time'] <= 3600 * 24 * 30 * 1) { + } else { + return false; + } return true; } From bb0656a29390fd84d3e00386bb532ebb47bffcb7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 25 Aug 2023 19:23:05 +0800 Subject: [PATCH 02/23] 1 --- webapp/models/Staking.php | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 83a76420..57a3dc12 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -170,13 +170,42 @@ class Staking extends BaseModel { if (!$stakingMeta) { return false; } + $stakingValue = $stakingMeta['stake_value']; + $realValue = $stakingValue / self::getCecPrice(); if ($row['stake_time'] >= 3600 * 24 * 30 * 12 * 2) { - } else if ($row['stake_time'] <= 3600 * 24 * 30 * 1) { + } else if ($row['stake_time'] <= 3600 * 24 * 30 * 12 * 1) { } else { return false; } return true; } + public static function getCecPrice() + { + return 1; + } + + public static function getDailyInterest($stakeTime) + { + $months = intval($stakeTime / 3600 / 24 / 30); + if ($months <= 0) { + return 0; + } + //1 3 6 12 24 + if ($months <= 1) { + return 0.01 / 30 * $months; + } else if ($months <= 3) { + return 0.05 / 30 * $months; + } else if ($months <= 6) { + return 0.15 / 30 * $months; + } else if ($months <= 12) { + return 0.4 / 30 * $months; + } else if ($months <= 24) { + return 1 / 30 * $months; + } else { + return 0; + } + } + } From 4cdd05ba2d8513515f09766592c0e7cfade8e315 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 25 Aug 2023 19:25:19 +0800 Subject: [PATCH 03/23] 1 --- webapp/models/Staking.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 57a3dc12..29835f3e 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -172,6 +172,7 @@ class Staking extends BaseModel { } $stakingValue = $stakingMeta['stake_value']; $realValue = $stakingValue / self::getCecPrice(); + $dailyInterest = self::getDailyInterest($row['stake_time']); if ($row['stake_time'] >= 3600 * 24 * 30 * 12 * 2) { } else if ($row['stake_time'] <= 3600 * 24 * 30 * 12 * 1) { From 4f84bcac987f9990fe544f4b42e5c3a5abb810e0 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 25 Aug 2023 20:53:07 +0800 Subject: [PATCH 04/23] 1 --- webapp/models/Staking.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 29835f3e..e48964b0 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -166,6 +166,7 @@ class Staking extends BaseModel { public static function calcReward($row, &$reward) { + $reward = 0; $stakingMeta = mt\Staking::get($row['item_id']); if (!$stakingMeta) { return false; @@ -173,9 +174,16 @@ class Staking extends BaseModel { $stakingValue = $stakingMeta['stake_value']; $realValue = $stakingValue / self::getCecPrice(); $dailyInterest = self::getDailyInterest($row['stake_time']); + $passedDays = myself()->_getNowTime() - $row['start_time']; + $saveDays = $row['stake_time'] / 3600 / 24; if ($row['stake_time'] >= 3600 * 24 * 30 * 12 * 2) { } else if ($row['stake_time'] <= 3600 * 24 * 30 * 12 * 1) { + if ($row['redeem_time'] > 0) { + + } else { + + } } else { return false; } From 36e8e7c68c9d4db70e5fa3d84b1505be6a7312a8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 25 Aug 2023 21:04:54 +0800 Subject: [PATCH 05/23] 1 --- webapp/models/Staking.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index e48964b0..f8741fd9 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -175,14 +175,14 @@ class Staking extends BaseModel { $realValue = $stakingValue / self::getCecPrice(); $dailyInterest = self::getDailyInterest($row['stake_time']); $passedDays = myself()->_getNowTime() - $row['start_time']; - $saveDays = $row['stake_time'] / 3600 / 24; + $saveDays = intval($row['stake_time'] / 3600 / 24); if ($row['stake_time'] >= 3600 * 24 * 30 * 12 * 2) { } else if ($row['stake_time'] <= 3600 * 24 * 30 * 12 * 1) { if ($row['redeem_time'] > 0) { } else { - + $reward = $realValue * min($passedDays, $saveDays) * $dailyInterest; } } else { return false; From 7001f96dfac4c82e113070fa47f48a07637d37e1 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 07:28:26 +0800 Subject: [PATCH 06/23] 1 --- webapp/models/Staking.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index f8741fd9..6bc9c1c9 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -180,7 +180,12 @@ class Staking extends BaseModel { } else if ($row['stake_time'] <= 3600 * 24 * 30 * 12 * 1) { if ($row['redeem_time'] > 0) { + $redeemDays = intval(($row['redeem_time'] - $row['start_time']) / 3600 / 24); + if ($redeemDays < $saveDays) { + } else { + $reward = $realValue * min($passedDays, $redeemDays) * $dailyInterest; + } } else { $reward = $realValue * min($passedDays, $saveDays) * $dailyInterest; } From dda18828aa850dcd5b9b89873354c76cca7204ad Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 08:00:09 +0800 Subject: [PATCH 07/23] 1 --- doc/Staking.py | 2 +- webapp/controller/StakingController.class.php | 34 ++----------------- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/doc/Staking.py b/doc/Staking.py index d1959106..d3068b35 100644 --- a/doc/Staking.py +++ b/doc/Staking.py @@ -33,9 +33,9 @@ class Staking(object): ['type', '', '1: planet 2: badge 3:cec'], ], 'response': [ + _common.RspHead(), ['type', '', '1: planet 2: badge 3:cec'], ['stacked_quant', '', '当前该类型质押总数'], - _common.RspHead(), ['!items', [_common.StakingDetail()], '质押列表'], ] }, diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 98734916..61654e39 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -102,21 +102,8 @@ class StackingController extends BaseAuthedController { $rows = Stacking::all(myself()->_getAddress()); foreach ($rows as $row) { if ($row['status'] == Stacking::STAKING_STATUS) { - $info = array(); - $info['token_id'] = $row['token_id']; - $info['token_type'] = $row['token_type']; - $info['contract_address'] = $row['contract_address']; - $info['net_id'] = $row['net_id']; - $info['start_time'] = $row['start_time']; - $info['stake_time'] = $row['stake_time']; - $info['txhash'] = $row['txhash']; - $info['item_id'] = $row['item_id']; - $info['stacked_days'] = intval((myself()->_getNowDaySeconds() - - myself()->_getDaySeconds($row['start_time'])) / 3600 / 24); - $info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']); - - - array_push($items, $info); + array_push($items, Stacking::toDto($info)); + ++$stackedQuant; } } myself()->_rspData(array( @@ -134,22 +121,7 @@ class StackingController extends BaseAuthedController { $rows = Stacking::all(myself()->_getAddress()); foreach ($rows as $row) { if ($row['status'] == Stacking::REDEEM_STATUS) { - $info = array(); - $info['token_id'] = $row['token_id']; - $info['token_type'] = $row['token_type']; - $info['contract_address'] = $row['contract_address']; - $info['net_id'] = $row['net_id']; - $info['start_time'] = $row['start_time']; - $info['stake_time'] = $row['stake_time']; - $info['txhash'] = $row['txhash']; - $info['item_id'] = $row['item_id']; - $info['stacked_days'] = intval( - (myself()->_getNowDaySeconds() - - myself()->_getDaySeconds($row['start_time']) + 3600 *24) / 3600 / 24); - $info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']); - - $info['total_rewards'] = $row['stacked_days'] *$info['daily_rewards']; - array_push($items, $info); + array_push($items, Staking::toDto($info)); } } myself()->_rspData(array( From c692f935e982ecc576bbbe3d06dad27ca09290a2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 08:18:40 +0800 Subject: [PATCH 08/23] 1 --- webapp/controller/StakingController.class.php | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 61654e39..339d9310 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -102,8 +102,10 @@ class StackingController extends BaseAuthedController { $rows = Stacking::all(myself()->_getAddress()); foreach ($rows as $row) { if ($row['status'] == Stacking::STAKING_STATUS) { - array_push($items, Stacking::toDto($info)); - ++$stackedQuant; + if ($this->isTypeNft($type, $row)) { + array_push($items, Stacking::toDto($info)); + ++$stackedQuant; + } } } myself()->_rspData(array( @@ -129,4 +131,26 @@ class StackingController extends BaseAuthedController { )); } + private function isTypeNft($type, $dbInfo) + { + switch ($type) { + case self::PLANET_TYPE: + { + + } + break; + case self::BADGE_TYPE: + { + + } + break; + case self::CEC_TYPE: + { + + } + break; + } + return false; + } + } From fee9be2d72899ad49a1bfcbd493853c4eefdeb88 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 08:24:28 +0800 Subject: [PATCH 09/23] 1 --- webapp/controller/StakingController.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 339d9310..f9e53f68 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -55,6 +55,9 @@ class StackingController extends BaseAuthedController { private function fillStackingInfo($info, $rows) { foreach ($rows as $row) { + if (!$this->isTypeNft($info['type'], $row)) { + continue; + } switch ($info['type']) { case self::PLANET_TYPE: { From 55f0fb10f99379a474c1605bdb84f14a34e84276 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 08:56:25 +0800 Subject: [PATCH 10/23] 1 --- webapp/controller/StakingController.class.php | 45 ++++++------------- 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index f9e53f68..08df3e82 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -17,43 +17,26 @@ class StackingController extends BaseAuthedController { $info = array( 'total_staking_value' => '0', 'daily_staking_value' => '0', - 'planet' => array( - 'type' => self::PLANET_TYPE, - 'is_open' => 1, - 'staked_quant' => 0, - 'claim_rewards' => 0, - 'daily_rewards' => 0, - 'staking_value' => 0, - 'maturity_quant' => 0, - ), - 'badge' => array( - 'type' => self::BADGE_TYPE, - 'is_open' => 1, - 'staked_quant' => 0, - 'claim_rewards' => 0, - 'daily_rewards' => 0, - 'staking_value' => 0, - 'maturity_quant' => 0, - ), - 'cec' => array( - 'type' => self::CEC_TYPE, - 'is_open' => 0, - 'staked_quant' => 0, - 'claim_rewards' => 0, - 'daily_rewards' => 0, - 'staking_value' => 0, - 'maturity_quant' => 0, - ), + 'planet' => array(), + 'badge' => array(), + 'cec' => array(), ); $rows = Stacking::all(myself()->_getAddress()); - $this->fillStackingInfo($info['planet'], $rows); - $this->fillStackingInfo($info['badge'], $rows); - $this->fillStackingInfo($info['cec'], $rows); + $this->fillStackingInfo($info['planet'], self::PLANET_TYPE, 1, $rows); + $this->fillStackingInfo($info['badge'], self::BADGE_TYPE, 1, $rows); + $this->fillStackingInfo($info['cec'], self::CEC_TYPE, 1, $rows); myself()->_rspData($info); } - private function fillStackingInfo($info, $rows) + private function fillStackingInfo(&$info, $type, $isOpen, $rows) { + $info['type'] = $type; + $info['is_open'] = $isOpen; + $info['staked_quant'] = 0; + $info['claim_rewards'] = 0; + $info['daily_rewards'] = 0; + $info['staking_value'] = 0; + $info['maturity_quant'] = 0; foreach ($rows as $row) { if (!$this->isTypeNft($info['type'], $row)) { continue; From 61e9e5fe0880b65c52a6437a940857f90c4d81e7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 09:03:43 +0800 Subject: [PATCH 11/23] 1 --- webapp/controller/StakingController.class.php | 45 ++++--------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 08df3e82..62e008be 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -38,45 +38,18 @@ class StackingController extends BaseAuthedController { $info['staking_value'] = 0; $info['maturity_quant'] = 0; foreach ($rows as $row) { - if (!$this->isTypeNft($info['type'], $row)) { - continue; - } - switch ($info['type']) { - case self::PLANET_TYPE: - { - if ($row['status'] == Stacking::STAKING_STATUS) { - if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { - $info['staked_quant'] += $row['stacked_num']; - } else { - $info['maturity_quant'] += $row['stacked_num']; - } - $stakingMeta = mt\Staking::get($row['item_id']); - if ($stakingMeta) { - $info['staking_value'] += $stakingMeta['stake_value']; - } + if ($this->isTypeNft($info['type'], $row) && + $row['status'] == Stacking::STAKING_STATUS) { + if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { + $info['staked_quant'] += $row['stacked_num']; + } else { + $info['maturity_quant'] += $row['stacked_num']; } - } - break; - case self::BADGE_TYPE: - { - if ($row['status'] == Stacking::STAKING_STATUS) { - if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { - $info['staked_quant'] += $row['stacked_num']; - } else { - $info['maturity_quant'] += $row['stacked_num']; - } - if ($stakingMeta) { - $info['staking_value'] += $stakingMeta['stake_value']; - } + $stakingMeta = mt\Staking::get($row['item_id']); + if ($stakingMeta) { + $info['staking_value'] += $stakingMeta['stake_value']; } } - break; - case self::CEC_TYPE: - { - - } - break; - } } } From 75b41c7ce41da6ee082e6d257984afc627f583b2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 10:00:35 +0800 Subject: [PATCH 12/23] 1 --- webapp/controller/StakingController.class.php | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 62e008be..6bf967a7 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -17,21 +17,28 @@ class StackingController extends BaseAuthedController { $info = array( 'total_staking_value' => '0', 'daily_staking_value' => '0', - 'planet' => array(), - 'badge' => array(), - 'cec' => array(), + 'planet' => array( + 'type' => self::PLANET_TYPE, + 'is_open' => 1 + ), + 'badge' => array( + 'type' => self::BADGE_TYPE, + 'is_open' => 1 + ), + 'cec' => array( + 'type' => self::CEC_TYPE, + 'is_open' => 0 + ), ); $rows = Stacking::all(myself()->_getAddress()); - $this->fillStackingInfo($info['planet'], self::PLANET_TYPE, 1, $rows); - $this->fillStackingInfo($info['badge'], self::BADGE_TYPE, 1, $rows); - $this->fillStackingInfo($info['cec'], self::CEC_TYPE, 1, $rows); + $this->fillStackingInfo($info['planet'], $rows); + $this->fillStackingInfo($info['badge'], $rows); + $this->fillStackingInfo($info['cec'], $rows); myself()->_rspData($info); } - private function fillStackingInfo(&$info, $type, $isOpen, $rows) + private function fillStackingInfo(&$info, $rows) { - $info['type'] = $type; - $info['is_open'] = $isOpen; $info['staked_quant'] = 0; $info['claim_rewards'] = 0; $info['daily_rewards'] = 0; From 5722c46f54c5d52ca05e2e7a349d606c060c8992 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 10:58:29 +0800 Subject: [PATCH 13/23] 1 --- webapp/controller/StakingController.class.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 6bf967a7..e9779190 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -31,30 +31,30 @@ class StackingController extends BaseAuthedController { ), ); $rows = Stacking::all(myself()->_getAddress()); - $this->fillStackingInfo($info['planet'], $rows); - $this->fillStackingInfo($info['badge'], $rows); - $this->fillStackingInfo($info['cec'], $rows); + $this->fillStackingInfo($info, 'planet', $rows); + $this->fillStackingInfo($info, 'badge', $rows); + $this->fillStackingInfo($info, 'cec', $rows); myself()->_rspData($info); } private function fillStackingInfo(&$info, $rows) { - $info['staked_quant'] = 0; - $info['claim_rewards'] = 0; - $info['daily_rewards'] = 0; - $info['staking_value'] = 0; - $info['maturity_quant'] = 0; + $stackingInfo['staked_quant'] = 0; + $stackingInfo['claim_rewards'] = 0; + $stackingInfo['daily_rewards'] = 0; + $stackingInfo['staking_value'] = 0; + $stackingInfo['maturity_quant'] = 0; foreach ($rows as $row) { - if ($this->isTypeNft($info['type'], $row) && + if ($this->isTypeNft($stackingInfo['type'], $row) && $row['status'] == Stacking::STAKING_STATUS) { if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { - $info['staked_quant'] += $row['stacked_num']; + $stackingInfo['staked_quant'] += $row['stacked_num']; } else { - $info['maturity_quant'] += $row['stacked_num']; + $stackingInfo['maturity_quant'] += $row['stacked_num']; } $stakingMeta = mt\Staking::get($row['item_id']); if ($stakingMeta) { - $info['staking_value'] += $stakingMeta['stake_value']; + $stackingInfo['staking_value'] += $stakingMeta['stake_value']; } } } From b96080626b4a747149bd4248d9ca7f5a2c9dd1eb Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 11:35:10 +0800 Subject: [PATCH 14/23] 1 --- webapp/controller/StakingController.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index e9779190..f5b5544d 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -37,8 +37,9 @@ class StackingController extends BaseAuthedController { myself()->_rspData($info); } - private function fillStackingInfo(&$info, $rows) + private function fillStackingInfo(&$info, $fieldName, $rows) { + $stackingInfo = $info[$fieldName]; $stackingInfo['staked_quant'] = 0; $stackingInfo['claim_rewards'] = 0; $stackingInfo['daily_rewards'] = 0; From af2f99ca8bae7bdbdc6a29fb37863a89b6167a4c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 26 Aug 2023 11:37:02 +0800 Subject: [PATCH 15/23] 1 --- webapp/controller/StakingController.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index f5b5544d..13e331f0 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -56,6 +56,7 @@ class StackingController extends BaseAuthedController { $stakingMeta = mt\Staking::get($row['item_id']); if ($stakingMeta) { $stackingInfo['staking_value'] += $stakingMeta['stake_value']; + $info['total_staking_value'] += $stakingMeta['stake_value']; } } } From 6879a6cdb9d45ac6e16c2a48644e5ea64726c56f Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 27 Aug 2023 09:34:54 +0800 Subject: [PATCH 16/23] 1 --- doc/Staking.py | 4 ++-- webapp/controller/StakingController.class.php | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/doc/Staking.py b/doc/Staking.py index d3068b35..90a515a3 100644 --- a/doc/Staking.py +++ b/doc/Staking.py @@ -16,8 +16,8 @@ class Staking(object): ], 'response': [ _common.RspHead(), - ['total_staking_value', '', '质押总ceg价值'], - ['daily_staking_value', '', '当天总ceg价值'], + ['total_staking_value', '', '质押总ceg价值,包含利息'], + ['daily_staking_value', '', '当天总ceg价值,包含利息'], ['planet', _common.Staking(), '星球质押'], ['badge', _common.Staking(), '徽章质押'], ['cec', _common.Staking(), 'cec质押'], diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 13e331f0..c83cbcc8 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -46,17 +46,20 @@ class StackingController extends BaseAuthedController { $stackingInfo['staking_value'] = 0; $stackingInfo['maturity_quant'] = 0; foreach ($rows as $row) { - if ($this->isTypeNft($stackingInfo['type'], $row) && - $row['status'] == Stacking::STAKING_STATUS) { - if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { - $stackingInfo['staked_quant'] += $row['stacked_num']; - } else { - $stackingInfo['maturity_quant'] += $row['stacked_num']; - } + if ($this->isTypeNft($stackingInfo['type'], $row)) { $stakingMeta = mt\Staking::get($row['item_id']); - if ($stakingMeta) { - $stackingInfo['staking_value'] += $stakingMeta['stake_value']; - $info['total_staking_value'] += $stakingMeta['stake_value']; + if ($row['status'] == Stacking::STAKING_STATUS) { + if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { + $stackingInfo['staked_quant'] += $row['stacked_num']; + } else { + $stackingInfo['maturity_quant'] += $row['stacked_num']; + } + if ($stakingMeta) { + $stackingInfo['staking_value'] += $stakingMeta['stake_value']; + $info['total_staking_value'] += $stakingMeta['stake_value']; + } + + } else { } } } From f01e7c8be8f1158d3fa30f3ebb53376991f0be0d Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 27 Aug 2023 09:41:28 +0800 Subject: [PATCH 17/23] 1 --- webapp/controller/StakingController.class.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index c83cbcc8..023afa6e 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -46,21 +46,18 @@ class StackingController extends BaseAuthedController { $stackingInfo['staking_value'] = 0; $stackingInfo['maturity_quant'] = 0; foreach ($rows as $row) { - if ($this->isTypeNft($stackingInfo['type'], $row)) { - $stakingMeta = mt\Staking::get($row['item_id']); + $stakingMeta = mt\Staking::get($row['item_id']); + if ($this->isTypeNft($stackingInfo['type'], $row) && $stakingMeta) { if ($row['status'] == Stacking::STAKING_STATUS) { if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { $stackingInfo['staked_quant'] += $row['stacked_num']; } else { $stackingInfo['maturity_quant'] += $row['stacked_num']; } - if ($stakingMeta) { - $stackingInfo['staking_value'] += $stakingMeta['stake_value']; - $info['total_staking_value'] += $stakingMeta['stake_value']; - } - } else { } + $stackingInfo['staking_value'] += $stakingMeta['stake_value']; + $info['total_staking_value'] += $stakingMeta['stake_value']; } } } From 9e747116a526fa53ec48b4b411d34c50077ddea1 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 27 Aug 2023 15:35:43 +0800 Subject: [PATCH 18/23] 1 --- webapp/controller/StakingController.class.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 023afa6e..fef40f5e 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -48,16 +48,20 @@ class StackingController extends BaseAuthedController { foreach ($rows as $row) { $stakingMeta = mt\Staking::get($row['item_id']); if ($this->isTypeNft($stackingInfo['type'], $row) && $stakingMeta) { - if ($row['status'] == Stacking::STAKING_STATUS) { - if ($row['start_time'] + $row['stake_time'] < myself()->_getNowTime()) { - $stackingInfo['staked_quant'] += $row['stacked_num']; + $stakingDto = Staking::toDto($row); + if ($stakingDto['status'] == Stacking::STAKING_STATUS) { + if ($stakingDto['start_time'] + $stakingDto['stake_time'] < myself()->_getNowTime()) { + $stackingInfo['staked_quant'] += $stakingDto['stacked_num']; } else { - $stackingInfo['maturity_quant'] += $row['stacked_num']; + $stackingInfo['maturity_quant'] += $stakingDto['stacked_num']; } + $stackingInfo['staking_value'] += $stakingMeta['stake_value']; + $stackingInfo['daily_rewards'] += $stakingMeta['daily_rewards']; } else { + $stackingInfo['claim_rewards'] += $stakingMeta['total_rewards']; } - $stackingInfo['staking_value'] += $stakingMeta['stake_value']; $info['total_staking_value'] += $stakingMeta['stake_value']; + $info['total_staking_value'] += $stakingMeta['cec_rewards']; } } } From d238a699e932c7016bdf0a037910d16e125396da Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 27 Aug 2023 16:08:06 +0800 Subject: [PATCH 19/23] 1 --- webapp/models/Staking.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 6bc9c1c9..4a765036 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -164,6 +164,29 @@ class Staking extends BaseModel { } } + public static function toDto($row) + { + $dto = array( + 'token_id' => $row['token_id'], + 'token_type' => $row['token_type'], + 'contract_address' => $row['contract_address'], + 'net_id' => $row['net_id'], + 'start_time' => $row['start_time'], + 'stake_time' => $row['stake_time'], + 'txhash' => $row['txhash'], + + 'item_id' => $row['item_id'], + ); + $yesterDay = myself()->_getNowDaySeconds() - 3600 * 24; + $passedDays = intval((myself()->_getNowDaySeconds() - + myself()->_getDaySeconds($row['start_time'])) / + 3600 / 24); + $saveDays = intval($row['stake_time'] / 3600 / 24); + $dto['stacked_days'] = max(0, $passedDays); + $dto['remain_days'] = max(0, $saveDays - $dto['stacked_days']); + return $dto; + } + public static function calcReward($row, &$reward) { $reward = 0; From 1120c295a8849962e1b35f9d174695e9755a4960 Mon Sep 17 00:00:00 2001 From: azw Date: Sun, 27 Aug 2023 16:22:46 +0800 Subject: [PATCH 20/23] 1 --- webapp/models/Staking.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 4a765036..15456cab 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -166,6 +166,7 @@ class Staking extends BaseModel { public static function toDto($row) { + $stakingMeta = mt\Staking::get($row['item_id']); $dto = array( 'token_id' => $row['token_id'], 'token_type' => $row['token_type'], @@ -176,14 +177,24 @@ class Staking extends BaseModel { 'txhash' => $row['txhash'], 'item_id' => $row['item_id'], + 'cec_value' => $stakingMeta['cec_value'] ); $yesterDay = myself()->_getNowDaySeconds() - 3600 * 24; $passedDays = intval((myself()->_getNowDaySeconds() - myself()->_getDaySeconds($row['start_time'])) / 3600 / 24); $saveDays = intval($row['stake_time'] / 3600 / 24); + $dailyInterest = self::getDailyInterest($row['stake_time']); $dto['stacked_days'] = max(0, $passedDays); $dto['remain_days'] = max(0, $saveDays - $dto['stacked_days']); + $dto['daily_rewards'] = $dto['cec_value'] * $dailyInterest; + if ($dto['remain_days'] <= 0 ) { + $dto['cec_rewards'] = $dto['daily_rewards'] * $saveDays; + $dto['total_rewards'] = $dto['daily_rewards'] * $saveDays; + } else { + $dto['cec_rewards'] = 0; + $dto['total_rewards'] = $dto['daily_rewards'] * ($saveDays - $passedDays); + } return $dto; } From f881a6c173cbcf184ef6524458bc7f54e1071a9d Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 28 Aug 2023 10:00:43 +0800 Subject: [PATCH 21/23] 1 --- webapp/controller/StakingController.class.php | 8 ++--- webapp/models/Staking.php | 31 ------------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index fef40f5e..8f2dafbe 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -50,13 +50,13 @@ class StackingController extends BaseAuthedController { if ($this->isTypeNft($stackingInfo['type'], $row) && $stakingMeta) { $stakingDto = Staking::toDto($row); if ($stakingDto['status'] == Stacking::STAKING_STATUS) { - if ($stakingDto['start_time'] + $stakingDto['stake_time'] < myself()->_getNowTime()) { - $stackingInfo['staked_quant'] += $stakingDto['stacked_num']; - } else { + if ($stakingDto['remain_days'] <= 0) { $stackingInfo['maturity_quant'] += $stakingDto['stacked_num']; + } else { + $stackingInfo['daily_rewards'] += $stakingMeta['daily_rewards']; } + $stackingInfo['staked_quant'] += $stakingDto['stacked_num']; $stackingInfo['staking_value'] += $stakingMeta['stake_value']; - $stackingInfo['daily_rewards'] += $stakingMeta['daily_rewards']; } else { $stackingInfo['claim_rewards'] += $stakingMeta['total_rewards']; } diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index 15456cab..0a420cb7 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -198,37 +198,6 @@ class Staking extends BaseModel { return $dto; } - public static function calcReward($row, &$reward) - { - $reward = 0; - $stakingMeta = mt\Staking::get($row['item_id']); - if (!$stakingMeta) { - return false; - } - $stakingValue = $stakingMeta['stake_value']; - $realValue = $stakingValue / self::getCecPrice(); - $dailyInterest = self::getDailyInterest($row['stake_time']); - $passedDays = myself()->_getNowTime() - $row['start_time']; - $saveDays = intval($row['stake_time'] / 3600 / 24); - if ($row['stake_time'] >= 3600 * 24 * 30 * 12 * 2) { - - } else if ($row['stake_time'] <= 3600 * 24 * 30 * 12 * 1) { - if ($row['redeem_time'] > 0) { - $redeemDays = intval(($row['redeem_time'] - $row['start_time']) / 3600 / 24); - if ($redeemDays < $saveDays) { - - } else { - $reward = $realValue * min($passedDays, $redeemDays) * $dailyInterest; - } - } else { - $reward = $realValue * min($passedDays, $saveDays) * $dailyInterest; - } - } else { - return false; - } - return true; - } - public static function getCecPrice() { return 1; From 5df4bb339bd2705396148e1640c0d0c86bd13099 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 28 Aug 2023 10:20:31 +0800 Subject: [PATCH 22/23] 1 --- webapp/controller/StakingController.class.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 8f2dafbe..410b7058 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -53,15 +53,17 @@ class StackingController extends BaseAuthedController { if ($stakingDto['remain_days'] <= 0) { $stackingInfo['maturity_quant'] += $stakingDto['stacked_num']; } else { - $stackingInfo['daily_rewards'] += $stakingMeta['daily_rewards']; + $stackingInfo['daily_rewards'] += $stakingMeta['cec_value'] * + $stakingMeta['daily_rewards']; + $info['daily_staking_value'] += $stakingMeta['cec_value'] * + $stakingMeta['daily_rewards']; } $stackingInfo['staked_quant'] += $stakingDto['stacked_num']; $stackingInfo['staking_value'] += $stakingMeta['stake_value']; } else { $stackingInfo['claim_rewards'] += $stakingMeta['total_rewards']; } - $info['total_staking_value'] += $stakingMeta['stake_value']; - $info['total_staking_value'] += $stakingMeta['cec_rewards']; + $info['total_staking_value'] += $stakingMeta['stake_value'] + $stackingInfo['daily_rewards']; } } } From 9509fbe9ebd220e7f1b453ee2b6bba43cfc60b2b Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 28 Aug 2023 10:31:34 +0800 Subject: [PATCH 23/23] 1 --- webapp/controller/StakingController.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index 410b7058..3c5bf8ca 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -2,8 +2,10 @@ require_once("mt/Stacking.php"); +require_once("models/Nft.php"); require_once("models/Stacking.php"); +use models\Nft; use models\Statcking; class StackingController extends BaseAuthedController { @@ -110,12 +112,19 @@ class StackingController extends BaseAuthedController { switch ($type) { case self::PLANET_TYPE: { + if (in_array($dbInfo['token_type'], array( + ))) { + } } break; case self::BADGE_TYPE: { - + if (in_array($dbInfo['token_type'], array( + Nft::HONOR1_TYPE + ))) { + return true; + } } break; case self::CEC_TYPE: