From f2ecbbd7b9afe5b94a80e3a1454d156bd52e0fce Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 8 Aug 2024 13:54:22 +0800 Subject: [PATCH] delete Staking --- doc/README.php | 1 + doc/Staking.py | 89 ----- webapp/controller/OtherController.class.php | 4 +- webapp/controller/StakingController.class.php | 317 ---------------- webapp/models/Staking.php | 357 ------------------ webapp/services/callback/Redeem721.php | 35 -- webapp/services/callback/Staked721.php | 33 -- 7 files changed, 3 insertions(+), 833 deletions(-) delete mode 100644 doc/Staking.py delete mode 100644 webapp/controller/StakingController.class.php delete mode 100644 webapp/models/Staking.php delete mode 100644 webapp/services/callback/Redeem721.php delete mode 100644 webapp/services/callback/Staked721.php diff --git a/doc/README.php b/doc/README.php index ef19c17d..850f50f0 100644 --- a/doc/README.php +++ b/doc/README.php @@ -41,6 +41,7 @@ * 删除 c=Market * 2024/08/08 * 删除 c=Mall + * 删除 c=Staking * * */ diff --git a/doc/Staking.py b/doc/Staking.py deleted file mode 100644 index 5894b776..00000000 --- a/doc/Staking.py +++ /dev/null @@ -1,89 +0,0 @@ -# -*- coding: utf-8 -*- - -import _common - -class Staking(object): - - def __init__(self): - self.apis = [ - { - 'name': 'info', - 'desc': '获取质押信息', - 'group': 'Staking', - 'url': 'webapp/index.php?c=Staking&a=info', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['pool_size', '', '池子数量'], - ['total_staking_value', '', '质押总ceg价值,包含利息'], - ['daily_staking_value', '', '当天总ceg价值,包含利息'], - ['planet', _common.Staking(), '星球质押'], - ['badge', _common.Staking(), '徽章质押'], - ['cec', _common.Staking(), 'cec质押'], - ] - }, - { - 'name': 'staking', - 'desc': '质押中nft列表', - 'group': 'Staking', - 'url': 'webapp/index.php?c=Staking&a=staking', - 'params': [ - _common.ReqHead(), - ['type', '', '1: planet 2: badge 3:cec'], - ], - 'response': [ - _common.RspHead(), - ['type', '', '1: planet 2: badge 3:cec'], - ['stacked_quant', '', '当前该类型质押总数'], - ['!items', [_common.StakingDetail()], '质押列表'], - ] - }, - { - 'name': 'history', - 'desc': '领取历史', - 'group': 'Staking', - 'url': 'webapp/index.php?c=Staking&a=history', - 'params': [ - _common.ReqHead(), - ['from_time', '', '开始时间(utc时间)'], - ['to_time', '', '结束时间(utc时间)'], - ], - 'response': [ - _common.RspHead(), - ['!items', [_common.StakingDetail()], '领取历史'], - ] - }, - { - 'name': 'redeemPreview', - 'desc': '赎回预览', - 'group': 'Staking', - 'url': 'webapp/index.php?c=Staking&a=redeemPreview', - 'params': [ - _common.ReqHead(), - ['trans_id', '', 'trans_id'], - ], - 'response': [ - _common.RspHead(), - ['cec_rewards', 0, '该nft结算得到的ceg数量'], - ] - }, - { - 'name': 'stakingPreview', - 'desc': '质押预览', - 'group': 'Staking', - 'url': 'webapp/index.php?c=Staking&a=stakingPreview', - 'params': [ - _common.ReqHead(), - ['token_id_list', '', 'token_id多个|分割'], - ['contract_address_list', '', 'contract_address多个|分割'], - ['net_id', '', 'net_id'], - ], - 'response': [ - _common.RspHead(), - ['nft_value', 0, 'nft价值'], - ['!items', [_common.StakingPreview()], ''], - ] - }, - ] diff --git a/webapp/controller/OtherController.class.php b/webapp/controller/OtherController.class.php index 2ac82258..2866eac1 100644 --- a/webapp/controller/OtherController.class.php +++ b/webapp/controller/OtherController.class.php @@ -15,7 +15,7 @@ require_once('mt/AchievementsCycle.php'); require_once('models/SignLog.php'); require_once('models/RankingSetRecord.php'); -require_once('models/Staking.php'); +//require_once('models/Staking.php'); require_once('models/SeasonRanking.php'); require_once('models/RewardsCec.php'); require_once('models/GlobalData.php'); @@ -28,7 +28,7 @@ require_once('models/Bag.php'); use models\SignLog; use phpcommon\SqlHelper; use models\RankingSetRecord; -use models\Staking; +//use models\Staking; use models\SeasonRanking; use models\RewardsCec; use models\GlobalData; diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php deleted file mode 100644 index 8da02d62..00000000 --- a/webapp/controller/StakingController.class.php +++ /dev/null @@ -1,317 +0,0 @@ - 8000 * 10000 - Staking::getAllStakingValue(), - 'total_staking_value' => '0', - 'daily_staking_value' => '0', - '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 = Staking::all(myself()->_getAddress()); - $this->fillStakingInfo($info, 'planet', $rows); - $this->fillStakingInfo($info, 'badge', $rows); - $this->fillStakingInfo($info, 'cec', $rows); - myself()->_rspData($info); - } - - private function fillStakingInfo(&$info, $fieldName, $rows) - { - $stackingInfo = &$info[$fieldName]; - $stackingInfo['staked_quant'] = 0; - $stackingInfo['claim_rewards'] = 0; - $stackingInfo['daily_rewards'] = 0; - $stackingInfo['staking_value'] = 0; - $stackingInfo['maturity_quant'] = 0; - foreach ($rows as $row) { - $stakingMeta = mt\Staking::get($row['item_id']); - if ($this->isTypeNft($stackingInfo['type'], $row) && $stakingMeta) { - $stakingDto = Staking::toDto($row); - if ($stakingDto['status'] == Staking::STAKING_STATUS) { - if ($stakingDto['remain_days'] <= 0) { - $stackingInfo['maturity_quant'] += $stakingDto['stacked_num']; - } else { - $stackingInfo['daily_rewards'] += $stakingDto['daily_rewards']; - $info['daily_staking_value'] += $stakingDto['daily_rewards']; - } - $stackingInfo['staked_quant'] += $stakingDto['stacked_num']; - $stackingInfo['staking_value'] += $stakingDto['cec_value']; - $info['total_staking_value'] += $stakingDto['cec_value'] + $stakingDto['total_rewards']; - } else { - $stackingInfo['claim_rewards'] += $stakingDto['total_rewards']; - } - } - } - } - - public function staking() - { - $type = getReqVal('type', ''); - $stackedQuant = 0; - $items = array(); - $rows = Staking::all(myself()->_getAddress()); - foreach ($rows as $row) { - if ($row['status'] == Staking::STAKING_STATUS) { - if ($this->isTypeNft($type, $row)) { - array_push($items, Staking::toDto($row)); - ++$stackedQuant; - } - } - } - myself()->_rspData(array( - 'type' => $type, - 'stacked_quant' => $stackedQuant, - 'items' => $items - )); - } - - public function history() - { - $items = array(); - $fromTime = getReqVal('from_time', ''); - $toTime = getReqVal('to_time', ''); - $rows = Staking::all(myself()->_getAddress()); - foreach ($rows as $row) { - if ($row['status'] == Staking::REDEEM_STATUS) { - array_push($items, Staking::toDto($row)); - } - } - myself()->_rspData(array( - 'items' => $items - )); - } - - public function redeemPreview() - { - $transId = getReqVal('trans_id', 0); - $rows = Staking::all(myself()->_getAddress()); - $cegRewards = '0'; - foreach ($rows as $row) { - $stakingDto = Staking::toDto($row); - if ($stakingDto && $stakingDto['trans_id'] == $transId) { - if ($stakingDto['remain_days'] <= 0) { - $cegRewards = $stakingDto['total_rewards']; - } else { - $cegRewards = $stakingDto['total_rewards'] * 0.25; - } - break; - } - } - myself()->_rspData(array( - 'ceg_rewards' => $cegRewards - )); - } - - public function stakingPreview() - { - $checkList = array(); - { - $tokenIdList = explode('|', getReqVal('token_id_list', '')); - $contractAddressList = explode('|', strtolower(getReqVal('contract_address_list', ''))); - $netId = getReqVal('net_id', ''); - if (count($tokenIdList) <= 0) { - myself()->_rspErr(1, 'paramater error'); - return; - } - if (count($tokenIdList) != count($contractAddressList)) { - myself()->_rspErr(1, 'paramater error'); - return; - } - for ($i = 0; $i < count($tokenIdList); ++$i) { - if (array_key_exists($tokenIdList[$i], $checkList)) { - myself()->_rspErr(1, 'paramater error'); - return; - } - $checkList[$tokenIdList[$i]] = array( - 'token_id' => $tokenIdList[$i], - 'contract_address' => $contractAddressList[$i], - 'net_id' => $netId - ); - } - } - $confirmedNfts = array(); - { - $nftList = Nft::getNftList(myself()->_getAddress()); - foreach ($nftList as $nft) { - if (array_key_exists($nft['token_id'], $checkList)) { - $c = $checkList[$nft['token_id']]; - if ($c['contract_address'] == $nft['contract_address'] && - $c['net_id'] == $nft['net_id']) { - array_push($confirmedNfts, - $nft); - } - } - } - } - error_log(json_encode($_REQUEST)); - error_log(json_encode($checkList)); - error_log(json_encode($confirmedNfts)); - if (count($checkList) != count($confirmedNfts)) { - myself()->_rspErr(3, 'paramater error'); - return; - } - $nftValue = 0; - $items = array(); - $lastTimeArr = null; - foreach ($confirmedNfts as $nft) { - $stakingMeta = mt\Staking::get($nft['item_id']); - if (!$stakingMeta) { - myself()->_rspErr(4, 'config error'); - return; - } - $nftValue += $stakingMeta['stake_value']; - if ($lastTimeArr) { - if (count($lastTimeArr) != count($stakingMeta['stake_time_arr'])) { - myself()->_rspErr(5, 'config error'); - return; - } - for ($i = 0; $i < count($lastTimeArr); ++$i) { - if ($lastTimeArr[$i] != $stakingMeta['stake_time_arr'][$i]) { - myself()->_rspErr(5, 'config error'); - return; - } - } - } - $lastTimeArr = $stakingMeta['stake_time_arr']; - } - foreach ($lastTimeArr as $time) { - $days = intval($time / 30); - switch ($days) { - case 1: - { - array_push( - $items, - array( - 'time' => $days * 30, - 'interest' => 1 - ) - ); - } - break; - case 3: - { - array_push( - $items, - array( - 'time' => $days * 30, - 'interest' => 5 - ) - ); - } - break; - case 6: - { - array_push( - $items, - array( - 'time' => $days * 30, - 'interest' => 15 - ) - ); - } - break; - case 12: - { - array_push( - $items, - array( - 'time' => $days * 30, - 'interest' => 40 - ) - ); - } - break; - case 24: - { - array_push( - $items, - array( - 'time' => $days * 30, - 'interest' => 100 - ) - ); - } - break; - default: - { - myself()->_rspErr(10, 'config error'); - return; - } - break; - } - } - myself()->_rspData(array( - 'nft_value' => $nftValue, - 'items' => $items - )); - } - - private function isTypeNft($type, $dbInfo) - { - switch ($type) { - case self::PLANET_TYPE: - { - if (in_array($dbInfo['token_type'], array( - Nft::PLANET_TYPE - ))) { - return true; - } - } - break; - case self::BADGE_TYPE: - { - if (SERVER_ENV != _ONLINE) { - if (in_array($dbInfo['token_type'], array( - Nft::HONOR1_TYPE - ))) { - return true; - } - } else { - if (in_array($dbInfo['token_type'], array( - Nft::GENESIS_TYPE - ))) { - return true; - } - } - } - break; - case self::CEC_TYPE: - { - - } - break; - } - return false; - } - -} diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php deleted file mode 100644 index 54943978..00000000 --- a/webapp/models/Staking.php +++ /dev/null @@ -1,357 +0,0 @@ -_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) - { - if (SERVER_ENV != _ONLINE) { - //myself()->_setTimeOffset(3600 * 24 * 360 * 2); - } - $result = array(); - $rows = SqlHelper::ormSelect( - myself()->_getMysql(''), - 't_staking', - array( - 'address' => $address - ) - ); - foreach ($rows as &$row) { - if (SERVER_ENV != _ONLINE) { - if ($row['status'] == self::REDEEM_STATUS) { - $row['redeem_time'] += myself()->_getTimeOffset(); - } - } - if ($row['nft_type'] == self::NFT721) { - if (!$row['item_id']) { - $itemId = 0; - $tokenType = 0; - if (!self::repair721NftInfo($row['token_id'], $row['contract_address'], $row['net_id'], - $row['start_time'], $itemId, $tokenType)) { - continue; - } - $row['item_id'] = $itemId; - $row['token_type'] = $tokenType; - } - } - array_push($result, $row); - } - return $result; - } - - public static function getStakingTotalValue() - { - $totalValue = 0; - $rows = self::all(myself()->_getAddress()); - foreach ($rows as $row) { - $stakingDto = self::toDto($row); - if ($stakingDto['status'] == self::STAKING_STATUS) { - if ($stakingDto['remain_days'] > 0) { - $totalValue += $stakingDto['stake_usd_value']; - } else { - } - } - } - if (SERVER_ENV != _ONLINE) { - myself()->_setTimeOffset(0); - } - return $totalValue; - } - - public static function staked721($data, $netId) - { - foreach ($data['infos'] as $info) { - $address = strtolower($info[0]); - $nftAddress = strtolower($info[1]); - $tokenId = $info[2]; - $startTime = $info[3]; - $stakeTime = $info[4]; - $userDb = User::findByAddress($address); - SqlHelper::upsert( - myself()->_getMysql(''), - 't_staking', - array( - 'token_id' => $tokenId, - 'contract_address' => $nftAddress, - 'net_id' => $netId, - 'start_time' => $nftAddress, - ), - array( - - ), - array( - 'account_id' => $userDb ? $userDb['account_id'] : '', - 'address' => $address, - 'token_id' => $tokenId, - 'token_type' => '0', - 'net_id' => $netId, - 'contract_address' => $nftAddress, - 'stacked_num' => 1, - 'start_time' => $startTime, - 'stake_time' => $stakeTime, - 'status' => self::STAKING_STATUS, - 'nft_type' => self::NFT721, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime(), - ) - ); - $itemId = 0; - $tokenType = 0; - self::repair721NftInfo($tokenId, $nftAddress, $netId, $startTime, - $itemId, $tokenId); - } - } - - public static function repair721NftInfo($tokenId, $contractAddress, $netId, $startTime, - &$itemId, &$tokenType) - { - $row = SqlHelper::ormSelectOne( - myself()->_getMarketMysql(), - 't_nft', - array( - 'token_id' => $tokenId, - 'contract_address' => $contractAddress, - 'net_id' => $netId, - ) - ); - if (!$row) { - return false; - } - $itemId = $row['item_id']; - $tokenType = $row['token_type']; - SqlHelper::update( - myself()->_getMysql(''), - 't_staking', - array( - 'token_id' => $tokenId, - 'contract_address' => $contractAddress, - 'net_id' => $netId, - 'start_time' => $startTime, - 'nft_type' => self::NFT721, - ), - array( - 'item_id' => $itemId, - 'token_type' => $tokenType - ) - ); - return true; - } - - public static function redeem721($data, $netId, $redeemTime, $txHash) - { - foreach ($data['infos'] as $info) { - $address = strtolower($info[0]); - $nftAddress = strtolower($info[1]); - $tokenId = $info[2]; - $startTime = $info[3]; - $stakeTime = $info[4]; - $userDb = User::findByAddress($address); - SqlHelper::upsert( - myself()->_getMysql(''), - 't_staking', - array( - 'token_id' => $tokenId, - 'contract_address' => $nftAddress, - 'net_id' => $netId, - 'start_time' => $startTime, - ), - array( - 'txhash' => $txHash, - 'redeem_time' => $redeemTime, - 'status' => self::REDEEM_STATUS, - ), - array( - 'account_id' => $userDb ? $userDb['account_id'] : '', - 'address' => $address, - 'token_id' => $tokenId, - 'token_type' => '0', - 'net_id' => $netId, - 'contract_address' => $nftAddress, - 'stacked_num' => 1, - 'start_time' => $startTime, - 'stake_time' => $stakeTime, - 'txhash' => $txHash, - 'redeem_time' => $redeemTime, - 'status' => self::REDEEM_STATUS, - 'nft_type' => self::NFT721, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime(), - ) - ); - $itemId = 0; - $tokenType = 0; - self::repair721NftInfo($tokenId, $nftAddress, $netId, $startTime, - $itemId, $tokenId); - } - } - - public static function toDto($row) - { - $stakingMeta = mt\Staking::get($row['item_id']); - $dto = array( - 'trans_id' => $row['idx'], - 'token_id' => $row['token_id'], - 'token_type' => $row['token_type'], - 'contract_address' => $row['contract_address'], - 'net_id' => $row['net_id'], - 'order_id' => $row['order_id'], - 'start_time' => $row['start_time'], - 'stake_time' => $row['stake_time'], - 'redeem_time' => $row['redeem_time'], - 'txhash' => $row['txhash'], - - 'item_id' => $row['item_id'], - 'status' => $row['status'], - 'stacked_num' => $row['stacked_num'], - 'cec_value' => $stakingMeta['stake_value'], - 'stake_usd_value' => $stakingMeta['stake_usd_value'], - ); - $passedDays = intval(((myself()->_getNowDaySeconds()) - - (myself()->_getDaySeconds($row['start_time']) + 3600 * 24)) / - 3600 / 24); - $passedDays = max(0, $passedDays); - $saveDays = max(0, intval($row['stake_time'] / 3600 / 24)); - $dto['stacked_days'] = $passedDays; - $dto['remain_days'] = max(0, $saveDays - $dto['stacked_days']); - $stakedDays = $dto['stacked_days']; - $dailyInterest = self::getDailyInterest($row['stake_time'], $dto['remain_days']); - $dto['daily_rewards'] = $dto['cec_value'] * $dailyInterest; - $dto['cec_rewards'] = 0; - $dto['total_rewards'] = 0; - if ($dto['status'] == self::REDEEM_STATUS) { - $stakedDays = intval((myself()->_getDaySeconds($dto['redeem_time']) - - (myself()->_getDaySeconds($row['start_time']) + 3600 * 24)) / 3600 / 24); - $stakedDays = max($stakedDays, 0); - $stakedDays = min($stakedDays, $saveDays); - $dto['stacked_days'] = $stakedDays; - /* - if ($dto['stacked_days'] <= 0) { - error_log(json_encode(array( - 'src_stacked_days' => $stakedDays, - 'now_daySeocnds' => myself()->_getNowDaySeconds(), - 'now_time' => myself()->_getNowTime(), - 'redeem_time' => myself()->_getDaySeconds($dto['redeem_time']) - ))); - }*/ - $rate = 0.25; - if ($stakedDays >= $saveDays) { - $rate = 1; - } - if ($saveDays >= 30 * 12 * 2) { - $stakedDays = max($stakedDays, 0); - $dto['cec_rewards'] = ($dto['cec_value'] * (0.6 / 30 / 12)) * min(30 * 12, $stakedDays) * $rate; - $dto['cec_rewards'] += ($dto['cec_value'] * (0.4 / 30 / 12)) * max(0, $stakedDays - 30 * 12) * $rate; - } else { - $dto['cec_rewards'] = $dto['daily_rewards'] * $stakedDays * $rate; - } - $dto['total_rewards'] = $dto['cec_rewards']; - } else { - $stakedDays = max($stakedDays, 0); - $stakedDays = min($stakedDays, $saveDays); - if ($dto['remain_days'] <= 0 ) { - $dto['cec_rewards'] = $dto['daily_rewards'] * $stakedDays; - if ($saveDays >= 30 * 12 * 2) { - $dto['cec_rewards'] = $dto['cec_value'] * 1; - } - } else { - if ($saveDays >= 30 * 12 * 2) { - $dto['cec_rewards'] = ($dto['cec_value'] * (0.6 / 30 / 12)) * min(30 * 12, $stakedDays); - $dto['cec_rewards'] += ($dto['cec_value'] * (0.6 / 30 / 12)) * max(0, $stakedDays - 30 * 12); - } else { - $dto['cec_rewards'] = $dto['daily_rewards'] * $stakedDays; - } - } - $dto['total_rewards'] = $dto['cec_rewards']; - } - return $dto; - } - - public static function getCecPrice() - { - return 1; - } - - private static function getDailyInterest($stakeTime, $remainDays) - { - $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) { - if ($remainDays > 360) { - return 0.6 / 30 / 12; - } else { - return 0.4 / 30 / 12; - } - } else { - return 0; - } - } - - 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; - } - } - -} diff --git a/webapp/services/callback/Redeem721.php b/webapp/services/callback/Redeem721.php deleted file mode 100644 index cc02843f..00000000 --- a/webapp/services/callback/Redeem721.php +++ /dev/null @@ -1,35 +0,0 @@ -_rspOk(); - } - -} diff --git a/webapp/services/callback/Staked721.php b/webapp/services/callback/Staked721.php deleted file mode 100644 index cfd5b7fe..00000000 --- a/webapp/services/callback/Staked721.php +++ /dev/null @@ -1,33 +0,0 @@ -_rspOk(); - } - -}