diff --git a/doc/BlockChain.py b/doc/BlockChain.py index cfa4ad37..213cbe01 100644 --- a/doc/BlockChain.py +++ b/doc/BlockChain.py @@ -46,20 +46,6 @@ class BlockChain(object): ['!params', [''], '合约参数列表'], ] }, - { - 'name': 'active1155Nft', - 'desc': '激活721nft', - 'group': 'BlockChain', - 'url': 'webapp/index.php?c=BlockChain&a=active1155Nft', - 'params': [ - ['uniid', '', '芯片唯一id'], - ], - 'response': [ - _common.RspHead(), - ['trans_id', '', '事务id'], - ['!params', [''], '合约参数列表'], - ] - }, { 'name': 'evolve721Nft', 'desc': 'nft进阶(英雄,武器)', @@ -97,7 +83,8 @@ class BlockChain(object): 'group': 'BlockChain', 'url': 'webapp/index.php?c=BlockChain&a=mintShardBatchUser', 'params': [ - ['ids', 0, 'tokenid1'], + ['item_uniid', 0, '道具唯一id'], + ['num', 0, '使用数量'], ], 'response': [ _common.RspHead(), diff --git a/webapp/controller/BagController.class.php b/webapp/controller/BagController.class.php index 9b525a74..1765fb3c 100644 --- a/webapp/controller/BagController.class.php +++ b/webapp/controller/BagController.class.php @@ -334,6 +334,8 @@ class BagController extends BaseAuthedController { } private function openFragmentBox($itemDb, $itemMeta, $itemNum){ + $this->_rspOk(); + /* if ($itemDb['item_num']<$itemNum){ $this->_rspErr(1, "The shard chest is insufficient"); return; @@ -348,7 +350,7 @@ class BagController extends BaseAuthedController { $this->propertyChgService->addBagChg(); $this->_rspData(array( 'property_chg' => $this->propertyChgService->toDto(), - )); + ));*/ } } diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 10ffb5d3..91e30904 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -101,11 +101,6 @@ class BlockChainController extends BaseAuthedController { } } - public function active1155Nft() - { - - } - public function reportResult() { $transId = getReqVal('trans_id', ''); @@ -126,7 +121,32 @@ class BlockChainController extends BaseAuthedController { public function mintShardBatchUser() { + $itemUniId = getReqVal('item_uniid', 0); + $num = getReqVal('num', 0); + $itemDb = Bag::findByUniId($itemUniId); + if (!$itemDb || $itemDb['item_num'] < $num) { + myself()->_rspErr(1, 'item not enough'); + return; + } + $itemMeta = mt\Item::get($itemDb['item_id']); + switch ($itemMeta['type']) { + case mt\Item::FRAGMENT_BOX_TYPE: + { + $this->internalOpenChipBox($itemDb); + } + break; + case mt\Item::CHIP_BOX_TYPE: + { + } + break; + default: + { + myself()->_rspErr(1, 'item type error'); + return; + } + break; + } } public function shardMixByUser() @@ -181,6 +201,98 @@ class BlockChainController extends BaseAuthedController { } } + private function internalOpenChipBox($itemDb) { + $params = array( + 'c' => 'BcService', + 'a' => 'activate1155Nft', + 'account_id' => myself()->_getAccountId(), + 'session_id' => myself()->_getSessionId(), + 'account' => myself()->_getOpenId(), + 'token_id' => $tokenId, + 'token_type' => $tokenType, + 'item_uniid' => $itemUniId, + 'item_id' => $itemId + ); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + error_log($response); + $rspObj = json_decode($response, true); + if ($rspObj['errcode'] == 0) { + $transId = $rspObj['trans_id']; + Transaction::add( + $transId, + Transaction::MINT_721_ACTION_TYPE, + $tokenId, + $tokenType, + $itemUniId, + $itemId + ); + myself()->_rspData(array( + 'trans_id' => $transId, + 'params' => $rspObj['params'] + )); + } else { + myself()->_rspErr(500, 'server internal error'); + return; + } + } + } + + private function internalOpenFragmentBox($itemDb) { + $params = array( + 'c' => 'BcService', + 'a' => 'mintShardBatchUser', + 'account_id' => myself()->_getAccountId(), + 'session_id' => myself()->_getSessionId(), + 'account' => myself()->_getOpenId(), + 'token_id' => $tokenId, + 'token_type' => $tokenType, + 'item_uniid' => $itemUniId, + 'item_id' => $itemId + ); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + error_log($response); + $rspObj = json_decode($response, true); + if ($rspObj['errcode'] == 0) { + $transId = $rspObj['trans_id']; + Transaction::add( + $transId, + Transaction::MINT_721_ACTION_TYPE, + $tokenId, + $tokenType, + $itemUniId, + $itemId + ); + myself()->_rspData(array( + 'trans_id' => $transId, + 'params' => $rspObj['params'] + )); + } else { + myself()->_rspErr(500, 'server internal error'); + return; + } + } + } + private static function getWeb3ServiceUrl() { if (SERVER_ENV == _TEST) { diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index 896dc1b2..0247fad7 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -92,6 +92,7 @@ class Item { const CHIP_TYPE = 13; const FRAGMENT_BOX_TYPE = 15; const PARACHUTE_TYPE = 16; + const CHIP_BOX_TYPE = 17; const RING_TYPE = 19; const FUNC_RENAME_CARD_SUBTYPE = 1;