From c1c32f4d4c12281c3b1d467f3266e55d6e0a6d25 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 9 Apr 2022 14:35:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0nft=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=92=8C=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Market.py | 6 +- doc/_common.py | 26 ++---- sql/marketdb.sql | 11 ++- third_party/phpcommon | 2 +- webapp/controller/MarketController.class.php | 87 ++++++++++--------- webapp/controller/RestApiController.class.php | 21 +---- webapp/models/Nft.php | 68 ++++++++++++++- 7 files changed, 135 insertions(+), 86 deletions(-) diff --git a/doc/Market.py b/doc/Market.py index 57c3860e..fe3294bd 100644 --- a/doc/Market.py +++ b/doc/Market.py @@ -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(), ] }, ] diff --git a/doc/_common.py b/doc/_common.py index 446bc3d1..90342651 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -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, '成功率'], - ] diff --git a/sql/marketdb.sql b/sql/marketdb.sql index 92804439..17113537 100644 --- a/sql/marketdb.sql +++ b/sql/marketdb.sql @@ -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', diff --git a/third_party/phpcommon b/third_party/phpcommon index d1e7d7e5..adec769a 160000 --- a/third_party/phpcommon +++ b/third_party/phpcommon @@ -1 +1 @@ -Subproject commit d1e7d7e56b59cf6b75ab727a04c1f223cae1cbbd +Subproject commit adec769a954ebfeaf4250fcd1499f6aabd793688 diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index e8090b95..93a959df 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -269,18 +269,58 @@ class MarketController extends BaseController { { $account = strtolower(getReqVal('account', '')); $token = getReqVal('token', ''); - if (!MarketService::isValidToken($account, $token)) { - myself()->_rspErr(100, 'invalid token'); - return; + $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); - array_push($nftList, $nft); + $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', '')); diff --git a/webapp/controller/RestApiController.class.php b/webapp/controller/RestApiController.class.php index f1bb0018..bce10f41 100644 --- a/webapp/controller/RestApiController.class.php +++ b/webapp/controller/RestApiController.class.php @@ -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); } diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index 3f945e98..d2d4f4b2 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -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; + } + }