_getMarketMysql(), 't_nft', array( 'owner_address' => $account, 'deleted' => 0, ), function ($row) use(&$nftList) { if (self::isVisableNft($row)) { array_push($nftList, $row); } } ); return $nftList; } public static function getNftListByType($account, $type) { $nftList = array(); SqlHelper::ormSelect( myself()->_getMarketMysql(), 't_nft', array( 'owner_address' => $account, 'token_type' => $type, ), function ($row) use(&$nftList) { array_push($nftList, $row); } ); return $nftList; } public static function getNft($tokenId) { $row = SqlHelper::ormSelectOne( myself()->_getMarketMysql(), 't_nft', array( 'token_id' => $tokenId, ) ); return $row; } public static function toDto($nftDb) { $itemMeta = mt\Item::get($nftDb['item_id']); if (!$itemMeta){ return null; } $tags = self::parseTags($nftDb['tags']); $image = 'https://www.cebg.games/res/avatars/' . $itemMeta['id'] . '.png'; $full_image = 'https://www.cebg.games/res/avatars/full_' . $itemMeta['id'] . '.png'; if (in_array(self::GENESIS_TAG, $tags)) { $image = 'https://www.cebg.games/res/avatars/' . $itemMeta['id'] . '_1' . '.png'; $full_image = 'https://www.cebg.games/res/avatars/full_' . $itemMeta['id'] . '_1' . '.png'; } if ($nftDb['token_type'] == self::CHIP_TYPE) { $image = 'https://www.cebg.games/res/avatars/' . $itemMeta['id'] . '_a' . '.png'; $full_image = 'https://www.cebg.games/res/avatars/full_' . $itemMeta['id'] . '_a' . '.png'; } $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'], 'lock_time' => 0, 'hide_attr' => 0, 'is_genesis' => in_array(self::GENESIS_TAG, $tags), 'image' => $image, 'full_image' => $full_image, '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'] = $heroMeta['hero_lucky']; $nft['info']['success_rate'] = 0; } } break; case Nft::EQUIP_TYPE: { $equipMeta = mt\Equip::get($itemMeta['relationship']); /*error_log(json_encode(array( 'equpMeta' => $equipMeta, 'nftDb' => $nftDb )));*/ $nft['full_image'] = $nft['image']; $nft['info']['level'] = 1; $nft['info']['quality'] = 1; $nft['info']['lucky'] = $equipMeta ? $equipMeta['gun_lucky'] : 0; $randAttr = array(); if (!is_null($nftDb['rand_attr'])) { $initQualityMeta = mt\GunQuality::getByQuality(1); if ($initQualityMeta) { $randAttr = mt\GunQuality::getRandAttr($initQualityMeta); } SqlHelper::update( myself()->_getMarketMysql(), 't_nft', array( 'token_id' => $nft['token_id'] ), array( 'rand_attr' => json_encode($randAttr) ) ); } { foreach($randAttr as &$attr) { $attrMeta = mt\Attr::get($attr['attr_id']); if ($attrMeta) { $attr['name'] = $attrMeta['attr_ename']; } else { $attr['name'] = ''; } } } { $nft['info']['clip_volume'] = getXVal($equipMeta, 'clip_volume', 0); $nft['info']['reload_time'] = getXVal($equipMeta, 'reload_time', 0); $nft['info']['fire_rate'] = getXVal($equipMeta, 'fire_rate', 0); $nft['info']['atk'] = getXVal($equipMeta, 'atk', 0); $nft['info']['bullet_speed'] = getXVal($equipMeta, 'bullet_speed', 0); $nft['info']['range'] = getXVal($equipMeta, 'range', 0); } $nft['info']['attr'] = $randAttr; } break; case Nft::CHIP_TYPE: { $nft['hide_attr'] = 1; } break; default: { return null; } } return $nft; } public static function toNftView($row, &$nftView) { $itemMeta = mt\Item::get($row['item_id']); if ($itemMeta) { $nftView['name'] = $itemMeta['name']; $nftView['description'] = getXVal($itemMeta, 'nft_desc', $itemMeta['name']); $nftView['image'] = 'https://www.cebg.games/res/nfts/' . $itemMeta['id'] . '.png'; $tags = self::parseTags($row['tags']); if (in_array(self::GENESIS_TAG, $tags)) { $nftView['image'] = 'https://www.cebg.games/res/nfts/' . $itemMeta['id'] . '_1' . '.png'; } } else { $nftView['image'] = 'https://www.cebg.games/res/nfts/0.png'; } } public static function addNftByFragmentBox($itemMeta,$num=0){ if ($itemMeta) { $tokenType = Nft::getTokenType($itemMeta); if ($tokenType == Nft::NONE_TYPE) { return false; } else { SqlHelper::insert( myself()->_getMarketMysql(), 't_nft', array( 'token_id' => myself()->_getNowTime()+$num, 'token_type' => $tokenType, 'game_id' => 2006, 'item_id' => $itemMeta['include_item_id'], 'owner_address' => myself()->_getOpenId(), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) ); return true; } } else { return false; } } public static function addNft($itemMeta){ if ($itemMeta) { $tokenType = Nft::getTokenType($itemMeta); if ($tokenType == Nft::NONE_TYPE) { return false; } else { SqlHelper::insert( myself()->_getMarketMysql(), 't_nft', array( 'token_id' => myself()->_getNowTime(), 'token_type' => $tokenType, 'game_id' => 2006, 'item_id' => $itemMeta['id'], 'owner_address' => myself()->_getOpenId(), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), ) ); return true; } } else { return false; } } private static function parseTags($tagsStr) { $tags = explode('|', $tagsStr); return $tags; } private static function isVisableNft($nftDb) { return in_array($nftDb['token_type'], array( self::HERO_TYPE, self::EQUIP_TYPE, self::CHIP_TYPE )); } }