From e793f51aa28c00b52b3415e8c40586d4952e4105 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 28 Mar 2022 13:47:57 +0800 Subject: [PATCH] 1 --- doc/Wallet.py | 3 + sql/marketdb.sql | 18 +++--- webapp/controller/WalletController.class.php | 64 +++++++++++++++++++- webapp/models/Transfer.php | 25 ++++++++ webapp/models/Withdrawal.php | 55 +++++++++++++++++ 5 files changed, 156 insertions(+), 9 deletions(-) create mode 100644 webapp/models/Transfer.php create mode 100644 webapp/models/Withdrawal.php diff --git a/doc/Wallet.py b/doc/Wallet.py index 685551a2..4681b52b 100644 --- a/doc/Wallet.py +++ b/doc/Wallet.py @@ -16,6 +16,7 @@ class Wallet(object): ['token', '', 'token'], ['type', 0, '货币类型 1:金币 2:钻石'], ['amount', '', '金额'], + ['net_id', '', '网络id'], ], 'response': [ _common.RspHead(), @@ -31,6 +32,7 @@ class Wallet(object): ['account', 0, '钱包账号'], ['token', '', 'token'], ['seq_id', 0, '提现序号'], + ['net_id', '', '网络id'], ], 'response': [ _common.RspHead(errcode='当errcode!=0的时候客户端不需要再调用(停止定时器)'), @@ -46,6 +48,7 @@ class Wallet(object): ['account', 0, '钱包账号'], ['token', '', 'token'], ['txhash', 0, 'hash值'], + ['net_id', '', '网络id'], ], 'response': [ _common.RspHead(), diff --git a/sql/marketdb.sql b/sql/marketdb.sql index bbd8e911..a9edff1a 100644 --- a/sql/marketdb.sql +++ b/sql/marketdb.sql @@ -132,7 +132,6 @@ DROP TABLE IF EXISTS `t_withdrawal`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `t_withdrawal` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', - `trans_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'trans_id', `account` varchar(255) NOT NULL DEFAULT '' COMMENT 'account', `type` int(11) NOT NULL DEFAULT '0' COMMENT 'type', `net_id` int(11) NOT NULL DEFAULT '0' COMMENT 'net_id', @@ -144,29 +143,32 @@ CREATE TABLE `t_withdrawal` ( `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), - UNIQUE KEY `trans_id` (`trans_id`), UNIQUE KEY `bc_txhash` (`bc_txhash`), KEY `account` (`account`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; -- --- Table structure for table `t_recharge` +-- Table structure for table `t_transfer` -- -DROP TABLE IF EXISTS `t_recharge`; +DROP TABLE IF EXISTS `t_transfer`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!40101 SET character_set_client = utf8 */; -CREATE TABLE `t_recharge` ( +CREATE TABLE `t_transfer` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `txhash` varchar(255) NOT NULL DEFAULT '' COMMENT 'txhash', - `account` varchar(255) NOT NULL DEFAULT '' COMMENT 'account', - `amount` bigint NOT NULL DEFAULT '0' COMMENT 'amount', + `type` int(11) NOT NULL DEFAULT '0' COMMENT 'type', + `_from` varchar(255) NOT NULL DEFAULT '' COMMENT '_from', + `_to` varchar(255) NOT NULL DEFAULT '' COMMENT '_to', + `value` bigint NOT NULL DEFAULT '0' COMMENT 'value', + `state` int(11) NOT NULL DEFAULT '0' COMMENT '0:未同步 1:同步成功', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), UNIQUE KEY `txhash` (`txhash`), - KEY `account` (`account`), + KEY `_from` (`_from`), + KEY `_to` (`_to`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/webapp/controller/WalletController.class.php b/webapp/controller/WalletController.class.php index 2d64508d..5304de67 100644 --- a/webapp/controller/WalletController.class.php +++ b/webapp/controller/WalletController.class.php @@ -6,11 +6,15 @@ require_once('mt/Hero.php'); require_once('mt/Parameter.php'); require_once('models/Nft.php'); +require_once('models/Withdrawal.php'); +require_once('models/Transfer.php'); require_once('phpcommon/bchelper.php'); use phpcommon\SqlHelper; use models\Nft; +use models\Withdrawal; +use models\Transfer; class WalletController extends BaseController { @@ -21,17 +25,75 @@ class WalletController extends BaseController { public function withdrawal() { + $account = strtolower(getReqVal('account', '')); + $token = getReqVal('token', ''); + $type = getReqVal('type', ''); + $netId = getReqVal('net_id', ''); + $amount = getReqVal('amount', ''); + $times = Withdrawal::getTodayWithdrawalTimes($account); + if ($times) { + myself()->_rspErr(1, 'More withdrawals than today'); + return; + } + $seqId = Withdrawal::add($account, $type, $netId, $amount); + myself()->_rspData(array( + 'seq_id' => $seqId + )); + if ($this->isTestMode()) { + } } public function queryWithdrawalResult() { - + $account = strtolower(getReqVal('account', '')); + $seqId = getReqVal('seq_id', ''); + $row = Withdrawal::find($seqId); + if (!$row || $row['account'] != $account) { + myself()->_rspErr(0, 'not found'); + return; + } + if ($row['state'] == 2) { + myself()->_rspErr(2, 'processing'); + return; + } + if ($row['state'] == 3) { + myself()->_rspErr(3, 'failed'); + return; + } + $transferDb = Transfer::find($row['bc_txhash']); + if (!$transferDb) { + myself()->_rspErr(2, 'processing'); + return; + } + if ($transferDb['state'] == 0) { + myself()->_rspErr(2, 'processing'); + return; + } else { + myself()->_rspErr(1, 'processing'); + return; + } } public function queryRechargeResult() { + $account = strtolower(getReqVal('account', '')); + $txHash = getReqVal('txhash', ''); + if ($this->isTestMode()) { + } + $transferDb = Transfer::find($txHash); + if (!$transferDb) { + myself()->_rspErr(2, 'processing'); + return; + } + if ($transferDb['state'] == 0) { + myself()->_rspErr(2, 'processing'); + return; + } else { + myself()->_rspErr(1, 'processing'); + return; + } } } diff --git a/webapp/models/Transfer.php b/webapp/models/Transfer.php new file mode 100644 index 00000000..c8eceef3 --- /dev/null +++ b/webapp/models/Transfer.php @@ -0,0 +1,25 @@ +_getSelfMysql(), + 't_transfer', + array( + 'txhash' => $txHash, + ) + ); + return $row; + } + +} diff --git a/webapp/models/Withdrawal.php b/webapp/models/Withdrawal.php new file mode 100644 index 00000000..5bb6316b --- /dev/null +++ b/webapp/models/Withdrawal.php @@ -0,0 +1,55 @@ +_getMarketMysql()->execQueryOne( + 'SELECT COUNT(1) AS times FROM t_withdrawal WHERE account=:account AND createtime>=:now_dayseconds AND createtime:<=:now_dayseconds + 3600 * 24;', + array( + ':account' => $account, + ':now_dayseconds' => myself()->_getNowDaySeconds() + ) + ); + return $row ? $row['times'] : 0; + } + + public static function add($account, $type, $netId, $amount) + { + SqlHelper::insert + (myself()->_getMarketMysql(), + 't_withdrawal', + array( + 'account' => $account, + 'type' => $type, + 'net_id' => $netId, + 'amount' => $amount, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + $seqId = SqlHelper::getLastInsertId(myself()->_getMarketMysql()); + return $seqId; + } + + public static function get($seqId) + { + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_withdrawal', + array( + 'idx' => $seqId, + ) + ); + return $row; + } + +}