145 lines
4.3 KiB
PHP
145 lines
4.3 KiB
PHP
<?php
|
|
|
|
require_once("mt/Staking.php");
|
|
|
|
require_once("models/Nft.php");
|
|
require_once("models/Staking.php");
|
|
|
|
use models\Nft;
|
|
use models\Staking;
|
|
|
|
class StakingController extends BaseAuthedController {
|
|
|
|
const PLANET_TYPE = 1;
|
|
const BADGE_TYPE = 2;
|
|
const CEC_TYPE = 3;
|
|
|
|
public function info()
|
|
{
|
|
$info = array(
|
|
'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'] += $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'] + $stackingInfo['daily_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($info));
|
|
++$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($info));
|
|
}
|
|
}
|
|
myself()->_rspData(array(
|
|
'items' => $items
|
|
));
|
|
}
|
|
|
|
public function redeemPreview()
|
|
{
|
|
$transId = getReqVal('trans_id', 0);
|
|
}
|
|
|
|
private function isTypeNft($type, $dbInfo)
|
|
{
|
|
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:
|
|
{
|
|
|
|
}
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|