116 lines
3.1 KiB
PHP
116 lines
3.1 KiB
PHP
<?php
|
|
|
|
require_once("mt/Stacking.php");
|
|
|
|
require_once("models/Stacking.php");
|
|
|
|
use models\Statcking;
|
|
|
|
class StackingController 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(),
|
|
'badge' => array(),
|
|
'cec' => array(),
|
|
);
|
|
$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);
|
|
myself()->_rspData($info);
|
|
}
|
|
|
|
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) &&
|
|
$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'];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function stacking()
|
|
{
|
|
$type = getReqVal('type', '');
|
|
$stackedQuant = 0;
|
|
$items = array();
|
|
$rows = Stacking::all(myself()->_getAddress());
|
|
foreach ($rows as $row) {
|
|
if ($row['status'] == Stacking::STAKING_STATUS) {
|
|
if ($this->isTypeNft($type, $row)) {
|
|
array_push($items, Stacking::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 = Stacking::all(myself()->_getAddress());
|
|
foreach ($rows as $row) {
|
|
if ($row['status'] == Stacking::REDEEM_STATUS) {
|
|
array_push($items, Staking::toDto($info));
|
|
}
|
|
}
|
|
myself()->_rspData(array(
|
|
'items' => $items
|
|
));
|
|
}
|
|
|
|
private function isTypeNft($type, $dbInfo)
|
|
{
|
|
switch ($type) {
|
|
case self::PLANET_TYPE:
|
|
{
|
|
|
|
}
|
|
break;
|
|
case self::BADGE_TYPE:
|
|
{
|
|
|
|
}
|
|
break;
|
|
case self::CEC_TYPE:
|
|
{
|
|
|
|
}
|
|
break;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|