Merge branch 'james_bc' of git.kingsome.cn:server/game2006api into james_bc

This commit is contained in:
hujiabin 2023-02-09 14:16:01 +08:00
commit e05583a87d
2 changed files with 122 additions and 19 deletions

View File

@ -28,6 +28,21 @@ class CurrencyType(object):
['name', '', '货币名称'],
['address', '', '货币地址'],
]
class TransactionRecord(object):
def __init__(self):
self.fields = [
['idx', '', 'idx'],
['createtime', 0, '交易成功时间'],
['orderid', 0, 'market订单id'],
['o_link', '', '合约订单id'],
['seller', '', '卖家'],
['buyer', '', '买家'],
['tokenid', '', 'tokenid'],
['amount', 0, '商品数量'],
['name', '', '商品名称'],
['type', 0, '商品类型'],
]
class Market(object):
def __init__(self):
@ -418,5 +433,25 @@ class Market(object):
_common.RspHead(),
['!list', [CurrencyType()], '货币类型列表'],
]
},
{
'name': 'getTransactionRecord',
'desc': '获取交易记录',
'group': 'Market',
'url': 'webapp/index.php?c=Market&a=getTransactionRecord',
'params': [
['account', '', '账号id'],
['type', 0, '物品类型 0:所有 1:英雄 2:武器 3:芯片 5:碎片'],
['start', 0, '分页开始偏移'],
['page_size', 0, '分页大小'],
],
'response': [
_common.RspHead(),
['total', 0, '交易记录总数'],
['start', 0, '有效的分页偏移'],
['page_size', 0, '有效的分页大小'],
['!list', [TransactionRecord()], '交易记录列表'],
]
}
]

View File

@ -831,8 +831,11 @@ class MarketController extends BaseController {
$nftDb = Nft::findNftByOwner($account, $row['token_id']);
// 0x768b5faed6dc69816f33377d214ffaf00dcdd0cf
if (!$nftDb) {
myself()->_rspErr(1, 'nft not exists');
return;
$nftDb = Nft::findNftByOwner('0xfc628dd79137395f3c9744e33b1c5de554d94882', $row['token_id']);
if (!$nftDb) {
myself()->_rspErr(1, 'nft not exists');
return;
}
}
}
$nft = Nft::toDto($nftDb);
@ -962,33 +965,85 @@ class MarketController extends BaseController {
'name' => 'USDT',
'address' => '0xc22Ffa318051d8aF4E5f2E2732d7049486fcE093',
));
array_push($types, array(
'name' => 'CEC',
'address' => '0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7',
));
array_push($types, array(
'name' => 'CEG',
'address' => '0xc22Ffa318051d8aF4E5f2E2732d7049486fcE093',
));
} else {
array_push($types, array(
'name' => 'USDT',
'address' => '0xc22Ffa318051d8aF4E5f2E2732d7049486fcE093',
));
array_push($types, array(
'name' => 'D CEC',
'address' => '0x9561C133DD8580860B6b7E504bC5Aa500f0f06a7',
));
array_push($types, array(
'name' => 'D CEG',
'address' => '0x59d3631c86BbE35EF041872d502F218A39FBa150',
));
}
$this->_rspData(array(
'list' => $types,
));
}
public function getTransactionRecord() {
$account = strtolower(getReqVal('account', ''));
$type = getReqVal('type', 0);
$start = getReqVal('start', 0);
$page_size = getReqVal('page_size', 10);
$conn = myself()->_getMysql('');
$type_filter_fn = function ($f) {
if ($f==0) {
return '';
}
else {
return 'AND type=' . $f;
}
};
$counts = $conn->execQuery(
'SELECT count(*) as count FROM t_market_transaction_record '.
'WHERE (seller=:account OR buyer=:account) '.
$type_filter_fn($type).
' 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) '.
$type_filter_fn($type).
' 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', ''));
@ -1090,7 +1145,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', 'token_type'), array('o_link' => $orderId));
if (empty($chk)) {
$this->_rspErr(1, 'not found order, orderId='.$orderId);
return;
@ -1107,6 +1162,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['token_type'],
);
$this->addTransactionRecord($record);
$this->_rspOk();
return;
}