This commit is contained in:
songliang 2023-07-14 22:02:18 +08:00
parent 2da3da8ad2
commit a15f0097bf
4 changed files with 80 additions and 74 deletions

View File

@ -1,8 +1,9 @@
<?php <?php
namespace services; namespace services;
require_once('MarketCallbackBase.php'); require_once('MarketCallbackBase.php');
require_once ('services/callback/common/SignatureService.php'); require_once('services/callback/common/SignatureService.php');
use services\MarketCallbackBase; use services\MarketCallbackBase;
use phpcommon\SqlHelper; use phpcommon\SqlHelper;
@ -11,73 +12,74 @@ use phpcommon\SqlHelper;
class MarketBuyOrderOk extends MarketCallbackBase class MarketBuyOrderOk extends MarketCallbackBase
{ {
public function process() public function process()
{ {
SignatureService::web3ServiceCheck(); SignatureService::web3ServiceCheck();
error_log('MarketBuyOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT)); error_log('MarketBuyOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
$tokenId = getReqVal('tokenId', ''); $tokenId = getReqVal('tokenId', '');
$orderId = getReqVal('orderId', ''); $orderId = getReqVal('orderId', '');
$nftToken = getReqVal('nftToken', ''); $nftToken = getReqVal('nftToken', '');
$amount = getReqVal('amount', 0); $amount = getReqVal('amount', 0);
$seller = strtolower(getReqVal('seller', '')); $seller = strtolower(getReqVal('seller', ''));
$buyer = strtolower(getReqVal('buyer', '')); $buyer = strtolower(getReqVal('buyer', ''));
$erc20 = getReqVal('erc20', ''); $erc20 = getReqVal('erc20', '');
$price = getReqVal('price', ''); $price = getReqVal('price', '');
error_log( error_log(
"eventBuyOrder:" . json_encode( "eventBuyOrder:" . json_encode(
array( array(
'tokenId' => $tokenId, 'tokenId' => $tokenId,
'orderId' => $orderId, 'orderId' => $orderId,
'nftToken' => $nftToken, 'nftToken' => $nftToken,
'amount' => $amount, 'amount' => $amount,
'seller' => $seller, 'seller' => $seller,
'buyer' => $buyer, 'buyer' => $buyer,
'erc20' => $erc20, 'erc20' => $erc20,
'price' => $price, 'price' => $price,
), ),
JSON_PRETTY_PRINT JSON_PRETTY_PRINT
)
);
$conn = myself()->_getMysql('');
// 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) {
// 增加交易记录 $o_link = $orderId;
$record = array( $conn = myself()->_getMysql('');
'createtime' => myself()->_getNowTime(),
'order_id' => $chk['order_id'], // 1. check order status
'o_link' => $orderId, $chk = SqlHelper::selectOne($conn, 't_market_store', array('status', 'idx', 'c_name', 'token_type'), array('o_link' => $o_link));
'seller' => $seller, if (empty($chk)) {
'buyer' => $buyer, $this->_rspErr(2, 'not found order, o_link=' . $o_link);
'tokenid' => $tokenId,
'amount' => $amount,
'name' => $chk['c_name'],
'type' => $chk['token_type'],
);
$this->addTransactionRecord($record);
$this->_rspOk();
return; 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['order_id'],
'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(2, 'order status error, o_link=' . $o_link);
} }
$this->_rspErr(1, 'order status error, order=' . $orderId);
}
} }

View File

@ -29,20 +29,22 @@ class MarketCancelOrderOk extends MarketCallbackBase
) )
); );
$o_link = $orderId;
$conn = myself()->_getMysql(''); $conn = myself()->_getMysql('');
// 1. check order status // 1. check order status
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $o_link));
if (empty($chk)) { if (empty($chk)) {
$this->_rspErr(1, 'not found order, orderId=' . $orderId); $this->_rspErr(2, 'not found order, o_link=' . $o_link);
return; return;
} }
if ($chk['status'] == '0') { if ($chk['status'] == '0') {
$r = SqlHelper::update( $r = SqlHelper::update(
$conn, $conn,
't_market_store', 't_market_store',
array( array(
'o_link' => $orderId, 'o_link' => $o_link
), ),
array( array(
'status' => 1, 'status' => 1,
@ -53,6 +55,6 @@ class MarketCancelOrderOk extends MarketCallbackBase
return; return;
} }
} }
$this->_rspErr(1, 'order status error, order=' . $orderId); $this->_rspErr(2, 'order status error, o_link=' . $o_link);
} }
} }

View File

@ -33,12 +33,13 @@ class MarketPriceUpdateOrderOk extends MarketCallbackBase
) )
); );
$o_link = $orderId;
$conn = myself()->_getMysql(''); $conn = myself()->_getMysql('');
// 1. check order status // 订单没找到
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId)); $chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $o_link));
if (empty($chk)) { if (empty($chk)) {
$this->_rspErr(1, 'not found order, orderId=' . $orderId); $this->_rspErr(2, 'not found order, o_link=' . $o_link);
return; return;
} }
@ -47,7 +48,7 @@ class MarketPriceUpdateOrderOk extends MarketCallbackBase
$conn, $conn,
't_market_store', 't_market_store',
array( array(
'o_link' => $orderId, 'o_link' => $o_link,
), ),
array( array(
's_price' => $price, 's_price' => $price,
@ -58,7 +59,7 @@ class MarketPriceUpdateOrderOk extends MarketCallbackBase
return; return;
} }
} }
// 更新价格失败,视作订单未找到
$this->_rspErr(1, 'price update failed, orderId=' . $orderId); $this->_rspErr(2, 'price update failed, o_link=' . $o_link);
} }
} }

View File

@ -92,7 +92,8 @@ class MarketSellOrderOk extends MarketCallbackBase
) )
); );
if (!$r) { if (!$r) {
$this->_rspErr(2, 'unknown error, orderId=' . $orderId); // 上架操作失败这种情况一般不不应该发生如果发生了就是系统bug
$this->_rspErr(2, 'unknown error, o_link=' . $o_link);
} }
// 成功上架更新nft状态 // 成功上架更新nft状态