_getMysql(''), 't_staking', array( 'address' => $address ) ); foreach ($rows as $row) { 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; } } array_push($result, $row); } return $result; } public static function staked721($data, $netId) { foreach ($data['infos'] as $info) { $address = strtolower($info[0]); $nftAddress = strtolower($info[1]); $tokenId = $info[2]; $startTime = $info[3]; $stakeTime = $info[4]; SqlHelper::upsert( myself()->_getMysql(''), 't_staking', array( 'token_id' => $tokenId, 'contract_address' => $nftAddress, 'net_id' => $netId, 'start_time' => $nftAddress, ), array( ), array( 'address' => $address, 'token_id' => $tokenId, 'token_type' => '0', 'net_id' => $netId, 'contract_address' => $nftAddress, 'stacked_num' => 1, 'start_time' => $startTime, 'stake_time' => $stakeTime, 'status' => self::STAKING_STATUS, 'nft_type' => self::NFT721, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) ); $itemId = 0; $tokenType = 0; self::repair721NftInfo($tokenId, $nftAddress, $netId, $startTime, $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) { foreach ($data['infos'] as $info) { $address = strtolower($info[0]); $nftAddress = strtolower($info[1]); $tokenId = $info[2]; $startTime = $info[3]; $stakeTime = $info[4]; SqlHelper::upsert( myself()->_getMysql(''), 't_staking', array( 'token_id' => $tokenId, 'contract_address' => $nftAddress, 'net_id' => $netId, 'start_time' => $startTime, ), array( 'txhash' => $txHash, 'redeem_time' => $redeemTime, 'status' => self::REDEEM_STATUS, ), array( 'address' => $address, 'token_id' => $tokenId, 'token_type' => '0', 'net_id' => $netId, 'contract_address' => $nftAddress, 'stacked_num' => 1, 'start_time' => $startTime, 'stake_time' => $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($tokenId, $nftAddress, $netId, $startTime, $itemId, $tokenId); } } public static function calcReward($row, &$reward) { $stakingMeta = mt\Staking::get($row['item_id']); if (!$stakingMeta) { return false; } $stakingValue = $stakingMeta['stake_value']; $realValue = $stakingValue / self::getCecPrice(); if ($row['stake_time'] >= 3600 * 24 * 30 * 12 * 2) { } else if ($row['stake_time'] <= 3600 * 24 * 30 * 12 * 1) { } else { return false; } return true; } public static function getCecPrice() { return 1; } public static function getDailyInterest($stakeTime) { $months = intval($stakeTime / 3600 / 24 / 30); if ($months <= 0) { return 0; } //1 3 6 12 24 if ($months <= 1) { return 0.01 / 30 * $months; } else if ($months <= 3) { return 0.05 / 30 * $months; } else if ($months <= 6) { return 0.15 / 30 * $months; } else if ($months <= 12) { return 0.4 / 30 * $months; } else if ($months <= 24) { return 1 / 30 * $months; } else { return 0; } } }