140 lines
4.4 KiB
PHP
140 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace models;
|
|
|
|
class Staking extends BaseModel {
|
|
|
|
const STAKING_STATUS = 0;
|
|
const REDEEM_STATUS = 1;
|
|
|
|
const NFT721 = 1;
|
|
|
|
public static function all($address)
|
|
{
|
|
$rows = SqlHelper::ormSelect(
|
|
myself()->_getMysql(''),
|
|
't_staking',
|
|
array(
|
|
'address' => $address
|
|
)
|
|
);
|
|
return $rows;
|
|
}
|
|
|
|
public static function staked721($data, $netId)
|
|
{
|
|
$address = $data['address'];
|
|
foreach ($data['infos'] as $info) {
|
|
SqlHelper::upsert(
|
|
myself()->_getMysql(''),
|
|
't_staking',
|
|
array(
|
|
'token_id' => $info['tokenid'],
|
|
'contract_address' => $info['nft'],
|
|
'net_id' => $netId,
|
|
'start_time' => $info['start'],
|
|
),
|
|
array(
|
|
|
|
),
|
|
array(
|
|
'address' => $address,
|
|
'token_id' => $info['tokenid'],
|
|
'token_type' => '0',
|
|
'net_id' => $netId,
|
|
'contract_address' => $info['nft'],
|
|
'stacked_num' => 1,
|
|
'start_time' => $info['start'],
|
|
'stake_time' => $info['stakeTime'],
|
|
'status' => self::STAKING_STATUS,
|
|
'nft_type' => self::NFT721,
|
|
'createtime' => myself()->_getNowTime(),
|
|
'modifytime' => myself()->_getNowTime(),
|
|
)
|
|
);
|
|
$itemId = 0;
|
|
$tokenType = 0;
|
|
self::repair721NftInfo($info['tokenid'], $info['nft'], $netId, $info['start'],
|
|
$itemId, $tokenId);
|
|
}
|
|
}
|
|
|
|
public static function repair721NftInfo($tokenId, $contractAddress, $netId, $startTime,
|
|
&$itemId, &$tokenType)
|
|
{
|
|
$row = SqlHelper::ormSelect(
|
|
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)
|
|
{
|
|
$address = $data['address'];
|
|
foreach ($data['infos'] as $info) {
|
|
SqlHelper::upsert(
|
|
myself()->_getMysql(''),
|
|
't_staking',
|
|
array(
|
|
'token_id' => $info['tokenid'],
|
|
'contract_address' => $info['nft'],
|
|
'net_id' => $netId,
|
|
'start_time' => $info['start'],
|
|
),
|
|
array(
|
|
'txhash' => $txHash,
|
|
'redeem_time' => $redeemTime,
|
|
'status' => self::REDEEM_STATUS,
|
|
),
|
|
array(
|
|
'address' => $address,
|
|
'token_id' => $info['tokenid'],
|
|
'token_type' => '0',
|
|
'net_id' => $netId,
|
|
'contract_address' => $info['nft'],
|
|
'stacked_num' => 1,
|
|
'start_time' => $info['start'],
|
|
'stake_time' => $info['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($info['tokenid'], $info['nft'], $netId, $info['start'],
|
|
$itemId, $tokenId);
|
|
}
|
|
}
|
|
|
|
}
|