This commit is contained in:
aozhiwei 2023-08-24 19:11:35 +08:00
parent 895a4557fa
commit 6c8e56ad46
2 changed files with 95 additions and 2 deletions

View File

@ -78,6 +78,7 @@ CREATE TABLE `t_staking` (
`token_type` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片 6:荣誉 7:徽章',
`net_id` bigint NOT NULL DEFAULT '0' COMMENT 'net_id',
`contract_address` varchar(60) NOT NULL DEFAULT '' COMMENT 'contract_address',
`stacked_num` varchar(60) NOT NULL DEFAULT '' COMMENT 'stacked_num',
`start_time` bigint NOT NULL DEFAULT '0' COMMENT '质押开始时间',
`stake_time` bigint NOT NULL DEFAULT '0' COMMENT '质押结束时间',
`unstake_time` bigint NOT NULL DEFAULT '0' COMMENT '解押结束时间',

View File

@ -2,8 +2,6 @@
require_once("models/Stacking.php");
use phpcommon\SqlHelper;
use models\Statcking;
class StackingController extends BaseAuthedController {
@ -46,7 +44,101 @@ class StackingController extends BaseAuthedController {
),
);
$rows = Stacking::all(myself()->_getAddress());
$this->fillStackingInfo($info['planet'], $rows);
$this->fillStackingInfo($info['badge'], $rows);
$this->fillStackingInfo($info['cec'], $rows);
myself()->_rspData($info);
}
private function fillStackingInfo($info, $rows)
{
foreach ($rows as $row) {
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'];
}
$info['staking_value'] += $row['ceg_value'];
}
}
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'];
}
$info['staking_value'] += $row['ceg_value'];
}
}
break;
case self::CEC_TYPE:
{
}
break;
}
}
}
public function stacking()
{
$type = getReqVal('type', '');
$stackedQuant = 0;
$items = array();
$rows = Stacking::all(myself()->_getAddress());
foreach ($rows as $row) {
if ($row['status'] == Stacking::UNSTAKE_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'];
array_push($items, $info);
}
}
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::UNSTAKE_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'];
array_push($items, $info);
}
}
myself()->_rspData(array(
'items' => $items
));
}
}