From 0db0f994baff1b8e0ca4220b4d5a649eddfb7174 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 7 Jun 2023 15:48:19 +0800 Subject: [PATCH] 1 --- doc/BlockChain.py | 12 +-- sql/gamedb.sql | 2 + sql/migrate_230607_01.sql | 8 ++ .../controller/BlockChainController.class.php | 76 +++++++++++++++++++ 4 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 sql/migrate_230607_01.sql diff --git a/doc/BlockChain.py b/doc/BlockChain.py index 45c6cf0d..610fe762 100644 --- a/doc/BlockChain.py +++ b/doc/BlockChain.py @@ -59,18 +59,18 @@ class BlockChain(object): ] }, { - 'name': 'mint', - 'desc': '激活nft', + 'name': 'active721Nft', + 'desc': '激活721nft', 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=mint', + 'url': 'webapp/index.php?c=BlockChain&a=active721Nft', 'params': [ - ['item_id', '', '指定的英雄id或者武器id'], - ['token_ids', '', 'token_ids多个用|分割'], + ['type', 0, '1:英雄 2:枪械 3:芯片'], + ['uniid', '', '唯一id'], ], 'response': [ _common.RspHead(), ['trans_id', '', '事务id'], ['!params', [''], '合约参数列表'], ] - } + }, ] diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 452409bf..17f240c7 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -246,6 +246,8 @@ CREATE TABLE `t_chip` ( `state` int(11) NOT NULL DEFAULT '0' COMMENT '0:已购买 1:免费(GIFT标签)', `inlay_state` varchar(60) COMMENT '所镶嵌的芯片页id:1|2|3', `rand_attr` mediumblob COMMENT '随机属性', + `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id', + `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count', `activate` int(11) NOT NULL DEFAULT '0' COMMENT '是否激活 1:已初始激活', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', diff --git a/sql/migrate_230607_01.sql b/sql/migrate_230607_01.sql new file mode 100644 index 00000000..27e7e468 --- /dev/null +++ b/sql/migrate_230607_01.sql @@ -0,0 +1,8 @@ +begin; + +alter table t_chip add column `active_token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'active_token_id'; +alter table t_chip add column `active_count` int(11) NOT NULL DEFAULT '0' COMMENT 'active_count'; + +insert into version (version) values(2023060701); + +commit; diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index ee5995d0..e7ecad32 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -112,6 +112,82 @@ class BlockChainController extends BaseAuthedController { )); } + public function active721Nft() + { + $type = getReqVal('type', 0); + $uniid = getReqVal('uniid', 0); + switch ($type) { + case 1: + { + $heroDb = Hero::find($uniid); + if (!$heroDb) { + myself()->_rspErr(1, 'hero not found'); + return; + } + if ($heroDb['token_id']) { + myself()->_rspErr(1, 'already activated'); + return; + } + $tokenId = $heroDb['active_token_id']; + if (!$tokenId) { + $tokenId = BuyRecord::genOrderId + ( + 2006, + phpcommon\BC_FUNC_CREATION, + myself()->_getNowTime(), + myself()->_getOpenId() + ); + Hero::Update($heroDb['hero_uniid'], + array( + 'active_token_id' => $tokenId, + 'active_count' => function () { + return 'active_count + 1'; + } + )); + } + $this->internalActivate721Nft($tokenId, Nft::HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id']); + } + break; + case 2: + { + $gunDb = Gun::find($uniid); + if (!$gunDb) { + myself()->_rspErr(1, 'gun not found'); + return; + } + if ($gunDb['token_id']) { + myself()->_rspErr(1, 'already activated'); + return; + } + $tokenId = $gunDb['active_token_id']; + if (!$tokenId) { + $tokenId = BuyRecord::genOrderId + ( + 2006, + phpcommon\BC_FUNC_CREATION, + myself()->_getNowTime(), + myself()->_getOpenId() + ); + Gun::Update($gunDb['gun_uniid'], + array( + 'active_token_id' => $tokenId, + 'active_count' => function () { + return 'active_count + 1'; + } + )); + } + $this->internalActivate721Nft($tokenId, Nft::EQUIP_TYPE, $gunDb['gun_uniid'], $gunDb['gun_id']); + } + break; + default: + { + myself()->_rspErr(1, 'type param error'); + return; + } + break; + } + } + private function internalBcCall($params, $transParams, $cb = null) { $propertyChgService = new services\PropertyChgService(); $propertyChgService->addUserChg();