add Currency
This commit is contained in:
parent
02cf3e43f2
commit
015a2a7f54
37
doc/Currency.py
Normal file
37
doc/Currency.py
Normal file
@ -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()], '列表信息'],
|
||||
]
|
||||
},
|
||||
]
|
@ -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'],
|
||||
]
|
@ -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 */;
|
47
webapp/controller/CurrencyController.class.php
Normal file
47
webapp/controller/CurrencyController.class.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
require_once('models/Currency.php');
|
||||
|
||||
use models\Currency;
|
||||
class CurrencyController extends BaseAuthedController{
|
||||
|
||||
public function addCurrency(){
|
||||
$accountId = myself()->_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
|
||||
));
|
||||
}
|
||||
}
|
162
webapp/models/Currency.php
Normal file
162
webapp/models/Currency.php
Normal file
@ -0,0 +1,162 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace models;
|
||||
|
||||
use mt;
|
||||
use phpcommon\SqlHelper;
|
||||
class Currency extends BaseModel
|
||||
{
|
||||
|
||||
public static function getCurrencyList(){
|
||||
$baseList = self::baseCurrency();
|
||||
$rows = SqlHelper::ormSelect(
|
||||
myself()->_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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user