添加nft详情和分页功能

This commit is contained in:
aozhiwei 2022-04-09 14:35:59 +08:00
parent 28768f302b
commit c1c32f4d4c
7 changed files with 135 additions and 86 deletions

View File

@ -128,10 +128,14 @@ class Market(object):
'params': [
['account', '', '账号id'],
['token', '', 'token'],
['page', 0, '获取第几页数据'],
['type', '', 'nft类型 1:英雄 2:枪支 3:芯片 [可选]如果不传则所有'],
['state', '', '0:正常状态 1:出售中 2:出租中 [可选]如果不传则所有'],
],
'response': [
_common.RspHead(),
['!nfts', [_common.NftDetail()], 'nft列表'],
['page', _common.Page(), '分页信息'],
]
},
{
@ -159,7 +163,7 @@ class Market(object):
],
'response': [
_common.RspHead(),
_common.InfoNft()
_common.NftDetail(),
]
},
]

View File

@ -41,6 +41,7 @@ class AttrDesc(object):
def __init__(self):
self.fields = [
['name', '', '属性名'],
['attr_id', 0, '属性id'],
['type', 0, '1: 绝对值 2百分比'],
['val', 0, '属性值'],
@ -479,6 +480,7 @@ class NftHeroDetail(object):
['advanced_count', 0, '升级次数'],
['lukcy', 0, '幸运'],
['success_rate', 0, '成功率'],
['!attr', [AttrDesc()], '属性'],
]
class NftGunDetail(object):
@ -486,6 +488,8 @@ class NftGunDetail(object):
def __init__(self):
self.fields = [
['name', '', '枪支名'],
['level', 0, '等级'],
['quality', 0, '星级'],
['!attr', [AttrDesc()], '属性'],
]
@ -513,6 +517,9 @@ class NftDetail(object):
['owner_address', '', '所有者地址'],
['owner_name', '', '所有名字'],
['item_id', 0, '道具id'],
['type', '', 'nft类型 1:英雄 2:枪支 3:芯片'],
['image', '', 'nft图片地址'],
['state', 0, '0:正常状态 1:出售中 2:出租中'],
['info', Union([
[NftHeroDetail(), '英雄'],
[NftGunDetail(), '枪支'],
@ -522,22 +529,3 @@ class NftDetail(object):
['!currency_list', [SystemCurrency()], '货币列表,(目前有且只有一个)'],
['mint_time', 0, '铸造时间'],
]
class InfoNft(object):
def __init__(self):
self.fields = [
['name', '', 'nft名字'],
['description', '', 'nft描述'],
['image', '', 'nft图片地址'],
['job', '', '职业'],
['level', 0, '等级'],
['quality', 0, '星级'],
['hp', 0, '血量'],
['speed', 0, '速度'],
['atk', 0, '攻击'],
['def', 0, '防御'],
['advanced_count', 0, '升级次数'],
['lukcy', 0, '幸运'],
['success_rate', 0, '成功率'],
]

View File

@ -68,7 +68,7 @@ CREATE TABLE `t_box_order` (
`bc_mint_tokenid1` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id',
`bc_mint_need1` int(11) NOT NULL DEFAULT '0' COMMENT 'need',
`bc_mint_itemid1` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
`bc_mint_token_type1` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 0:英雄 1:枪支 2:芯片',
`bc_mint_token_type1` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片',
`bc_mint_count1` int(11) NOT NULL DEFAULT '0' COMMENT '生成nft次数',
`bc_mint_time1` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次生成nft时间',
`bc_mint_prepare_block_number1` varchar(60) NOT NULL DEFAULT '' COMMENT 'nft生成准备前块id',
@ -79,7 +79,7 @@ CREATE TABLE `t_box_order` (
`bc_mint_tokenid2` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id',
`bc_mint_need2` int(11) NOT NULL DEFAULT '0' COMMENT 'need',
`bc_mint_itemid2` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
`bc_mint_token_type2` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 0:英雄 1:枪支 2:芯片',
`bc_mint_token_type2` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片',
`bc_mint_count2` int(11) NOT NULL DEFAULT '0' COMMENT '生成nft次数',
`bc_mint_time2` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次生成nft时间',
`bc_mint_prepare_block_number2` varchar(60) NOT NULL DEFAULT '' COMMENT 'nft生成准备前块id',
@ -90,7 +90,7 @@ CREATE TABLE `t_box_order` (
`bc_mint_tokenid3` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id',
`bc_mint_need3` int(11) NOT NULL DEFAULT '0' COMMENT 'need',
`bc_mint_itemid3` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
`bc_mint_token_type3` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 0:英雄 1:枪支 2:芯片',
`bc_mint_token_type3` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片',
`bc_mint_count3` int(11) NOT NULL DEFAULT '0' COMMENT '生成nft次数',
`bc_mint_time3` int(11) NOT NULL DEFAULT '0' COMMENT '最后一次生成nft时间',
`bc_mint_prepare_block_number3` varchar(60) NOT NULL DEFAULT '' COMMENT 'nft生成准备前块id',
@ -120,7 +120,10 @@ DROP TABLE IF EXISTS `t_nft`;
CREATE TABLE `t_nft` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id',
`token_type` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 0:英雄 1:枪支 2:芯片',
`token_type` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片',
`game_id` int(11) NOT NULL DEFAULT '0' COMMENT 'game id',
`token_state` int(11) NOT NULL DEFAULT '0' COMMENT '0:正常状态 1:出售中 2:出租中',
`token_state` NOT NULL DEFAULT '' COMMENT '0:正常状态 1:出售中 2:出租中',
`game_id` int(11) NOT NULL DEFAULT '0' COMMENT 'game id',
`item_id` int(11) NOT NULL DEFAULT '0' COMMENT '道具id',
`owner_address` varchar(255) NOT NULL DEFAULT '' COMMENT 'owner_address',

@ -1 +1 @@
Subproject commit d1e7d7e56b59cf6b75ab727a04c1f223cae1cbbd
Subproject commit adec769a954ebfeaf4250fcd1499f6aabd793688

View File

@ -269,18 +269,58 @@ class MarketController extends BaseController {
{
$account = strtolower(getReqVal('account', ''));
$token = getReqVal('token', '');
$page = getReqVal('page', 0);
if (MarketService::isTestMode()) {
} else {
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(100, 'invalid token');
return;
}
$nftDbList = Nft::getNftList($account);
}
$nftDbList = array();
$pagination = array();
SqlHelper::rawQueryPage(
myself()->_getMarketMysql(),
'SELECT * FROM t_nft WHERE owner_address=:owner_address',
array(
':owner_address' => $account
),
array(
'page' => $page,
'perPage' => 2,
'filter' => array(
'data' => $_REQUEST,
'fields' => array(
array(
'name' => 'type',
'field_name' => 'token_type',
'cond' => '=',
'ignore_empty' => true
),
array(
'name' => 'state',
'field_name' => 'token_state',
'cond' => '=',
'ignore_empty' => true
),
)
),
'handle' => function ($row) use(&$nftDbList) {
array_push($nftDbList, $row);
}
),
$pagination
);
$nftList = array();
foreach ($nftDbList as $nftDb) {
$nft = $this->toNftDto($nftDb);
$nft = Nft::toDto($nftDb);
if ($nft) {
array_push($nftList, $nft);
}
}
myself()->_rspData(array(
'nfts' => $nftList
'nfts' => $nftList,
'page' => $pagination
));
}
@ -299,43 +339,12 @@ class MarketController extends BaseController {
myself()->_rspErr(1, 'nft not exists');
return;
}
$nft = $this->toNftDto($nftDb);
$nft = Nft::toDto($nftDb);
myself()->_rspData(array(
'info' => $nft
));
}
private function toNftDto($nftDb)
{
$nft = array(
'token_id' => $nftDb['token_id'],
'owner_address' => $nftDb['owner_address'],
//'owner_name' => $nftDb['owner_name'],
'owner_name' => '',
'item_id' => $nftDb['item_id'],
'currency_list' => array(),
'transaction_recrod' => array(),
'info' => array(
),
'mint_time' => $nftDb['createtime']
);
$heroMeta = mt\Hero::get($nftDb['item_id']);
if ($heroMeta) {
$nft['info']['name'] = $heroMeta['name'];
$nft['info']['job'] = $heroMeta['herotype'];
$nft['info']['level'] = 1;
$nft['info']['quality'] = 1;
$nft['info']['hp'] = $heroMeta['hp'];
$nft['info']['speed'] = $heroMeta['move_speed'];
$nft['info']['atk'] = $heroMeta['damage'];
$nft['info']['def'] = $heroMeta['defence'];
$nft['info']['advanced_count'] = 0;
$nft['info']['lucky'] = 0;
$nft['info']['success_rate'] = 0;
}
return $nft;
}
public function getNonce()
{
$account = strtolower(getReqVal('account', ''));

View File

@ -57,26 +57,11 @@ class RestApiController extends BaseController {
myself()->_rspErr(1, 'nft not found');
return;
}
$heroMeta = mt\Hero::get($nftDb['item_id']);
if (!$heroMeta) {
myself()->_rspErr(2, 'server internal error');
$nftDto = Nft::toDto($nftDb);
if (!$nftDto) {
myself()->_rspErr(1, 'nft not found');
return;
}
$nftDto = array();
$nftDto['name'] = $heroMeta['name'];
$nftDto['description'] = '';
$nftDto['image'] = 'https://www.cebg.games/res/nft/' . $nftDb['item_id'] . '.png';
$nftDto['job'] = $heroMeta['herotype'];
$nftDto['level'] = 1;
$nftDto['quality'] = 1;
$nftDto['hp'] = $heroMeta['hp'];
$nftDto['speed'] = $heroMeta['move_speed5'];
$nftDto['atk'] = $heroMeta['damage'];
$nftDto['def'] = $heroMeta['defence'];
$nftDto['advanced_count'] = 0;
$nftDto['lucky'] = 0;
$nftDto['success_rate'] = 0;
myself()->_rspData($nftDto);
}

View File

@ -9,10 +9,10 @@ use phpcommon\SqlHelper;
class Nft extends BaseModel {
const NONE_TYPE = -1;
const HERO_TYPE = 0;
const EQUIP_TYPE = 1;
const CHIP_TYPE = 2;
const NONE_TYPE = 0;
const HERO_TYPE = 1;
const EQUIP_TYPE = 2;
const CHIP_TYPE = 3;
public static function getTokenType($itemMeta)
{
@ -83,4 +83,64 @@ class Nft extends BaseModel {
return $row;
}
public static function toDto($nftDb)
{
$itemMeta = mt\Item::get($nftDb['item_id']);
if (!$itemMeta){
return null;
}
$nft = array(
'token_id' => $nftDb['token_id'],
'owner_address' => $nftDb['owner_address'],
'owner_name' => '',
'item_id' => $nftDb['item_id'],
'type' => $nftDb['token_type'],
'state' => $nftDb['token_state'],
'image' => 'https://www.cebg.games/res/avatars/' . $itemMeta['id'] . '.png',
'currency_list' => array(),
'transaction_recrod' => array(),
'info' => array(
'name' => $itemMeta['name'],
'attr' => array()
),
'mint_time' => $nftDb['createtime']
);
switch ($nftDb['token_type']) {
case Nft::HERO_TYPE:
{
$heroMeta = mt\Hero::get($nftDb['item_id']);
if ($heroMeta) {
//$nft['info']['name'] = $heroMeta['name'];
$nft['info']['job'] = $heroMeta['herotype'];
$nft['info']['level'] = 1;
$nft['info']['quality'] = 1;
$nft['info']['hp'] = $heroMeta['hp'];
$nft['info']['speed'] = $heroMeta['move_speed'];
$nft['info']['atk'] = $heroMeta['damage'];
$nft['info']['def'] = $heroMeta['defence'];
$nft['info']['advanced_count'] = 0;
$nft['info']['lucky'] = 0;
$nft['info']['success_rate'] = 0;
}
}
break;
case Nft::EQUIP_TYPE:
{
$nft['info']['level'] = 1;
$nft['info']['quality'] = 1;
}
break;
case Nft::CHIP_TYPE:
{
}
break;
default:
{
return null;
}
}
return $nft;
}
}