diff --git a/doc/AccountVerify.py b/doc/AccountVerify.py new file mode 100644 index 00000000..a02ff5dd --- /dev/null +++ b/doc/AccountVerify.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +import _common + +class AccountVerify(object): + + def __init__(self): + self.apis = [ + { + 'method': 'GET', + 'name': 'canBind', + 'desc': '是否可绑定', + 'group': 'AccountVerify', + 'url': 'webapp/index.php?c=AccountVerify&a=canBind', + 'params': [ + _common.ReqHead(), + ['guest_account', '', 'guest账号'], + ['target_plat', '', '绑定的目标账号渠道'], + ['target_account', '', '绑定的目标账号'], + ], + 'response': [ + _common.RspHead(), + ] + }, + ] diff --git a/sql/gamedb2006_migrate_230816_01.sql b/sql/gamedb2006_migrate_230816_01.sql index ed92b262..b9257fc3 100644 --- a/sql/gamedb2006_migrate_230816_01.sql +++ b/sql/gamedb2006_migrate_230816_01.sql @@ -81,15 +81,15 @@ CREATE TABLE `t_staking` ( `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 '解押结束时间', + `redeem_time` bigint NOT NULL DEFAULT '0' COMMENT '赎回时间', `status` int(11) NOT NULL COMMENT '0:质押中 1:已解押', `txhash` varchar(255) NOT NULL DEFAULT '' COMMENT 'txhash', - `ceg_value` double NOT NULL DEFAULT '0' COMMENT 'ceg价值', - `ceg_reward` double NOT NULL DEFAULT '0' COMMENT '利息', + `nft_type` int(11) NOT NULL COMMENT '', + `nft_reward` double NOT NULL DEFAULT '0' COMMENT '利息', `createtime` int(11) NOT NULL COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), - UNIQUE KEY `unikey` (`token_id`, `contract_address`, `net_id`, `start_time`) + UNIQUE KEY `unikey` (`token_id`, `contract_address`, `net_id`, `start_time`), KEY `address` (`address`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8; diff --git a/webapp/controller/AccountVerifyController.class.php b/webapp/controller/AccountVerifyController.class.php new file mode 100644 index 00000000..aabfbc8b --- /dev/null +++ b/webapp/controller/AccountVerifyController.class.php @@ -0,0 +1,38 @@ +_getMysql(''), + 't_user', + array( + 'account_id' => TAPTAP_CHANNEL . '_2006_' . $guestAccount + )); + if (!$row) { + myself()->_rspErr(1, 'guest_account not found'); + return; + } + } + { + $row = SqlHelper::ormSelectOne( + myself()->_getMysql(''), + 't_user', + array( + 'account_id' => BC_POLY_CHANNEL . '_2006_' . $targetPlat . '_' . $targetAccount + )); + if ($row) { + myself()->_rspErr(1, 'cannot bind'); + return; + } + } + } + +} diff --git a/webapp/controller/StakingController.class.php b/webapp/controller/StakingController.class.php index b88cfa17..98734916 100644 --- a/webapp/controller/StakingController.class.php +++ b/webapp/controller/StakingController.class.php @@ -1,5 +1,7 @@ _getNowDaySeconds() - + myself()->_getDaySeconds($row['start_time'])) / 3600 / 24); + $info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']); + array_push($items, $info); } @@ -122,7 +133,7 @@ class StackingController extends BaseAuthedController { $toTime = getReqVal('to_time', ''); $rows = Stacking::all(myself()->_getAddress()); foreach ($rows as $row) { - if ($row['status'] == Stacking::UNSTAKE_STATUS) { + if ($row['status'] == Stacking::REDEEM_STATUS) { $info = array(); $info['token_id'] = $row['token_id']; $info['token_type'] = $row['token_type']; @@ -132,7 +143,12 @@ class StackingController extends BaseAuthedController { $info['stake_time'] = $row['stake_time']; $info['txhash'] = $row['txhash']; $info['item_id'] = $row['item_id']; + $info['stacked_days'] = intval( + (myself()->_getNowDaySeconds() - + myself()->_getDaySeconds($row['start_time']) + 3600 *24) / 3600 / 24); + $info['remain_days'] = max(0, intval($row['stake_time'] / 3600 / 24) - $info['stacked_days']); + $info['total_rewards'] = $row['stacked_days'] *$info['daily_rewards']; array_push($items, $info); } } diff --git a/webapp/models/Staking.php b/webapp/models/Staking.php index bc6fabe6..4180700b 100644 --- a/webapp/models/Staking.php +++ b/webapp/models/Staking.php @@ -2,13 +2,20 @@ namespace models; +require_once("mt/Staking.php"); + +use phpcommon\SqlHelper; + class Staking extends BaseModel { const STAKING_STATUS = 0; - const UNSTAKE_STATUS = 1; + const REDEEM_STATUS = 1; + + const NFT721 = 1; public static function all($address) { + $result = array(); $rows = SqlHelper::ormSelect( myself()->_getMysql(''), 't_staking', @@ -16,7 +23,154 @@ class Staking extends BaseModel { 'address' => $address ) ); - return $rows; + 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; + } + return true; } } diff --git a/webapp/mt/Staking.php b/webapp/mt/Staking.php new file mode 100644 index 00000000..85d9f74b --- /dev/null +++ b/webapp/mt/Staking.php @@ -0,0 +1,24 @@ + 'MarketPriceUpdateOrderOk', 'inappPurchase' => 'InAppPurchase', 'outappPurchase' => 'OutAppPurchase', + 'staked721' => 'Staked721', + 'redeem721' => 'Redeem721', ); public function dispatch($action) diff --git a/webapp/services/callback/Redeem721.php b/webapp/services/callback/Redeem721.php new file mode 100644 index 00000000..cc02843f --- /dev/null +++ b/webapp/services/callback/Redeem721.php @@ -0,0 +1,35 @@ +_rspOk(); + } + +} diff --git a/webapp/services/callback/Staked721.php b/webapp/services/callback/Staked721.php new file mode 100644 index 00000000..cfd5b7fe --- /dev/null +++ b/webapp/services/callback/Staked721.php @@ -0,0 +1,33 @@ +_rspOk(); + } + +}