From 015a2a7f54e34f54a67b947a97c63d0e5329b18f Mon Sep 17 00:00:00 2001 From: hujiabin Date: Mon, 12 Dec 2022 10:48:48 +0800 Subject: [PATCH] add Currency --- doc/Currency.py | 37 ++++ doc/_common.py | 12 ++ sql/gamedb.sql | 23 +++ .../controller/CurrencyController.class.php | 47 +++++ webapp/models/Currency.php | 162 ++++++++++++++++++ 5 files changed, 281 insertions(+) create mode 100644 doc/Currency.py create mode 100644 webapp/controller/CurrencyController.class.php create mode 100644 webapp/models/Currency.php diff --git a/doc/Currency.py b/doc/Currency.py new file mode 100644 index 00000000..bf5042e6 --- /dev/null +++ b/doc/Currency.py @@ -0,0 +1,37 @@ + +import _common + +class Currency(object): + + def __init__(self): + self.apis = [ + { + 'name': 'addCurrency', + 'desc': '添加货币地址', + 'group': 'Currency', + 'url': 'webapp/index.php?c=Currency&a=addCurrency', + 'params': [ + _common.ReqHead(), + ['net_id', 0, '链id'], + ['address', '', '货币地址'], + ['symbol', '', '符号'], + ['precision', 0, '精度'], + ['type', 0, '1:ERC721 2:ERC1155 3:ERC20'], + ], + 'response': [ + _common.RspHead(), + ] + },{ + 'name': 'currencyList', + 'desc': '列表', + 'group': 'Currency', + 'url': 'webapp/index.php?c=Currency&a=currencyList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['!list', [_common.Currency()], '列表信息'], + ] + }, + ] \ No newline at end of file diff --git a/doc/_common.py b/doc/_common.py index dc6ba631..e38c0f55 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1001,3 +1001,15 @@ class EventRankingList(object): ['endTime', '', '结束时间'], ['status', 0, '0:已结束 1:进行中 2:等待中'], ] + +class Currency(object): + + def __init__(self): + self.fields = [ + ['account_id', '', 'account_id'], + ['net_id', 0, '链id'], + ['address', '', '货币地址'], + ['symbol', '', '符号'], + ['precision', 0, '精度'], + ['type', 0, '1:ERC721 2:ERC1155 3:ERC20'], + ] \ No newline at end of file diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 8209a8c9..fd809c41 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -896,3 +896,26 @@ CREATE TABLE `t_event_ranking` ( KEY `value` (`value`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; + + +-- +-- Table structure for table `t_user_currency` +-- + +DROP TABLE IF EXISTS `t_user_currency`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_user_currency` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id', + `net_id` int(11) NOT NULL DEFAULT '0' COMMENT '链id', + `address` varchar(60) NOT NULL DEFAULT '' COMMENT '货币地址', + `symbol` varchar(10) NOT NULL DEFAULT '' COMMENT '符号', + `precision` int(11) NOT NULL DEFAULT '0' COMMENT '精度', + `type` int(11) NOT NULL DEFAULT '0' COMMENT '类型 1:ERC721 2:ERC1155 3:ERC20', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `account_net_address` (`account_id`, `net_id`, `address`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; \ No newline at end of file diff --git a/webapp/controller/CurrencyController.class.php b/webapp/controller/CurrencyController.class.php new file mode 100644 index 00000000..d3fac0b9 --- /dev/null +++ b/webapp/controller/CurrencyController.class.php @@ -0,0 +1,47 @@ +_getAccountId(); + $netId = getReqVal('net_id', 0); + $address = getReqVal('address', 0); + $symbol = getReqVal('symbol', 0); + $precision = getReqVal('precision', 0); + $type = getReqVal('type', 0); + if ( ! $netId){ + $this->_rspErr(1,'param netId error'); + return; + }elseif( ! $address){ + $this->_rspErr(1,'param address error'); + return; + }elseif( ! $symbol){ + $this->_rspErr(1,'param symbol error'); + return; + }elseif( ! $precision){ + $this->_rspErr(1,'param precision error'); + return; + }elseif( ! $type){ + $this->_rspErr(1,'param type error'); + return; + } + Currency::addCurrency(array( + 'net_id' => $netId, + 'address' => $address, + 'symbol' => $symbol, + 'precision' => $precision, + 'type' => $type, + )); + $this->_rspOk(); + } + + public function currencyList(){ + $list = Currency::getCurrencyList(); + $this->_rspData(array( + 'list'=>$list + )); + } +} \ No newline at end of file diff --git a/webapp/models/Currency.php b/webapp/models/Currency.php new file mode 100644 index 00000000..a564d4d0 --- /dev/null +++ b/webapp/models/Currency.php @@ -0,0 +1,162 @@ +_getSelfMysql(), + 't_user_currency', + array( + 'account_id'=>myself()->_getAccountId() + ) + ); + if ($rows){ + $list = array_merge($baseList,$rows); + }else{ + $list = $baseList; + } + return $list; + } + + public static function addCurrency($data){ + if (!$data){ + return; + } + SqlHelper::upsert + (myself()->_getSelfMysql(), + 't_user_currency', + array( + 'account_id' => myself()->_getAccountId(), + 'net_id' => $data['net_id'], + 'address' => $data['address'], + ), + array( + ), + array( + 'account_id' => myself()->_getAccountId(), + 'net_id' => $data['net_id'], + 'address' => $data['address'], + 'symbol' => $data['symbol'], + 'precision' => $data['precision'], + 'type' => $data['type'], + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + + ) + ); + } + + + private static function baseCurrency(){ + if (SERVER_ENV == _ONLINE) { + return array( + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>80001, + 'address'=>'0xfa513999031dC1DCf86e99d91101e17d07839235', + 'symbol'=>'CEC', + 'precision'=>18, + 'type'=>3, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>80001, + 'address'=>'0x9f87eCA8F0479383fF11a5AB2336b5A6c383d6F3', + 'symbol'=>'CEG', + 'precision'=>18, + 'type'=>3, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>80001, + 'address'=>'0x3EBF5196dADC8F3F09C808333f98FE8A4b7d1e62', + 'symbol'=>'hero', + 'precision'=>18, + 'type'=>1, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>80001, + 'address'=>'0x2F2Ed1c403cB7156617449795dE1CB47A0302a25', + 'symbol'=>'weapon', + 'precision'=>18, + 'type'=>1, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>80001, + 'address'=>'0x73482411443E87CAC124C12A10B34e9Aaa2De168', + 'symbol'=>'chip', + 'precision'=>18, + 'type'=>2, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>80001, + 'address'=>'0xFc21A863bFb4E4534B246078772e2074e076f0a7', + 'symbol'=>'shard', + 'precision'=>18, + 'type'=>2, + ), + ); + }else{ + return array( + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>1338, + 'address'=>'0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7', + 'symbol'=>'CEC', + 'precision'=>18, + 'type'=>3, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>1338, + 'address'=>'0x59d3631c86BbE35EF041872d502F218A39FBa150', + 'symbol'=>'CEG', + 'precision'=>18, + 'type'=>3, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>1338, + 'address'=>'0x9b1f7F645351AF3631a656421eD2e40f2802E6c0', + 'symbol'=>'hero', + 'precision'=>18, + 'type'=>1, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>1338, + 'address'=>'0x2612Af3A521c2df9EAF28422Ca335b04AdF3ac66', + 'symbol'=>'weapon', + 'precision'=>18, + 'type'=>1, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>1338, + 'address'=>'0x26b4AFb60d6C903165150C6F0AA14F8016bE4aec', + 'symbol'=>'chip', + 'precision'=>18, + 'type'=>2, + ), + array( + 'account_id'=> myself()->_getAccountId(), + 'net_id'=>1338, + 'address'=>'0x0E696947A06550DEf604e82C26fd9E493e576337', + 'symbol'=>'shard', + 'precision'=>18, + 'type'=>2, + ), + ); + } + } +} \ No newline at end of file