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

This commit is contained in:
hujiabin 2024-06-19 15:55:45 +08:00
commit a08f9cf846
5 changed files with 216 additions and 4 deletions

View File

@ -39,6 +39,23 @@ class AAMarket(object):
['!rows', [_common.MarketGoods()], '数据'], ['!rows', [_common.MarketGoods()], '数据'],
] ]
}, },
{
'method': 'GET',
'name': '/api/market/product/category/:net_id',
'desc': '获取上架出售的NFTs分类数量',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/market/product/list/:net_id',
'params': [
[':net_id', 0, '链id'],
],
'response': [
_common.RspHead(),
['!data', [
['item_id', 0, '道具id'],
['num', 0, '商品数量'],
], '分类数量'],
]
},
{ {
'name': '/api/market/transaction/history/:net_id/:account_address', 'name': '/api/market/transaction/history/:net_id/:account_address',
'desc': '获取账号交易历史', 'desc': '获取账号交易历史',
@ -76,4 +93,114 @@ class AAMarket(object):
['!rows', [_common.NftInfo()], '数据'], ['!rows', [_common.NftInfo()], '数据'],
] ]
}, },
{
'method': 'POST',
'name': '/api/hero/use/:net_id',
'desc': '使用英雄(带入游戏内)',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/hero/use/:net_id',
'is_json_params': True,
'request_params': [
[':net_id', 0, '链id'],
['account_address', '', '钱包地址'],
],
'params': [
['!token_ids', [''], 'tokenId列表'],
],
'response': [
_common.RspHead(),
['trans_id', '', '事务id'],
['!params', [''], '合约参数列表'],
]
},
{
'method': 'POST',
'name': '/api/guld_bullion/use/:net_id',
'desc': '使用金砖(生成金币带入游戏内)',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/gold_bullion/use/:net_id',
'is_json_params': True,
'request_params': [
[':net_id', 0, '链id'],
['account_address', '', '钱包地址'],
],
'params': [
['!token_ids', [''], 'tokenId列表'],
],
'response': [
_common.RspHead(),
['trans_id', '', '事务id'],
['!params', [''], '合约参数列表'],
]
},
{
'method': 'GET',
'name': '/api/shopcart/list',
'desc': '购物车-商品列表',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/shopcart/list',
'headers': _common.JwtHeader,
'permission': _common.LoginRequired,
'params': [
],
'response': [
_common.RspHead(),
['!data', [_common.MarketGoods()], '数据'],
]
},
{
'method': 'POST',
'name': '/api/shopcart/add',
'desc': '购物车-添加商品',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/shopcart/add',
'headers': _common.JwtHeader,
'permission': _common.LoginRequired,
'is_json_params': True,
'params': [
['net_id', 0, '链id'],
['!tokens', [
['token_id', '', 'token_id'],
['token_type', 0, '1: hero 11:gold bullion'],
], 'nft list']
],
'response': [
_common.RspHead(),
]
},
{
'method': 'POST',
'name': '/api/shopcart/del',
'desc': '购物车-删除商品',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/shopcart/del',
'headers': _common.JwtHeader,
'permission': _common.LoginRequired,
'is_json_params': True,
'params': [
['net_id', 0, '链id'],
['!tokens', [
['token_id', '', 'token_id'],
['token_type', 0, '1: hero 11:gold bullion'],
], 'nft list']
],
'response': [
_common.RspHead(),
]
},
{
'method': 'POST',
'name': '/api/shopcart/clear',
'desc': '购物车-清空购物车',
'group': '!AAMarket',
'url': 'https://market-test.kingsome.cn/api/shopcart/clear',
'headers': _common.JwtHeader,
'permission': _common.LoginRequired,
'params': [
['net_id', 0, '链id'],
],
'response': [
_common.RspHead(),
]
},
] ]

View File

