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
namespace services;
require_once('MarketCallbackBase.php');
require_once ('services/callback/common/SignatureService.php');
require_once('services/callback/common/SignatureService.php');
use services\MarketCallbackBase;
use phpcommon\SqlHelper;
@ -11,73 +12,74 @@ use phpcommon\SqlHelper;
class MarketBuyOrderOk extends MarketCallbackBase
{
public function process()
{
SignatureService::web3ServiceCheck();
error_log('MarketBuyOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
public function process()
{
SignatureService::web3ServiceCheck();
error_log('MarketBuyOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
$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', '');
$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
)
);
$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,
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
)
);
if ($r) {
// 增加交易记录
$record = array(
'createtime' => myself()->_getNowTime(),
'order_id' => $chk['order_id'],
'o_link' => $orderId,
'seller' => $seller,
'buyer' => $buyer,
'tokenid' => $tokenId,
'amount' => $amount,
'name' => $chk['c_name'],
'type' => $chk['token_type'],
);
$this->addTransactionRecord($record);
$this->_rspOk();
$o_link = $orderId;
$conn = myself()->_getMysql('');
// 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(2, 'not found order, o_link=' . $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['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('');
// 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)) {
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
$this->_rspErr(2, 'not found order, o_link=' . $o_link);
return;
}
if ($chk['status'] == '0') {
$r = SqlHelper::update(
$conn,
't_market_store',
array(
'o_link' => $orderId,
'o_link' => $o_link
),
array(
'status' => 1,
@ -53,6 +55,6 @@ class MarketCancelOrderOk extends MarketCallbackBase
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('');
// 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)) {
$this->_rspErr(1, 'not found order, orderId=' . $orderId);
$this->_rspErr(2, 'not found order, o_link=' . $o_link);
return;
}
@ -47,7 +48,7 @@ class MarketPriceUpdateOrderOk extends MarketCallbackBase
$conn,
't_market_store',
array(
'o_link' => $orderId,
'o_link' => $o_link,
),
array(
's_price' => $price,
@ -58,7 +59,7 @@ class MarketPriceUpdateOrderOk extends MarketCallbackBase
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) {
$this->_rspErr(2, 'unknown error, orderId=' . $orderId);
// 上架操作失败这种情况一般不不应该发生如果发生了就是系统bug
$this->_rspErr(2, 'unknown error, o_link=' . $o_link);
}
// 成功上架更新nft状态