diff --git a/webapp/controller/CallbackController.class.php b/webapp/controller/CallbackController.class.php index 450ca5ba..daecd478 100644 --- a/webapp/controller/CallbackController.class.php +++ b/webapp/controller/CallbackController.class.php @@ -4,6 +4,12 @@ class CallbackController extends BaseController { private $handlers = array( 'gameItemMallBuyOk' => 'GameItemMallBuyOk', + 'eventSellOrder' => 'eventSellOrder', + 'eventBuyOrder' => 'eventBuyOrder', + 'eventCancelOrder' => 'eventCancelOrder', + 'eventPriceUpdateOrder' => 'eventPriceUpdateOrder', + 'buyGoodsDirect' => 'buyGoodsDirect', + 'inappPurchaseDiamonds' => 'inappPurchaseDiamonds', ); public function dispatch() diff --git a/webapp/models/BuyRecord.php b/webapp/models/BuyRecord.php index a0a09073..0de0525f 100644 --- a/webapp/models/BuyRecord.php +++ b/webapp/models/BuyRecord.php @@ -10,7 +10,7 @@ use phpcommon\SqlHelper; class BuyRecord extends BaseModel { - public static function genOrderId($gameId, $funcId, $time, $®) + public static function genOrderId($gameId, $funcId, $time, $buyerAddress) { SqlHelper::insert (myself()->_getMarketMysql(), diff --git a/webapp/services/callback/buyGoodsDirect.php b/webapp/services/callback/buyGoodsDirect.php new file mode 100644 index 00000000..6109c4be --- /dev/null +++ b/webapp/services/callback/buyGoodsDirect.php @@ -0,0 +1,11 @@ + $tokenId, + 'orderId' => $orderId, + 'nftToken' => $nftToken, + 'amount' => $amount, + 'seller' => $seller, + 'buyer' => $buyer, + 'erc20' => $erc20, + 'price' => $price, + ), + JSON_PRETTY_PRINT + ) + ); + + $conn = myself()->_getSelfMysql(); + + // 1. check order status + $chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), 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' => 2, + ) + ); + if ($r) { + // 增加交易记录 + $record = array( + 'createtime' => myself()->_getNowTime(), + 'orderid' => $chk['idx'], + 'o_link' => $orderId, + '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); + } +} diff --git a/webapp/services/callback/eventCancelOrder.php b/webapp/services/callback/eventCancelOrder.php new file mode 100644 index 00000000..07dd09a3 --- /dev/null +++ b/webapp/services/callback/eventCancelOrder.php @@ -0,0 +1,51 @@ + $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); + } +} diff --git a/webapp/services/callback/eventPriceUpdateOrder.php b/webapp/services/callback/eventPriceUpdateOrder.php new file mode 100644 index 00000000..612dc2c9 --- /dev/null +++ b/webapp/services/callback/eventPriceUpdateOrder.php @@ -0,0 +1,57 @@ + $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); + } +} diff --git a/webapp/services/callback/eventSellOrder.php b/webapp/services/callback/eventSellOrder.php new file mode 100644 index 00000000..af419d9d --- /dev/null +++ b/webapp/services/callback/eventSellOrder.php @@ -0,0 +1,83 @@ + $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(); + } +} diff --git a/webapp/services/callback/inappPurchaseDiamonds.php b/webapp/services/callback/inappPurchaseDiamonds.php new file mode 100644 index 00000000..d3edacc3 --- /dev/null +++ b/webapp/services/callback/inappPurchaseDiamonds.php @@ -0,0 +1,12 @@ +