From 17c8cd647821f3543b2c7b62c1f3efed5e8ba01d Mon Sep 17 00:00:00 2001 From: songliang Date: Fri, 14 Jul 2023 15:53:03 +0800 Subject: [PATCH] ... --- webapp/controller/MarketController.class.php | 266 +------------------ 1 file changed, 1 insertion(+), 265 deletions(-) diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 5cd94f09..a0bc677a 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -43,19 +43,6 @@ use models\Transaction; class MarketController extends BaseAuthedController { - - public function _handlePre() - { - if ( - getReqVal('a', '') != 'eventSellOrder' && - getReqVal('a', '') != 'eventBuyOrder' && - getReqVal('a', '') != 'eventCancelOrder' && - getReqVal('a', '') != 'eventPriceUpdateOrder' - ) { - parent::_handlePre(); - } - } - private function getNftListByAccountAndType($account, $type, $order_method, $order_asc, $job, $search, $lv, $quality, $durability) { $sortByLevel = function ($a, $b) use ($order_asc) { @@ -718,7 +705,7 @@ class MarketController extends BaseAuthedController 'order_id' => $goods['order_id'], )), )); - + $this->_rspData(array( 'block_chain' => $response, )); @@ -863,257 +850,6 @@ class MarketController extends BaseAuthedController )); } - private function addTransactionRecord($record) - { - $conn = myself()->_getMarketMysql(''); - - $r = SqlHelper::insert( - $conn, - 't_market_transaction_record', - $record - ); - if (!$r) { - $this->_rspErr(2, 'unknown error, orderId=' . $record['order_id']); - } - } - - public function eventSellOrder() - { - $tokenId = getReqVal('tokenId', ''); - $owner = strtolower(getReqVal('owner', '')); - $nftToken = getReqVal('nftToken', ''); - $amount = getReqVal('amount', 0); - $orderId = getReqVal('orderId', ''); - $currency = getReqVal('currency', ''); - $price = getReqVal('price', ''); - - error_log( - "eventSellOrder:" . json_encode( - array( - 'tokenId' => $tokenId, - 'owner' => $owner, - 'nftToken' => $nftToken, - 'amount' => $amount, - 'orderId' => $orderId, - 'currency' => $currency, - 'price' => $price, - ), - JSON_PRETTY_PRINT - ) - ); - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); - if (!empty($chk)) { - $this->_rspErr(1, 'repeat sell order, orderId=' . $orderId); - 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' => $orderId, - '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) { - $this->_rspErr(2, 'unknown error, orderId=' . $orderId); - } - - $this->_rspOk(); - } - - public function eventBuyOrder() - { - $tokenId = getReqVal('tokenId', ''); - $orderId = getReqVal('orderId', ''); - $nftToken = getReqVal('nftToken', ''); - $amount = getReqVal('amount', 0); - $seller = strtolower(getReqVal('seller', '')); - $buyer = strtolower(getReqVal('buyer', '')); - $erc20 = getReqVal('erc20', ''); - $price = getReqVal('price', ''); - - error_log( - "eventBuyOrder:" . json_encode( - array( - 'tokenId' => $tokenId, - 'orderId' => $orderId, - 'nftToken' => $nftToken, - 'amount' => $amount, - 'seller' => $seller, - 'buyer' => $buyer, - 'erc20' => $erc20, - 'price' => $price, - ), - JSON_PRETTY_PRINT - ) - ); - - // nft order id 统一改为 o_link 字段 - $o_link = $orderId; - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $o_link)); - if (empty($chk)) { - $this->_rspErr(1, 'not found order, orderId=' . $o_link); - return; - } - if ($chk['status'] == '0') { - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'o_link' => $o_link, - ), - array( - 'status' => 2, - ) - ); - if ($r) { - // 增加交易记录 - $record = array( - 'createtime' => myself()->_getNowTime(), - 'order_id' => $chk['idx'], - 'o_link' => $o_link, - 'seller' => $seller, - 'buyer' => $buyer, - 'tokenid' => $tokenId, - 'amount' => $amount, - 'name' => $chk['c_name'], - 'type' => $chk['token_type'], - ); - $this->addTransactionRecord($record); - $this->_rspOk(); - return; - } - } - $this->_rspErr(1, 'order status error, order=' . $orderId); - } - - public function eventCancelOrder() - { - $orderId = getReqVal('orderId', ''); - $nftToken = getReqVal('nftToken', ''); - $tokenId = getReqVal('tokenId', ''); - error_log( - "eventCancelOrder:" . json_encode( - array( - 'orderId' => $orderId, - 'nftToken' => $nftToken, - 'tokenId' => $tokenId, - ), - JSON_PRETTY_PRINT - ) - ); - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); - if (empty($chk)) { - $this->_rspErr(1, 'not found order, orderId=' . $orderId); - return; - } - if ($chk['status'] == '0') { - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'o_link' => $orderId, - ), - array( - 'status' => 1, - ) - ); - if ($r) { - $this->_rspOk(); - return; - } - } - $this->_rspErr(1, 'order status error, order=' . $orderId); - } - - public function eventPriceUpdateOrder() - { - $orderId = getReqVal('orderId', '');; - $nftToken = getReqVal('nftToken', ''); - $tokenId = getReqVal('tokenId', ''); - $priceOld = getReqVal('priceOld', ''); - $price = getReqVal('price', ''); - error_log( - "eventPriceUpdateOrder:" . json_encode( - array( - 'orderId' => $orderId, - 'nftToken' => $nftToken, - 'tokenId' => $tokenId, - 'priceOld' => $priceOld, - 'price' => $price, - ), - JSON_PRETTY_PRINT - ) - ); - - $conn = myself()->_getSelfMysql(); - - // 1. check order status - $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); - if (empty($chk)) { - $this->_rspErr(1, 'not found order, orderId=' . $orderId); - return; - } - - if ($chk['status'] == '0') { - $r = SqlHelper::update( - $conn, - 't_market_store', - array( - 'o_link' => $orderId, - ), - array( - 's_price' => $price, - ) - ); - if ($r) { - $this->_rspOk(); - return; - } - } - - $this->_rspErr(1, 'price update failed, orderId=' . $orderId); - } - private function getNftGameData($nftRowInfo) { $t = $nftRowInfo['token_type'];