$tokenId, 'owner' => $owner, 'nftToken' => $nftToken, 'amount' => $amount, 'orderId' => $orderId, 'currency' => $currency, 'price' => $price, ), JSON_PRETTY_PRINT ) ); $o_link = $orderId; $conn = myself()->_getMysql(''); // 1. check order status and repeat order $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $o_link)); if (!empty($chk)) { $this->_rspErr(1, 'repeat sell order, o_link=' . $o_link); return; } // 2. insert sell order to t_market_store $nftDb = Nft::findNftByOwner($owner, $tokenId); if (empty($nftDb)) { $nftDb = Nft::getNft($tokenId); } $nftDetail = Nft::toDto($nftDb); $detail = $this->getNftGameData($nftDb); $r = SqlHelper::insert( $conn, 't_market_store', array( 'token_id' => $tokenId, 'o_link' => $o_link, 'nft_token' => $nftToken, 'status' => 0, 'owner_address' => $owner, 'token_type' => $nftDetail['type'], 'amount' => $amount, 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime(), 's_currency' => $currency, 's_price' => $price, 'c_name' => $nftDetail['info']['name'], 'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job'] : (isset($detail['chip_type']) ? $detail['chip_type'] : (isset($detail['type']) ? $detail['type'] : 0)), 'c_lv' => @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'], 'c_quality' => isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0, 'c_durability' => isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0), 'c_type' => isset($detail['type']) ? $detail['type'] : 0, 'c_id' => $nftDetail['item_id'], ) ); if (!$r) { // 上架操作失败,这种情况一般不不应该发生,如果发生了,就是系统bug $this->_rspErr(2, 'unknown error, o_link=' . $o_link); } // 成功上架,更新nft状态 $this->_rspOk(); } private function getNftGameData($nftRowInfo) { $t = $nftRowInfo['token_type']; $token_id = $nftRowInfo['token_id']; switch ($t) { case Nft::HERO_TYPE: { return $this->appendChipsInfo(Hero::toDtoInfo(Hero::findByTokenId2($token_id))); } break; case Nft::EQUIP_TYPE: { return $this->appendChipsInfo(Gun::toDtoInfo(Gun::findByTokenId2($token_id))); } break; case Nft::CHIP_TYPE: { return Chip::toDto(Chip::getChipByTokenId($token_id)); } break; case Nft::FRAGMENT_TYPE: { return Fragment::ToDto($nftRowInfo); } break; default: { } break; } return array('unknown' => 'unknown game data type, cannot find data'); } private function appendChipsInfo($detail) { $detail['chips_info'] = array(); if (!empty($detail['chip_ids'])) { $chips = explode('|', $detail['chip_ids']); foreach ($chips as $chip) { $chip_info = ""; if (!empty($chip)) { $chip_info = Chip::toDto(Chip::getChipByTokenId($chip)); } array_push($detail['chips_info'], $chip_info); } } return $detail; } }