@ -66,6 +66,7 @@ class BlockChain(object):
'params': [ 'params': [
['type', 0, '1英雄 2金砖'], ['type', 0, '1英雄 2金砖'],
['uniid', '', '唯一id'], ['uniid', '', '唯一id'],
['account_address', '', '钱包地址'],
], ],
'response': [ 'response': [
_common.RspHead(), _common.RspHead(),
@ -80,6 +81,7 @@ class BlockChain(object):
'url': 'webapp/index.php?c=BlockChain&a=mintGoldBullion', 'url': 'webapp/index.php?c=BlockChain&a=mintGoldBullion',
'params': [ 'params': [
['type', 0, '11w金币 210w金币'], ['type', 0, '11w金币 210w金币'],
['account_address', '', '钱包地址'],
], ],
'response': [ 'response': [
_common.RspHead(), _common.RspHead(),

View File

@ -22,6 +22,12 @@ class RspHead(object):
self.fields[i][1] = value self.fields[i][1] = value
break break
JwtHeader = [
'Authorization Bearer {JwtToken}'
]
LoginRequired = 'login required'
class Union(object): class Union(object):
def __init__(self, fields): def __init__(self, fields):

View File

@ -116,6 +116,11 @@ class BlockChainController extends BaseAuthedController {
{ {
$type = getReqVal('type', 0); $type = getReqVal('type', 0);
$uniid = getReqVal('uniid', 0); $uniid = getReqVal('uniid', 0);
$accountAddress = strtolower(getReqVal('account_address', ''));
if ($accountAddress != myself()->_getAddress()) {
myself()->_rspErr(1, 'account address error');
return;
}
switch ($type) { switch ($type) {
case 1: case 1:
{ {
@ -153,7 +158,8 @@ class BlockChainController extends BaseAuthedController {
Nft::HERO_TYPE, Nft::HERO_TYPE,
$heroDb['hero_uniid'], $heroDb['hero_uniid'],
$heroDb['hero_id'], $heroDb['hero_id'],
$isMint); $isMint,
null);
} }
break; break;
default: default:
@ -168,16 +174,24 @@ class BlockChainController extends BaseAuthedController {
public function mintGoldBullion() public function mintGoldBullion()
{ {
$type = getReqVal('type', 0); $type = getReqVal('type', 0);
$accountAddress = strtolower(getReqVal('account_address', ''));
if ($accountAddress != myself()->_getAddress()) {
myself()->_rspErr(1, 'account address error');
return;
}
$itemId = 0; $itemId = 0;
$goldNum = 0;
switch ($type) { switch ($type) {
case 1: case 1:
{ {
$itemId = V_ITEM_GOLD_BULLION_1W; $itemId = V_ITEM_GOLD_BULLION_1W;
$goldNum = 10000;
} }
break; break;
case 2: case 2:
{ {
$itemId = V_ITEM_GOLD_BULLION_10W; $itemId = V_ITEM_GOLD_BULLION_10W;
$goldNum = 10000 * 10;
} }
break; break;
default: default:
@ -185,10 +199,70 @@ class BlockChainController extends BaseAuthedController {
return; return;
} }
} }
if (empty($itemId) || empty($goldNum)) {
return;
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $goldNum
),
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, 'gold not enough');
return;
}
$tokenId = BuyRecord::genOrderId
(
GAME_ID,
phpcommon\BC_FUNC_CREATION,
myself()->_getNowTime(),
myself()->_getAddress()
);
$okCb = function () use($tokenId, $itemId, $costItems, $lackItem) {
$lackItem = null;
if (!myself()->_hasEnoughItems($costItems, $lackItem)) {
myself()->_rspErr(3, 'gold not enough');
return false;
}
$goldBullionDb = SqlHelper::ormSelectOne
(myself()->_getSelfMysql(),
't_gold_bullion',
array(
'token_id' => $tokenId
)
);
if (!empty($goldBullionDb)) {
$this->_rspErr(500, 'server internal error');
return false;
}
SqlHelper::insert
(myself()->_getSelfMysql(),
't_gold_bullion',
array(
'src_account_id' => myself()->_getAccountId(),
'src_address' => myself()->_getAddress(),
'token_id' => $tokenId,
'net_id' => NET_ID,
'item_id' => $itemId,
'gold' => $goldNum,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
)
);
return true;
};
$this->internalActivate721Nft(
$tokenId,
Nft::GOLD_BULLION_TYPE,
0,
$itemId,
true,
$okCb);
} }
private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId, $isMint) private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId, $isMint, $okCb)
{ {
$params = array( $params = array(
'c' => 'BcService', 'c' => 'BcService',
@ -228,6 +302,9 @@ class BlockChainController extends BaseAuthedController {
1, 1,
1 1
); );
if (!empty($okCb) && !$okCb()) {
return;
}
myself()->_rspData(array( myself()->_rspData(array(
'trans_id' => $transId, 'trans_id' => $transId,
'trans_req' => $rspObj['trans_req'] 'trans_req' => $rspObj['trans_req']

View File

@ -653,7 +653,7 @@ class Hero extends BaseModel {
{ {
if (self::find($heroUniId)) { if (self::find($heroUniId)) {
myself()->_getSelfMysql()->execScript( myself()->_getSelfMysql()->execScript(
'UPDATE t_hero SET token_id=:token_id, active_count=active_count + 1 ' . 'UPDATE t_hero SET token_id=:token_id ' .
'WHERE idx=:idx AND token_id IS NULL;', 'WHERE idx=:idx AND token_id IS NULL;',
array( array(
':idx' => $heroUniId, ':idx' => $heroUniId,