diff --git a/doc/Market.py b/doc/Market.py index e1fe883d..26141c6b 100644 --- a/doc/Market.py +++ b/doc/Market.py @@ -32,7 +32,7 @@ class CurrencyType(object): class TransactionRecord(object): def __init__(self): self.fields = [ - ['idx', 0, 'idx'], + ['idx', '', 'idx'], ['createtime', 0, '交易成功时间'], ['orderid', 0, 'market订单id'], ['o_link', '', '合约订单id'], diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index f9c48250..4042a593 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -976,6 +976,60 @@ class MarketController extends BaseController { )); } + public function getTransactionRecord() { + $account = strtolower(getReqVal('account', '')); + $start = getReqVal('start', 0); + $page_size = getReqVal('page_size', 10); + + $conn = myself()->_getMysql(''); + + $counts = $conn->execQuery( + 'SELECT count(*) as count FROM t_market_transaction_record '. + 'WHERE seller=:account OR buyer=:account ORDER BY createtime DESC', + array( + ':account' => $account, + ) + ); + + $total = $counts[0]['count']; + $page_end = $start + $page_size; + if ($page_end > $total) { + $page_end = $total; + $start = $total-1; + $start = intval($start / $page_size) * $page_size; + if ($start<0) $start = 0; + } + + $rows = $conn->execQuery( + 'SELECT * FROM t_market_transaction_record '. + 'WHERE seller=:account OR buyer=:account ORDER BY createtime DESC '. + 'LIMIT '.$start.','.$page_size, + array( + ':account' => $account, + ) + ); + + $this->_rspData(array( + "total" => $total, + "start" => $start, + "page_size" => $page_size, + 'nfts' => $rows, + )); + } + + private function addTransactionRecord($record) { + $conn = myself()->_getMysql(''); + + $r = SqlHelper::insert( + $conn, + 't_market_transaction_record', + $record + ); + if (!$r) { + $this->_rspErr(2, 'unknown error, orderId='.$record['orderid']); + } + } + public function eventSellOrder() { $tokenId = getReqVal('tokenId', ''); $owner = strtolower(getReqVal('owner', '')); @@ -1077,7 +1131,7 @@ class MarketController extends BaseController { $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','idx', 'c_name', 'c_type'), array('o_link' => $orderId)); if (empty($chk)) { $this->_rspErr(1, 'not found order, orderId='.$orderId); return; @@ -1094,6 +1148,19 @@ class MarketController extends BaseController { ) ); 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['c_type'], + ); + $this->addTransactionRecord($record); $this->_rspOk(); return; }