This commit is contained in:
aozhiwei 2024-08-06 15:07:27 +08:00
parent 2699be5296
commit 114835ca6d
2 changed files with 141 additions and 0 deletions

View File

@ -348,4 +348,9 @@ class TempToolsController extends BaseController {
}
}
public function exportStaking()
{
}
}

View File

@ -5,10 +5,12 @@ namespace models;
require_once("mt/Staking.php");
require_once("models/User.php");
require_once("models/Nft.php");
use phpcommon\SqlHelper;
use mt;
use models\Nft;
class Staking extends BaseModel {
@ -355,4 +357,138 @@ class Staking extends BaseModel {
}
}
public static function exportStatData()
{
$addressHash = self::getAllAddressHash();
$poolSize = 8000 * 10000 - self::getAllStakingValue();
foreach ($addressHash as $rows) {
$info = array(
'pool_size' => $poolSize,
'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
),
);
self::fillStakingInfo($info, 'planet', $rows);
self::fillStakingInfo($info, 'badge', $rows);
self::fillStakingInfo($info, 'cec', $rows);
}
}
private static 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 (self::isTypeNft($stackingInfo['type'], $row) && $stakingMeta) {
$stakingDto = self::toDto($row);
if ($stakingDto['status'] == self::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 static function getAllAddressHash()
{
$rows = SqlHelper::ormSelect(
myself()->_getMysql(''),
't_staking',
array(
)
);
$addressHash = array();
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;
}
}
if (!array_key_exists($row['address'], $addressHash)) {
$addressHash[$row['address']] = array();
}
array_push($addressHash[$row['address']], $row);
}
return $addressHash;
}
private static 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;
}
const PLANET_TYPE = 1;
const BADGE_TYPE = 2;
const CEC_TYPE = 3;
}